blob: 6e04d0ee0b191f5926662bda401a0a911b5e36f7 [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]12d10d42010-05-19 02:31:1028 fake_network_change_notifier_thread_.Start();
[email protected]72a31b42010-02-17 22:26:3329 RegisterPreferences();
30 SetSyncSetupCompleted();
31 }
32 virtual ~TestProfileSyncService() {
[email protected]12d10d42010-05-19 02:31:1033 // 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]72a31b42010-02-17 22:26:3339 }
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]82d9d2952010-05-15 00:36:1646 backend()->InitializeForTestMode(
47 L"testuser", &fake_network_change_notifier_thread_,
48 factory, factory2, delete_sync_data_folder,
49 browser_sync::kDefaultNotificationMethod);
[email protected]4c217582010-05-13 21:37:1450 // 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]72a31b42010-02-17 22:26:3359 }
60
61 virtual void OnBackendInitialized() {
62 ProfileSyncService::OnBackendInitialized();
[email protected]4c217582010-05-13 21:37:1463 // TODO(akalin): Figure out a better way to do this.
64 if (synchronous_backend_initialization_) {
65 MessageLoop::current()->Quit();
66 }
[email protected]72a31b42010-02-17 22:26:3367 }
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]4c217582010-05-13 21:37:1475
76 bool synchronous_backend_initialization_;
[email protected]82d9d2952010-05-15 00:36:1677 chrome_common_net::FakeNetworkChangeNotifierThread
78 fake_network_change_notifier_thread_;
[email protected]72a31b42010-02-17 22:26:3379};
80
81#endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_