[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/message_loop.h" |
| 11 | #include "chrome/browser/profile.h" |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 12 | #include "chrome/browser/sync/profile_sync_factory.h" |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 13 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 82d9d295 | 2010-05-15 00:36:16 | [diff] [blame] | 14 | #include "chrome/common/net/fake_network_change_notifier_thread.h" |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 15 | #include "chrome/test/sync/test_http_bridge_factory.h" |
| 16 | |
| 17 | class TestProfileSyncService : public ProfileSyncService { |
| 18 | public: |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 19 | explicit TestProfileSyncService(ProfileSyncFactory* factory, |
| 20 | Profile* profile, |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 21 | bool bootstrap_sync_authentication, |
| 22 | bool synchronous_backend_initialization) |
[email protected] | 82d9d295 | 2010-05-15 00:36:16 | [diff] [blame] | 23 | : ProfileSyncService(factory, profile, |
| 24 | &fake_network_change_notifier_thread_, |
| 25 | bootstrap_sync_authentication), |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 26 | synchronous_backend_initialization_( |
| 27 | synchronous_backend_initialization) { |
[email protected] | 12d10d4 | 2010-05-19 02:31:10 | [diff] [blame] | 28 | fake_network_change_notifier_thread_.Start(); |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 29 | RegisterPreferences(); |
| 30 | SetSyncSetupCompleted(); |
| 31 | } |
| 32 | virtual ~TestProfileSyncService() { |
[email protected] | 12d10d4 | 2010-05-19 02:31:10 | [diff] [blame] | 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(); |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | virtual void InitializeBackend(bool delete_sync_data_folder) { |
| 42 | browser_sync::TestHttpBridgeFactory* factory = |
| 43 | new browser_sync::TestHttpBridgeFactory(); |
| 44 | browser_sync::TestHttpBridgeFactory* factory2 = |
| 45 | new browser_sync::TestHttpBridgeFactory(); |
[email protected] | 82d9d295 | 2010-05-15 00:36:16 | [diff] [blame] | 46 | backend()->InitializeForTestMode( |
| 47 | L"testuser", &fake_network_change_notifier_thread_, |
| 48 | factory, factory2, delete_sync_data_folder, |
| 49 | browser_sync::kDefaultNotificationMethod); |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 50 | // TODO(akalin): Figure out a better way to do this. |
| 51 | if (synchronous_backend_initialization_) { |
| 52 | // The SyncBackend posts a task to the current loop when |
| 53 | // initialization completes. |
| 54 | MessageLoop::current()->Run(); |
| 55 | // Initialization is synchronous for test mode, so we should be |
| 56 | // good to go. |
| 57 | DCHECK(sync_initialized()); |
| 58 | } |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | virtual void OnBackendInitialized() { |
| 62 | ProfileSyncService::OnBackendInitialized(); |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 63 | // TODO(akalin): Figure out a better way to do this. |
| 64 | if (synchronous_backend_initialization_) { |
| 65 | MessageLoop::current()->Quit(); |
| 66 | } |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | private: |
| 70 | // When testing under ChromiumOS, this method must not return an empty |
| 71 | // value value in order for the profile sync service to start. |
| 72 | virtual std::string GetLsidForAuthBootstraping() { |
| 73 | return "foo"; |
| 74 | } |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 75 | |
| 76 | bool synchronous_backend_initialization_; |
[email protected] | 82d9d295 | 2010-05-15 00:36:16 | [diff] [blame] | 77 | chrome_common_net::FakeNetworkChangeNotifierThread |
| 78 | fake_network_change_notifier_thread_; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |