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