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 <cstdio> | 5 #include <cstdio> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 LOG(INFO) << "Notifications enabled"; | 56 LOG(INFO) << "Notifications enabled"; |
57 } | 57 } |
58 | 58 |
59 virtual void OnNotificationsDisabled( | 59 virtual void OnNotificationsDisabled( |
60 NotificationsDisabledReason reason) OVERRIDE { | 60 NotificationsDisabledReason reason) OVERRIDE { |
61 LOG(INFO) << "Notifications disabled with reason " | 61 LOG(INFO) << "Notifications disabled with reason " |
62 << NotificationsDisabledReasonToString(reason); | 62 << NotificationsDisabledReasonToString(reason); |
63 } | 63 } |
64 | 64 |
65 virtual void OnIncomingNotification( | 65 virtual void OnIncomingNotification( |
66 const ObjectIdPayloadMap& id_payloads, | 66 const ModelTypePayloadMap& type_payloads, |
67 IncomingNotificationSource source) OVERRIDE { | 67 IncomingNotificationSource source) OVERRIDE { |
68 const ModelTypePayloadMap& type_payloads = | |
69 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); | |
70 for (ModelTypePayloadMap::const_iterator it = | 68 for (ModelTypePayloadMap::const_iterator it = |
71 type_payloads.begin(); it != type_payloads.end(); ++it) { | 69 type_payloads.begin(); it != type_payloads.end(); ++it) { |
72 LOG(INFO) << (source == REMOTE_NOTIFICATION ? "Remote" : "Local") | 70 LOG(INFO) << (source == REMOTE_NOTIFICATION ? "Remote" : "Local") |
73 << " Notification: type = " | 71 << " Notification: type = " |
74 << ModelTypeToString(it->first) | 72 << ModelTypeToString(it->first) |
75 << ", payload = " << it->second; | 73 << ", payload = " << it->second; |
76 } | 74 } |
77 } | 75 } |
78 | 76 |
79 private: | 77 private: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 command_line, | 226 command_line, |
229 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); | 227 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); |
230 const char kClientInfo[] = "sync_listen_notifications"; | 228 const char kClientInfo[] = "sync_listen_notifications"; |
231 NullInvalidationStateTracker null_invalidation_state_tracker; | 229 NullInvalidationStateTracker null_invalidation_state_tracker; |
232 SyncNotifierFactory sync_notifier_factory( | 230 SyncNotifierFactory sync_notifier_factory( |
233 notifier_options, kClientInfo, | 231 notifier_options, kClientInfo, |
234 null_invalidation_state_tracker.AsWeakPtr()); | 232 null_invalidation_state_tracker.AsWeakPtr()); |
235 scoped_ptr<SyncNotifier> sync_notifier( | 233 scoped_ptr<SyncNotifier> sync_notifier( |
236 sync_notifier_factory.CreateSyncNotifier()); | 234 sync_notifier_factory.CreateSyncNotifier()); |
237 NotificationPrinter notification_printer; | 235 NotificationPrinter notification_printer; |
| 236 sync_notifier->AddObserver(¬ification_printer); |
238 | 237 |
239 const char kUniqueId[] = "fake_unique_id"; | 238 const char kUniqueId[] = "fake_unique_id"; |
240 sync_notifier->SetUniqueId(kUniqueId); | 239 sync_notifier->SetUniqueId(kUniqueId); |
241 sync_notifier->UpdateCredentials(email, token); | 240 sync_notifier->UpdateCredentials(email, token); |
242 // Listen for notifications for all known types. | 241 // Listen for notifications for all known types. |
243 sync_notifier->UpdateRegisteredIds( | 242 sync_notifier->UpdateEnabledTypes(ModelTypeSet::All()); |
244 ¬ification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())); | |
245 | 243 |
246 ui_loop.Run(); | 244 ui_loop.Run(); |
247 | 245 |
248 sync_notifier->UpdateRegisteredIds(¬ification_printer, ObjectIdSet()); | 246 sync_notifier->RemoveObserver(¬ification_printer); |
249 io_thread.Stop(); | 247 io_thread.Stop(); |
250 return 0; | 248 return 0; |
251 } | 249 } |
252 | 250 |
253 } // namespace | 251 } // namespace |
254 } // namespace syncer | 252 } // namespace syncer |
255 | 253 |
256 int main(int argc, char* argv[]) { | 254 int main(int argc, char* argv[]) { |
257 return syncer::SyncListenNotificationsMain(argc, argv); | 255 return syncer::SyncListenNotificationsMain(argc, argv); |
258 } | 256 } |
OLD | NEW |