blob: f7959982b1bbf54edaf4af5e343bc13d4be1c999 [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"
14#include "chrome/test/sync/test_http_bridge_factory.h"
15
16class TestProfileSyncService : public ProfileSyncService {
17 public:
[email protected]e3e43d92010-02-26 22:02:3818 explicit TestProfileSyncService(ProfileSyncFactory* factory,
19 Profile* profile,
[email protected]4c217582010-05-13 21:37:1420 bool bootstrap_sync_authentication,
21 bool synchronous_backend_initialization)
[email protected]66761b952010-06-25 21:30:3822 : ProfileSyncService(factory, profile, bootstrap_sync_authentication),
[email protected]4c217582010-05-13 21:37:1423 synchronous_backend_initialization_(
24 synchronous_backend_initialization) {
[email protected]72a31b42010-02-17 22:26:3325 RegisterPreferences();
26 SetSyncSetupCompleted();
27 }
[email protected]66761b952010-06-25 21:30:3828 virtual ~TestProfileSyncService() { }
[email protected]72a31b42010-02-17 22:26:3329
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]66761b952010-06-25 21:30:3835 backend()->InitializeForTestMode(L"testuser", factory, factory2,
36 delete_sync_data_folder, browser_sync::kDefaultNotificationMethod);
[email protected]4c217582010-05-13 21:37:1437 // 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]72a31b42010-02-17 22:26:3346 }
47
48 virtual void OnBackendInitialized() {
49 ProfileSyncService::OnBackendInitialized();
[email protected]4c217582010-05-13 21:37:1450 // TODO(akalin): Figure out a better way to do this.
51 if (synchronous_backend_initialization_) {
52 MessageLoop::current()->Quit();
53 }
[email protected]72a31b42010-02-17 22:26:3354 }
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]4c217582010-05-13 21:37:1462
63 bool synchronous_backend_initialization_;
[email protected]72a31b42010-02-17 22:26:3364};
65
66#endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_