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