[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / invalidation / invalidation_service_android.cc
blob57a34bd557bc8babc3457f6ca62d4e853252d53d
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 IdentityProvider* InvalidationServiceAndroid::GetIdentityProvider() {
72 return NULL;
75 void InvalidationServiceAndroid::Observe(
76 int type,
77 const content::NotificationSource& source,
78 const content::NotificationDetails& details) {
79 DCHECK(CalledOnValidThread());
80 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE);
82 content::Details<const syncer::ObjectIdInvalidationMap>
83 state_details(details);
84 const syncer::ObjectIdInvalidationMap object_invalidation_map =
85 *(state_details.ptr());
87 // An empty map implies that we should invalidate all.
88 const syncer::ObjectIdInvalidationMap& effective_invalidation_map =
89 object_invalidation_map.Empty() ?
90 syncer::ObjectIdInvalidationMap::InvalidateAll(
91 invalidator_registrar_.GetAllRegisteredIds()) :
92 object_invalidation_map;
94 invalidator_registrar_.DispatchInvalidationsToHandlers(
95 effective_invalidation_map);
96 logger_.OnInvalidation(effective_invalidation_map);
99 void InvalidationServiceAndroid::TriggerStateChangeForTest(
100 syncer::InvalidatorState state) {
101 DCHECK(CalledOnValidThread());
102 invalidator_state_ = state;
103 invalidator_registrar_.UpdateInvalidatorState(invalidator_state_);
106 } // namespace invalidation