Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: sync/notifier/invalidation_notifier.cc

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to HEAD Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/notifier/invalidation_notifier.h ('k') | sync/notifier/invalidation_notifier_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/notifier/invalidation_notifier.h" 5 #include "sync/notifier/invalidation_notifier.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "jingle/notifier/listener/push_client.h" 10 #include "jingle/notifier/listener/push_client.h"
(...skipping 16 matching lines...) Expand all
27 invalidation_state_tracker_(invalidation_state_tracker), 27 invalidation_state_tracker_(invalidation_state_tracker),
28 client_info_(client_info), 28 client_info_(client_info),
29 invalidation_state_(initial_invalidation_state), 29 invalidation_state_(initial_invalidation_state),
30 invalidation_client_(push_client.Pass()) { 30 invalidation_client_(push_client.Pass()) {
31 } 31 }
32 32
33 InvalidationNotifier::~InvalidationNotifier() { 33 InvalidationNotifier::~InvalidationNotifier() {
34 DCHECK(CalledOnValidThread()); 34 DCHECK(CalledOnValidThread());
35 } 35 }
36 36
37 void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) { 37 void InvalidationNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler,
38 const ObjectIdSet& ids) {
38 DCHECK(CalledOnValidThread()); 39 DCHECK(CalledOnValidThread());
39 observers_.AddObserver(observer); 40 invalidation_client_.RegisterIds(helper_.UpdateRegisteredIds(handler, ids));
40 }
41
42 void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) {
43 DCHECK(CalledOnValidThread());
44 observers_.RemoveObserver(observer);
45 } 41 }
46 42
47 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { 43 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) {
48 DCHECK(CalledOnValidThread()); 44 DCHECK(CalledOnValidThread());
49 invalidation_client_id_ = unique_id; 45 invalidation_client_id_ = unique_id;
50 DVLOG(1) << "Setting unique ID to " << unique_id; 46 DVLOG(1) << "Setting unique ID to " << unique_id;
51 CHECK(!invalidation_client_id_.empty()); 47 CHECK(!invalidation_client_id_.empty());
52 } 48 }
53 49
54 void InvalidationNotifier::SetStateDeprecated(const std::string& state) { 50 void InvalidationNotifier::SetStateDeprecated(const std::string& state) {
(...skipping 23 matching lines...) Expand all
78 invalidation_client_id_, client_info_, invalidation_state_, 74 invalidation_client_id_, client_info_, invalidation_state_,
79 initial_max_invalidation_versions_, 75 initial_max_invalidation_versions_,
80 invalidation_state_tracker_, 76 invalidation_state_tracker_,
81 this); 77 this);
82 invalidation_state_.clear(); 78 invalidation_state_.clear();
83 state_ = STARTED; 79 state_ = STARTED;
84 } 80 }
85 invalidation_client_.UpdateCredentials(email, token); 81 invalidation_client_.UpdateCredentials(email, token);
86 } 82 }
87 83
88 void InvalidationNotifier::UpdateEnabledTypes(ModelTypeSet enabled_types) {
89 DCHECK(CalledOnValidThread());
90 CHECK(!invalidation_client_id_.empty());
91 ObjectIdSet ids;
92 for (ModelTypeSet::Iterator it = enabled_types.First(); it.Good();
93 it.Inc()) {
94 invalidation::ObjectId id;
95 if (!RealModelTypeToObjectId(it.Get(), &id)) {
96 DLOG(WARNING) << "Invalid model type " << it.Get();
97 continue;
98 }
99 ids.insert(id);
100 }
101 invalidation_client_.RegisterIds(ids);
102 }
103
104 void InvalidationNotifier::SendNotification(ModelTypeSet changed_types) { 84 void InvalidationNotifier::SendNotification(ModelTypeSet changed_types) {
105 DCHECK(CalledOnValidThread()); 85 DCHECK(CalledOnValidThread());
106 // Do nothing. 86 // Do nothing.
107 } 87 }
108 88
109 void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { 89 void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) {
110 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
111 // TODO(dcheng): This should probably be a utility function somewhere... 91 helper_.DispatchInvalidationsToHandlers(id_payloads, REMOTE_NOTIFICATION);
112 ModelTypePayloadMap type_payloads;
113 for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin();
114 it != id_payloads.end(); ++it) {
115 ModelType model_type;
116 if (!ObjectIdToRealModelType(it->first, &model_type)) {
117 DLOG(WARNING) << "Invalid object ID: " << ObjectIdToString(it->first);
118 continue;
119 }
120 type_payloads[model_type] = it->second;
121 }
122 FOR_EACH_OBSERVER(
123 SyncNotifierObserver, observers_,
124 OnIncomingNotification(type_payloads, REMOTE_NOTIFICATION));
125 } 92 }
126 93
127 void InvalidationNotifier::OnNotificationsEnabled() { 94 void InvalidationNotifier::OnNotificationsEnabled() {
128 DCHECK(CalledOnValidThread()); 95 DCHECK(CalledOnValidThread());
129 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, 96 helper_.EmitOnNotificationsEnabled();
130 OnNotificationsEnabled());
131 } 97 }
132 98
133 void InvalidationNotifier::OnNotificationsDisabled( 99 void InvalidationNotifier::OnNotificationsDisabled(
134 NotificationsDisabledReason reason) { 100 NotificationsDisabledReason reason) {
135 DCHECK(CalledOnValidThread()); 101 DCHECK(CalledOnValidThread());
136 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, 102 helper_.EmitOnNotificationsDisabled(reason);
137 OnNotificationsDisabled(reason));
138 } 103 }
139 104
140 } // namespace syncer 105 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/invalidation_notifier.h ('k') | sync/notifier/invalidation_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698