blob: 43be463638b56491c5a5d34684ad9e96efce9c71 [file] [log] [blame]
[email protected]72a31b42010-02-17 22:26:331// 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]e3e43d92010-02-26 22:02:3812#include "chrome/browser/sync/profile_sync_factory.h"
[email protected]72a31b42010-02-17 22:26:3313#include "chrome/browser/sync/profile_sync_service.h"
[email protected]82d9d2952010-05-15 00:36:1614#include "chrome/common/net/fake_network_change_notifier_thread.h"
[email protected]72a31b42010-02-17 22:26:3315#include "chrome/test/sync/test_http_bridge_factory.h"
16
17class TestProfileSyncService : public ProfileSyncService {
18 public:
[email protected]e3e43d92010-02-26 22:02:3819 explicit TestProfileSyncService(ProfileSyncFactory* factory,
20 Profile* profile,
[email protected]4c217582010-05-13 21:37:1421 bool bootstrap_sync_authentication,
22 bool synchronous_backend_initialization)
[email protected]82d9d2952010-05-15 00:36:1623 : ProfileSyncService(factory, profile,
24 &fake_network_change_notifier_thread_,
25 bootstrap_sync_authentication),
[email protected]4c217582010-05-13 21:37:1426 synchronous_backend_initialization_(
27 synchronous_backend_initialization) {
[email protected]72a31b42010-02-17 22:26:3328 RegisterPreferences();
29 SetSyncSetupCompleted();
30 }
31 virtual ~TestProfileSyncService() {
32 }
33
34 virtual void InitializeBackend(bool delete_sync_data_folder) {
35 browser_sync::TestHttpBridgeFactory* factory =
36 new browser_sync::TestHttpBridgeFactory();
37 browser_sync::TestHttpBridgeFactory* factory2 =
38 new browser_sync::TestHttpBridgeFactory();
[email protected]82d9d2952010-05-15 00:36:1639 backend()->InitializeForTestMode(
40 L"testuser", &fake_network_change_notifier_thread_,
41 factory, factory2, delete_sync_data_folder,
42 browser_sync::kDefaultNotificationMethod);
[email protected]4c217582010-05-13 21:37:1443 // TODO(akalin): Figure out a better way to do this.
44 if (synchronous_backend_initialization_) {
45 // The SyncBackend posts a task to the current loop when
46 // initialization completes.
47 MessageLoop::current()->Run();
48 // Initialization is synchronous for test mode, so we should be
49 // good to go.
50 DCHECK(sync_initialized());
51 }
[email protected]72a31b42010-02-17 22:26:3352 }
53
54 virtual void OnBackendInitialized() {
55 ProfileSyncService::OnBackendInitialized();
[email protected]4c217582010-05-13 21:37:1456 // TODO(akalin): Figure out a better way to do this.
57 if (synchronous_backend_initialization_) {
58 MessageLoop::current()->Quit();
59 }
[email protected]72a31b42010-02-17 22:26:3360 }
61
62 private:
63 // When testing under ChromiumOS, this method must not return an empty
64 // value value in order for the profile sync service to start.
65 virtual std::string GetLsidForAuthBootstraping() {
66 return "foo";
67 }
[email protected]4c217582010-05-13 21:37:1468
69 bool synchronous_backend_initialization_;
[email protected]82d9d2952010-05-15 00:36:1670 chrome_common_net::FakeNetworkChangeNotifierThread
71 fake_network_change_notifier_thread_;
[email protected]72a31b42010-02-17 22:26:3372};
73
74#endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_