OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/invalidation/invalidation_service_android.h" |
| 6 |
| 7 #include "chrome/common/chrome_notification_types.h" |
| 8 #include "content/public/browser/notification_service.h" |
| 9 |
| 10 namespace invalidation { |
| 11 |
| 12 InvalidationServiceAndroid::InvalidationServiceAndroid(Profile* profile) |
| 13 : invalidator_state_(syncer::INVALIDATIONS_ENABLED) { |
| 14 DCHECK(CalledOnValidThread()); |
| 15 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
| 16 content::Source<Profile>(profile)); |
| 17 } |
| 18 |
| 19 InvalidationServiceAndroid::~InvalidationServiceAndroid() { } |
| 20 |
| 21 void InvalidationServiceAndroid::RegisterInvalidationHandler( |
| 22 syncer::InvalidationHandler* handler) { |
| 23 DCHECK(CalledOnValidThread()); |
| 24 invalidator_registrar_.RegisterHandler(handler); |
| 25 } |
| 26 |
| 27 void InvalidationServiceAndroid::UpdateRegisteredInvalidationIds( |
| 28 syncer::InvalidationHandler* handler, |
| 29 const syncer::ObjectIdSet& ids) { |
| 30 DCHECK(CalledOnValidThread()); |
| 31 invalidator_registrar_.UpdateRegisteredIds(handler, ids); |
| 32 } |
| 33 |
| 34 void InvalidationServiceAndroid::UnregisterInvalidationHandler( |
| 35 syncer::InvalidationHandler* handler) { |
| 36 DCHECK(CalledOnValidThread()); |
| 37 invalidator_registrar_.UnregisterHandler(handler); |
| 38 } |
| 39 |
| 40 void InvalidationServiceAndroid::AcknowledgeInvalidation( |
| 41 const invalidation::ObjectId& id, |
| 42 const syncer::AckHandle& ack_handle) { |
| 43 DCHECK(CalledOnValidThread()); |
| 44 // Do nothing. The Android invalidator does not support ack tracking. |
| 45 } |
| 46 |
| 47 syncer::InvalidatorState |
| 48 InvalidationServiceAndroid::GetInvalidatorState() const { |
| 49 DCHECK(CalledOnValidThread()); |
| 50 return invalidator_state_; |
| 51 } |
| 52 |
| 53 std::string InvalidationServiceAndroid::GetInvalidatorClientId() const { |
| 54 DCHECK(CalledOnValidThread()); |
| 55 // TODO: Return a valid ID here. See crbug.com/172391. |
| 56 return "Bogus"; |
| 57 } |
| 58 |
| 59 void InvalidationServiceAndroid::Observe( |
| 60 int type, |
| 61 const content::NotificationSource& source, |
| 62 const content::NotificationDetails& details) { |
| 63 DCHECK(CalledOnValidThread()); |
| 64 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE); |
| 65 |
| 66 // TODO(akalin): Use ObjectIdInvalidationMap here instead. We'll have to |
| 67 // make sure all emitters of the relevant notifications also use |
| 68 // ObjectIdInvalidationMap. |
| 69 content::Details<const syncer::ModelTypeInvalidationMap> |
| 70 state_details(details); |
| 71 const syncer::ModelTypeInvalidationMap& model_type_invalidation_map = |
| 72 *(state_details.ptr()); |
| 73 syncer::ObjectIdInvalidationMap object_invalidation_map = |
| 74 ModelTypeInvalidationMapToObjectIdInvalidationMap( |
| 75 model_type_invalidation_map); |
| 76 |
| 77 // An empty map implies that we should invalidate all. |
| 78 const syncer::ObjectIdInvalidationMap& effective_invalidation_map = |
| 79 object_invalidation_map.empty() ? |
| 80 ObjectIdSetToInvalidationMap( |
| 81 invalidator_registrar_.GetAllRegisteredIds(), std::string()) : |
| 82 object_invalidation_map; |
| 83 |
| 84 invalidator_registrar_.DispatchInvalidationsToHandlers( |
| 85 effective_invalidation_map); |
| 86 } |
| 87 |
| 88 void InvalidationServiceAndroid::TriggerStateChangeForTest( |
| 89 syncer::InvalidatorState state) { |
| 90 DCHECK(CalledOnValidThread()); |
| 91 invalidator_state_ = state; |
| 92 invalidator_registrar_.UpdateInvalidatorState(invalidator_state_); |
| 93 } |
| 94 |
| 95 } // namespace invalidation |
OLD | NEW |