Componentize AccountReconcilor.
[chromium-blink-merge.git] / chrome / browser / invalidation / invalidation_service_android.cc
blobf53f5bec24da401a485e40c41aca8e619979d5d6
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.
5 #include "chrome/browser/invalidation/invalidation_service_android.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/invalidation/invalidation_controller_android.h"
9 #include "content/public/browser/notification_service.h"
10 #include "sync/notifier/object_id_invalidation_map.h"
12 namespace invalidation {
14 InvalidationServiceAndroid::InvalidationServiceAndroid(
15 Profile* profile,
16 InvalidationControllerAndroid* invalidation_controller)
17 : invalidator_state_(syncer::INVALIDATIONS_ENABLED),
18 invalidation_controller_(invalidation_controller),
19 logger_() {
20 DCHECK(CalledOnValidThread());
21 DCHECK(invalidation_controller);
22 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
23 content::Source<Profile>(profile));
26 InvalidationServiceAndroid::~InvalidationServiceAndroid() { }
28 void InvalidationServiceAndroid::RegisterInvalidationHandler(
29 syncer::InvalidationHandler* handler) {
30 DCHECK(CalledOnValidThread());
31 invalidator_registrar_.RegisterHandler(handler);
32 logger_.OnRegistration(handler->GetOwnerName());
35 void InvalidationServiceAndroid::UpdateRegisteredInvalidationIds(
36 syncer::InvalidationHandler* handler,
37 const syncer::ObjectIdSet& ids) {
38 DCHECK(CalledOnValidThread());
39 invalidator_registrar_.UpdateRegisteredIds(handler, ids);
40 invalidation_controller_->SetRegisteredObjectIds(
41 invalidator_registrar_.GetAllRegisteredIds());
42 logger_.OnUpdateIds(invalidator_registrar_.GetSanitizedHandlersIdsMap());
45 void InvalidationServiceAndroid::UnregisterInvalidationHandler(
46 syncer::InvalidationHandler* handler) {
47 DCHECK(CalledOnValidThread());
48 invalidator_registrar_.UnregisterHandler(handler);
49 logger_.OnUnregistration(handler->GetOwnerName());
52 syncer::InvalidatorState
53 InvalidationServiceAndroid::GetInvalidatorState() const {
54 DCHECK(CalledOnValidThread());
55 return invalidator_state_;
58 std::string InvalidationServiceAndroid::GetInvalidatorClientId() const {
59 DCHECK(CalledOnValidThread());
60 return invalidation_controller_->GetInvalidatorClientId();
63 InvalidationLogger* InvalidationServiceAndroid::GetInvalidationLogger() {
64 return &logger_;
67 void InvalidationServiceAndroid::RequestDetailedStatus(
68 base::Callback<void(const base::DictionaryValue&)> return_callback) const {
71 InvalidationAuthProvider*
72 InvalidationServiceAndroid::GetInvalidationAuthProvider() {
73 return NULL;
76 void InvalidationServiceAndroid::Observe(
77 int type,
78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) {
80 DCHECK(CalledOnValidThread());
81 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE);
83 content::Details<const syncer::ObjectIdInvalidationMap>
84 state_details(details);
85 const syncer::ObjectIdInvalidationMap object_invalidation_map =
86 *(state_details.ptr());
88 // An empty map implies that we should invalidate all.
89 const syncer::ObjectIdInvalidationMap& effective_invalidation_map =
90 object_invalidation_map.Empty() ?
91 syncer::ObjectIdInvalidationMap::InvalidateAll(
92 invalidator_registrar_.GetAllRegisteredIds()) :
93 object_invalidation_map;
95 invalidator_registrar_.DispatchInvalidationsToHandlers(
96 effective_invalidation_map);
97 logger_.OnInvalidation(effective_invalidation_map);
100 void InvalidationServiceAndroid::TriggerStateChangeForTest(
101 syncer::InvalidatorState state) {
102 DCHECK(CalledOnValidThread());
103 invalidator_state_ = state;
104 invalidator_registrar_.UpdateInvalidatorState(invalidator_state_);
107 } // namespace invalidation