OLD | NEW |
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 17 matching lines...) Expand all Loading... |
28 invalidation_state_tracker_(invalidation_state_tracker), | 28 invalidation_state_tracker_(invalidation_state_tracker), |
29 client_info_(client_info), | 29 client_info_(client_info), |
30 invalidation_state_(initial_invalidation_state), | 30 invalidation_state_(initial_invalidation_state), |
31 invalidation_client_(push_client.Pass()) { | 31 invalidation_client_(push_client.Pass()) { |
32 } | 32 } |
33 | 33 |
34 InvalidationNotifier::~InvalidationNotifier() { | 34 InvalidationNotifier::~InvalidationNotifier() { |
35 DCHECK(CalledOnValidThread()); | 35 DCHECK(CalledOnValidThread()); |
36 } | 36 } |
37 | 37 |
38 void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) { | 38 void InvalidationNotifier::AddHandler(SyncNotifierObserver* observer) { |
39 DCHECK(CalledOnValidThread()); | 39 DCHECK(CalledOnValidThread()); |
40 observers_.AddObserver(observer); | 40 InvalidationNotifierBase::AddHandler(observer); |
41 } | 41 } |
42 | 42 |
43 void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) { | 43 void InvalidationNotifier::RemoveHandler(SyncNotifierObserver* observer) { |
44 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
45 observers_.RemoveObserver(observer); | 45 InvalidationNotifierBase::RemoveHandler(observer); |
| 46 } |
| 47 |
| 48 void InvalidationNotifier::ReloadHandlers() { |
| 49 const ObjectIdSet& ids_to_register = UpdateObjectIdObserverMap(); |
| 50 invalidation_client_.RegisterIds(ids_to_register); |
46 } | 51 } |
47 | 52 |
48 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { | 53 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { |
49 DCHECK(CalledOnValidThread()); | 54 DCHECK(CalledOnValidThread()); |
50 invalidation_client_id_ = unique_id; | 55 invalidation_client_id_ = unique_id; |
51 DVLOG(1) << "Setting unique ID to " << unique_id; | 56 DVLOG(1) << "Setting unique ID to " << unique_id; |
52 CHECK(!invalidation_client_id_.empty()); | 57 CHECK(!invalidation_client_id_.empty()); |
53 } | 58 } |
54 | 59 |
55 void InvalidationNotifier::SetStateDeprecated(const std::string& state) { | 60 void InvalidationNotifier::SetStateDeprecated(const std::string& state) { |
(...skipping 23 matching lines...) Expand all Loading... |
79 invalidation_client_id_, client_info_, invalidation_state_, | 84 invalidation_client_id_, client_info_, invalidation_state_, |
80 initial_max_invalidation_versions_, | 85 initial_max_invalidation_versions_, |
81 invalidation_state_tracker_, | 86 invalidation_state_tracker_, |
82 this); | 87 this); |
83 invalidation_state_.clear(); | 88 invalidation_state_.clear(); |
84 state_ = STARTED; | 89 state_ = STARTED; |
85 } | 90 } |
86 invalidation_client_.UpdateCredentials(email, token); | 91 invalidation_client_.UpdateCredentials(email, token); |
87 } | 92 } |
88 | 93 |
89 void InvalidationNotifier::UpdateEnabledTypes( | |
90 syncer::ModelTypeSet enabled_types) { | |
91 DCHECK(CalledOnValidThread()); | |
92 CHECK(!invalidation_client_id_.empty()); | |
93 ObjectIdSet ids; | |
94 for (syncer::ModelTypeSet::Iterator it = enabled_types.First(); it.Good(); | |
95 it.Inc()) { | |
96 invalidation::ObjectId id; | |
97 if (!RealModelTypeToObjectId(it.Get(), &id)) { | |
98 DLOG(WARNING) << "Invalid model type " << it.Get(); | |
99 continue; | |
100 } | |
101 ids.insert(id); | |
102 } | |
103 invalidation_client_.RegisterIds(ids); | |
104 } | |
105 | |
106 void InvalidationNotifier::SendNotification( | 94 void InvalidationNotifier::SendNotification( |
107 syncer::ModelTypeSet changed_types) { | 95 syncer::ModelTypeSet changed_types) { |
108 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
109 // Do nothing. | 97 // Do nothing. |
110 } | 98 } |
111 | 99 |
112 void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { | 100 void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { |
113 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
114 // TODO(dcheng): This should probably be a utility function somewhere... | 102 DispatchInvalidationsToObservers(id_payloads, syncer::REMOTE_NOTIFICATION); |
115 syncer::ModelTypePayloadMap type_payloads; | |
116 for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); | |
117 it != id_payloads.end(); ++it) { | |
118 syncer::ModelType model_type; | |
119 if (!ObjectIdToRealModelType(it->first, &model_type)) { | |
120 DLOG(WARNING) << "Invalid object ID: " << ObjectIdToString(it->first); | |
121 continue; | |
122 } | |
123 type_payloads[model_type] = it->second; | |
124 } | |
125 FOR_EACH_OBSERVER( | |
126 SyncNotifierObserver, observers_, | |
127 OnIncomingNotification(type_payloads, | |
128 syncer::REMOTE_NOTIFICATION)); | |
129 } | 103 } |
130 | 104 |
131 void InvalidationNotifier::OnNotificationsEnabled() { | 105 void InvalidationNotifier::OnNotificationsEnabled() { |
132 DCHECK(CalledOnValidThread()); | 106 DCHECK(CalledOnValidThread()); |
133 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 107 FOR_EACH_OBSERVER(SyncNotifierObserver, observers(), |
134 OnNotificationsEnabled()); | 108 OnNotificationsEnabled()); |
135 } | 109 } |
136 | 110 |
137 void InvalidationNotifier::OnNotificationsDisabled( | 111 void InvalidationNotifier::OnNotificationsDisabled( |
138 NotificationsDisabledReason reason) { | 112 NotificationsDisabledReason reason) { |
139 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
140 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 114 FOR_EACH_OBSERVER(SyncNotifierObserver, observers(), |
141 OnNotificationsDisabled(reason)); | 115 OnNotificationsDisabled(reason)); |
142 } | 116 } |
143 | 117 |
144 } // namespace syncer | 118 } // namespace syncer |
OLD | NEW |