[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" |
| 14 | #include "chrome/test/sync/test_http_bridge_factory.h" |
| 15 | |
| 16 | class TestProfileSyncService : public ProfileSyncService { |
| 17 | public: |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 18 | explicit TestProfileSyncService(ProfileSyncFactory* factory, |
| 19 | Profile* profile, |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 20 | bool bootstrap_sync_authentication, |
| 21 | bool synchronous_backend_initialization) |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame^] | 22 | : ProfileSyncService(factory, profile, bootstrap_sync_authentication), |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 23 | synchronous_backend_initialization_( |
| 24 | synchronous_backend_initialization) { |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 25 | RegisterPreferences(); |
| 26 | SetSyncSetupCompleted(); |
| 27 | } |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame^] | 28 | virtual ~TestProfileSyncService() { } |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 29 | |
| 30 | virtual void InitializeBackend(bool delete_sync_data_folder) { |
| 31 | browser_sync::TestHttpBridgeFactory* factory = |
| 32 | new browser_sync::TestHttpBridgeFactory(); |
| 33 | browser_sync::TestHttpBridgeFactory* factory2 = |
| 34 | new browser_sync::TestHttpBridgeFactory(); |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame^] | 35 | backend()->InitializeForTestMode(L"testuser", factory, factory2, |
| 36 | delete_sync_data_folder, browser_sync::kDefaultNotificationMethod); |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 37 | // TODO(akalin): Figure out a better way to do this. |
| 38 | if (synchronous_backend_initialization_) { |
| 39 | // The SyncBackend posts a task to the current loop when |
| 40 | // initialization completes. |
| 41 | MessageLoop::current()->Run(); |
| 42 | // Initialization is synchronous for test mode, so we should be |
| 43 | // good to go. |
| 44 | DCHECK(sync_initialized()); |
| 45 | } |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | virtual void OnBackendInitialized() { |
| 49 | ProfileSyncService::OnBackendInitialized(); |
[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 | MessageLoop::current()->Quit(); |
| 53 | } |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | private: |
| 57 | // When testing under ChromiumOS, this method must not return an empty |
| 58 | // value value in order for the profile sync service to start. |
| 59 | virtual std::string GetLsidForAuthBootstraping() { |
| 60 | return "foo"; |
| 61 | } |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 62 | |
| 63 | bool synchronous_backend_initialization_; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |