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::UpdateRegisteredIds(SyncNotifierObserver* handler, |
| 39 const ObjectIdSet& ids) { |
39 DCHECK(CalledOnValidThread()); | 40 DCHECK(CalledOnValidThread()); |
40 observers_.AddObserver(observer); | 41 invalidation_client_.RegisterIds(helper_.UpdateRegisteredIds(handler, ids)); |
41 } | |
42 | |
43 void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) { | |
44 DCHECK(CalledOnValidThread()); | |
45 observers_.RemoveObserver(observer); | |
46 } | 42 } |
47 | 43 |
48 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { | 44 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { |
49 DCHECK(CalledOnValidThread()); | 45 DCHECK(CalledOnValidThread()); |
50 invalidation_client_id_ = unique_id; | 46 invalidation_client_id_ = unique_id; |
51 DVLOG(1) << "Setting unique ID to " << unique_id; | 47 DVLOG(1) << "Setting unique ID to " << unique_id; |
52 CHECK(!invalidation_client_id_.empty()); | 48 CHECK(!invalidation_client_id_.empty()); |
53 } | 49 } |
54 | 50 |
55 void InvalidationNotifier::SetStateDeprecated(const std::string& state) { | 51 void InvalidationNotifier::SetStateDeprecated(const std::string& state) { |
(...skipping 23 matching lines...) Expand all Loading... |
79 invalidation_client_id_, client_info_, invalidation_state_, | 75 invalidation_client_id_, client_info_, invalidation_state_, |
80 initial_max_invalidation_versions_, | 76 initial_max_invalidation_versions_, |
81 invalidation_state_tracker_, | 77 invalidation_state_tracker_, |
82 this); | 78 this); |
83 invalidation_state_.clear(); | 79 invalidation_state_.clear(); |
84 state_ = STARTED; | 80 state_ = STARTED; |
85 } | 81 } |
86 invalidation_client_.UpdateCredentials(email, token); | 82 invalidation_client_.UpdateCredentials(email, token); |
87 } | 83 } |
88 | 84 |
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( | 85 void InvalidationNotifier::SendNotification( |
107 syncer::ModelTypeSet changed_types) { | 86 syncer::ModelTypeSet changed_types) { |
108 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
109 // Do nothing. | 88 // Do nothing. |
110 } | 89 } |
111 | 90 |
112 void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { | 91 void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { |
113 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
114 // TODO(dcheng): This should probably be a utility function somewhere... | 93 helper_.DispatchInvalidationsToHandlers( |
115 syncer::ModelTypePayloadMap type_payloads; | 94 id_payloads, syncer::REMOTE_NOTIFICATION); |
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 } | 95 } |
130 | 96 |
131 void InvalidationNotifier::OnNotificationsEnabled() { | 97 void InvalidationNotifier::OnNotificationsEnabled() { |
132 DCHECK(CalledOnValidThread()); | 98 DCHECK(CalledOnValidThread()); |
133 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 99 FOR_EACH_OBSERVER(SyncNotifierObserver, *helper_.handlers(), |
134 OnNotificationsEnabled()); | 100 OnNotificationsEnabled()); |
135 } | 101 } |
136 | 102 |
137 void InvalidationNotifier::OnNotificationsDisabled( | 103 void InvalidationNotifier::OnNotificationsDisabled( |
138 NotificationsDisabledReason reason) { | 104 NotificationsDisabledReason reason) { |
139 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
140 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 106 FOR_EACH_OBSERVER(SyncNotifierObserver, *helper_.handlers(), |
141 OnNotificationsDisabled(reason)); | 107 OnNotificationsDisabled(reason)); |
142 } | 108 } |
143 | 109 |
144 } // namespace syncer | 110 } // namespace syncer |
OLD | NEW |