| 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 "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 5 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
| 6 | 6 |
| 7 #include <cstddef> |
| 8 |
| 7 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 12 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 13 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 ChromeSyncNotificationBridge* bridge, | 48 ChromeSyncNotificationBridge* bridge, |
| 47 const syncer::ObjectIdPayloadMap& expected_payloads, | 49 const syncer::ObjectIdPayloadMap& expected_payloads, |
| 48 syncer::IncomingNotificationSource expected_source) | 50 syncer::IncomingNotificationSource expected_source) |
| 49 : sync_task_runner_(sync_task_runner), | 51 : sync_task_runner_(sync_task_runner), |
| 50 bridge_(bridge), | 52 bridge_(bridge), |
| 51 received_improper_notification_(false), | 53 received_improper_notification_(false), |
| 52 notification_count_(0), | 54 notification_count_(0), |
| 53 expected_payloads_(expected_payloads), | 55 expected_payloads_(expected_payloads), |
| 54 expected_source_(expected_source) { | 56 expected_source_(expected_source) { |
| 55 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 57 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 58 bridge_->RegisterHandler(this); |
| 56 const syncer::ObjectIdSet& ids = | 59 const syncer::ObjectIdSet& ids = |
| 57 syncer::ObjectIdPayloadMapToSet(expected_payloads); | 60 syncer::ObjectIdPayloadMapToSet(expected_payloads); |
| 58 bridge_->UpdateRegisteredIds(this, ids); | 61 bridge_->UpdateRegisteredIds(this, ids); |
| 59 } | 62 } |
| 60 | 63 |
| 61 virtual ~FakeSyncNotifierObserver() { | 64 virtual ~FakeSyncNotifierObserver() { |
| 62 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 65 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 63 bridge_->UpdateRegisteredIds(this, syncer::ObjectIdSet()); | 66 bridge_->UnregisterHandler(this); |
| 64 } | 67 } |
| 65 | 68 |
| 66 // SyncNotifierObserver implementation. | 69 // SyncNotifierObserver implementation. |
| 67 virtual void OnIncomingNotification( | 70 virtual void OnIncomingNotification( |
| 68 const syncer::ObjectIdPayloadMap& id_payloads, | 71 const syncer::ObjectIdPayloadMap& id_payloads, |
| 69 syncer::IncomingNotificationSource source) OVERRIDE { | 72 syncer::IncomingNotificationSource source) OVERRIDE { |
| 70 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 73 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 71 notification_count_++; | 74 notification_count_++; |
| 72 if (source != expected_source_) { | 75 if (source != expected_source_) { |
| 73 LOG(ERROR) << "Received notification with wrong source"; | 76 LOG(ERROR) << "Received notification with wrong source"; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 116 |
| 114 protected: | 117 protected: |
| 115 virtual void SetUp() OVERRIDE { | 118 virtual void SetUp() OVERRIDE { |
| 116 ASSERT_TRUE(sync_thread_.Start()); | 119 ASSERT_TRUE(sync_thread_.Start()); |
| 117 bridge_.reset( | 120 bridge_.reset( |
| 118 new ChromeSyncNotificationBridge( | 121 new ChromeSyncNotificationBridge( |
| 119 &mock_profile_, sync_thread_.message_loop_proxy())); | 122 &mock_profile_, sync_thread_.message_loop_proxy())); |
| 120 } | 123 } |
| 121 | 124 |
| 122 virtual void TearDown() OVERRIDE { | 125 virtual void TearDown() OVERRIDE { |
| 126 bridge_->StopForShutdown(); |
| 123 sync_thread_.Stop(); | 127 sync_thread_.Stop(); |
| 124 // Must be reset only after the sync thread is stopped. | 128 // Must be reset only after the sync thread is stopped. |
| 125 bridge_.reset(); | 129 bridge_.reset(); |
| 126 EXPECT_EQ(NULL, sync_observer_); | 130 EXPECT_EQ(NULL, sync_observer_); |
| 127 if (sync_observer_notification_failure_) | 131 if (sync_observer_notification_failure_) |
| 128 ADD_FAILURE() << "Sync Observer did not receive proper notification."; | 132 ADD_FAILURE() << "Sync Observer did not receive proper notification."; |
| 129 } | 133 } |
| 130 | 134 |
| 131 void VerifyAndDestroyObserver() { | 135 void VerifyAndDestroyObserver() { |
| 132 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( | 136 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 CreateObserverWithExpectations( | 283 CreateObserverWithExpectations( |
| 280 enabled_types_payload_map, syncer::REMOTE_NOTIFICATION); | 284 enabled_types_payload_map, syncer::REMOTE_NOTIFICATION); |
| 281 UpdateBridgeEnabledTypes(enabled_types); | 285 UpdateBridgeEnabledTypes(enabled_types); |
| 282 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 286 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
| 283 syncer::ModelTypePayloadMap()); | 287 syncer::ModelTypePayloadMap()); |
| 284 VerifyAndDestroyObserver(); | 288 VerifyAndDestroyObserver(); |
| 285 } | 289 } |
| 286 | 290 |
| 287 } // namespace | 291 } // namespace |
| 288 } // namespace browser_sync | 292 } // namespace browser_sync |
| OLD | NEW |