| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_factory.h" | 12 #include "chrome/browser/sync/profile_sync_factory.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/common/net/fake_network_change_notifier_thread.h" | |
| 15 #include "chrome/test/sync/test_http_bridge_factory.h" | 14 #include "chrome/test/sync/test_http_bridge_factory.h" |
| 16 | 15 |
| 17 class TestProfileSyncService : public ProfileSyncService { | 16 class TestProfileSyncService : public ProfileSyncService { |
| 18 public: | 17 public: |
| 19 explicit TestProfileSyncService(ProfileSyncFactory* factory, | 18 explicit TestProfileSyncService(ProfileSyncFactory* factory, |
| 20 Profile* profile, | 19 Profile* profile, |
| 21 bool bootstrap_sync_authentication, | 20 bool bootstrap_sync_authentication, |
| 22 bool synchronous_backend_initialization) | 21 bool synchronous_backend_initialization) |
| 23 : ProfileSyncService(factory, profile, | 22 : ProfileSyncService(factory, profile, bootstrap_sync_authentication), |
| 24 &fake_network_change_notifier_thread_, | |
| 25 bootstrap_sync_authentication), | |
| 26 synchronous_backend_initialization_( | 23 synchronous_backend_initialization_( |
| 27 synchronous_backend_initialization) { | 24 synchronous_backend_initialization) { |
| 28 fake_network_change_notifier_thread_.Start(); | |
| 29 RegisterPreferences(); | 25 RegisterPreferences(); |
| 30 SetSyncSetupCompleted(); | 26 SetSyncSetupCompleted(); |
| 31 } | 27 } |
| 32 virtual ~TestProfileSyncService() { | 28 virtual ~TestProfileSyncService() { } |
| 33 // This needs to happen before | |
| 34 // |fake_network_change_notifier_thread_| is stopped. This is | |
| 35 // also called again in ProfileSyncService's destructor, but | |
| 36 // calling it multiple times is okay. | |
| 37 Shutdown(false); | |
| 38 fake_network_change_notifier_thread_.Stop(); | |
| 39 } | |
| 40 | 29 |
| 41 virtual void InitializeBackend(bool delete_sync_data_folder) { | 30 virtual void InitializeBackend(bool delete_sync_data_folder) { |
| 42 browser_sync::TestHttpBridgeFactory* factory = | 31 browser_sync::TestHttpBridgeFactory* factory = |
| 43 new browser_sync::TestHttpBridgeFactory(); | 32 new browser_sync::TestHttpBridgeFactory(); |
| 44 browser_sync::TestHttpBridgeFactory* factory2 = | 33 browser_sync::TestHttpBridgeFactory* factory2 = |
| 45 new browser_sync::TestHttpBridgeFactory(); | 34 new browser_sync::TestHttpBridgeFactory(); |
| 46 backend()->InitializeForTestMode( | 35 backend()->InitializeForTestMode(L"testuser", factory, factory2, |
| 47 L"testuser", &fake_network_change_notifier_thread_, | 36 delete_sync_data_folder, browser_sync::kDefaultNotificationMethod); |
| 48 factory, factory2, delete_sync_data_folder, | |
| 49 browser_sync::kDefaultNotificationMethod); | |
| 50 // TODO(akalin): Figure out a better way to do this. | 37 // TODO(akalin): Figure out a better way to do this. |
| 51 if (synchronous_backend_initialization_) { | 38 if (synchronous_backend_initialization_) { |
| 52 // The SyncBackend posts a task to the current loop when | 39 // The SyncBackend posts a task to the current loop when |
| 53 // initialization completes. | 40 // initialization completes. |
| 54 MessageLoop::current()->Run(); | 41 MessageLoop::current()->Run(); |
| 55 // Initialization is synchronous for test mode, so we should be | 42 // Initialization is synchronous for test mode, so we should be |
| 56 // good to go. | 43 // good to go. |
| 57 DCHECK(sync_initialized()); | 44 DCHECK(sync_initialized()); |
| 58 } | 45 } |
| 59 } | 46 } |
| 60 | 47 |
| 61 virtual void OnBackendInitialized() { | 48 virtual void OnBackendInitialized() { |
| 62 ProfileSyncService::OnBackendInitialized(); | 49 ProfileSyncService::OnBackendInitialized(); |
| 63 // TODO(akalin): Figure out a better way to do this. | 50 // TODO(akalin): Figure out a better way to do this. |
| 64 if (synchronous_backend_initialization_) { | 51 if (synchronous_backend_initialization_) { |
| 65 MessageLoop::current()->Quit(); | 52 MessageLoop::current()->Quit(); |
| 66 } | 53 } |
| 67 } | 54 } |
| 68 | 55 |
| 69 private: | 56 private: |
| 70 // When testing under ChromiumOS, this method must not return an empty | 57 // When testing under ChromiumOS, this method must not return an empty |
| 71 // value value in order for the profile sync service to start. | 58 // value value in order for the profile sync service to start. |
| 72 virtual std::string GetLsidForAuthBootstraping() { | 59 virtual std::string GetLsidForAuthBootstraping() { |
| 73 return "foo"; | 60 return "foo"; |
| 74 } | 61 } |
| 75 | 62 |
| 76 bool synchronous_backend_initialization_; | 63 bool synchronous_backend_initialization_; |
| 77 chrome_common_net::FakeNetworkChangeNotifierThread | |
| 78 fake_network_change_notifier_thread_; | |
| 79 }; | 64 }; |
| 80 | 65 |
| 81 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 66 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
| OLD | NEW |