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/p2p_notifier.h" | 5 #include "sync/notifier/p2p_notifier.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "jingle/notifier/listener/push_client.h" | 13 #include "jingle/notifier/listener/push_client.h" |
14 #include "sync/internal_api/public/base/model_type_state_map.h" | 14 #include "sync/internal_api/public/base/model_type_state_map.h" |
| 15 #include "sync/notifier/invalidation_handler.h" |
15 #include "sync/notifier/invalidation_util.h" | 16 #include "sync/notifier/invalidation_util.h" |
16 #include "sync/notifier/sync_notifier_observer.h" | |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 | 19 |
20 const char* kSyncP2PNotificationChannel = "http://www.google.com/chrome/sync"; | 20 const char* kSyncP2PNotificationChannel = "http://www.google.com/chrome/sync"; |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kNotifySelf[] = "notifySelf"; | 24 const char kNotifySelf[] = "notifySelf"; |
25 const char kNotifyOthers[] = "notifyOthers"; | 25 const char kNotifyOthers[] = "notifyOthers"; |
26 const char kNotifyAll[] = "notifyAll"; | 26 const char kNotifyAll[] = "notifyAll"; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 DCHECK(send_notification_target_ == NOTIFY_OTHERS || | 150 DCHECK(send_notification_target_ == NOTIFY_OTHERS || |
151 send_notification_target_ == NOTIFY_ALL); | 151 send_notification_target_ == NOTIFY_ALL); |
152 push_client_->AddObserver(this); | 152 push_client_->AddObserver(this); |
153 } | 153 } |
154 | 154 |
155 P2PNotifier::~P2PNotifier() { | 155 P2PNotifier::~P2PNotifier() { |
156 DCHECK(thread_checker_.CalledOnValidThread()); | 156 DCHECK(thread_checker_.CalledOnValidThread()); |
157 push_client_->RemoveObserver(this); | 157 push_client_->RemoveObserver(this); |
158 } | 158 } |
159 | 159 |
160 void P2PNotifier::RegisterHandler(SyncNotifierObserver* handler) { | 160 void P2PNotifier::RegisterHandler(InvalidationHandler* handler) { |
161 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
162 registrar_.RegisterHandler(handler); | 162 registrar_.RegisterHandler(handler); |
163 } | 163 } |
164 | 164 |
165 void P2PNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, | 165 void P2PNotifier::UpdateRegisteredIds(InvalidationHandler* handler, |
166 const ObjectIdSet& ids) { | 166 const ObjectIdSet& ids) { |
167 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411). | 167 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411). |
168 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
169 registrar_.UpdateRegisteredIds(handler, ids); | 169 registrar_.UpdateRegisteredIds(handler, ids); |
170 const ModelTypeSet enabled_types = | 170 const ModelTypeSet enabled_types = |
171 ObjectIdSetToModelTypeSet(registrar_.GetAllRegisteredIds()); | 171 ObjectIdSetToModelTypeSet(registrar_.GetAllRegisteredIds()); |
172 const ModelTypeSet new_enabled_types = | 172 const ModelTypeSet new_enabled_types = |
173 Difference(enabled_types, enabled_types_); | 173 Difference(enabled_types, enabled_types_); |
174 const P2PNotificationData notification_data( | 174 const P2PNotificationData notification_data( |
175 unique_id_, NOTIFY_SELF, new_enabled_types); | 175 unique_id_, NOTIFY_SELF, new_enabled_types); |
176 SendNotificationData(notification_data); | 176 SendNotificationData(notification_data); |
177 enabled_types_ = enabled_types; | 177 enabled_types_ = enabled_types; |
178 } | 178 } |
179 | 179 |
180 void P2PNotifier::UnregisterHandler(SyncNotifierObserver* handler) { | 180 void P2PNotifier::UnregisterHandler(InvalidationHandler* handler) { |
181 DCHECK(thread_checker_.CalledOnValidThread()); | 181 DCHECK(thread_checker_.CalledOnValidThread()); |
182 registrar_.UnregisterHandler(handler); | 182 registrar_.UnregisterHandler(handler); |
183 } | 183 } |
184 | 184 |
185 void P2PNotifier::SetUniqueId(const std::string& unique_id) { | 185 void P2PNotifier::SetUniqueId(const std::string& unique_id) { |
186 DCHECK(thread_checker_.CalledOnValidThread()); | 186 DCHECK(thread_checker_.CalledOnValidThread()); |
187 unique_id_ = unique_id; | 187 unique_id_ = unique_id; |
188 } | 188 } |
189 | 189 |
190 void P2PNotifier::SetStateDeprecated(const std::string& state) { | 190 void P2PNotifier::SetStateDeprecated(const std::string& state) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return; | 290 return; |
291 } | 291 } |
292 notifier::Notification notification; | 292 notifier::Notification notification; |
293 notification.channel = kSyncP2PNotificationChannel; | 293 notification.channel = kSyncP2PNotificationChannel; |
294 notification.data = notification_data.ToString(); | 294 notification.data = notification_data.ToString(); |
295 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 295 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
296 push_client_->SendNotification(notification); | 296 push_client_->SendNotification(notification); |
297 } | 297 } |
298 | 298 |
299 } // namespace syncer | 299 } // namespace syncer |
OLD | NEW |