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