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