Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test_profile_sync_service.h
blob08b42621a769d774f11c548f8537603c9142cbeb
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service.h"
14 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
15 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/sync_prefs.h"
18 #include "sync/test/engine/test_id_factory.h"
19 #include "testing/gmock/include/gmock/gmock.h"
21 class Profile;
22 class ProfileOAuth2TokenService;
23 class ProfileSyncComponentsFactory;
24 class ProfileSyncComponentsFactoryMock;
26 ACTION(ReturnNewDataTypeManager) {
27 return new browser_sync::DataTypeManagerImpl(arg0,
28 arg1,
29 arg2,
30 arg3,
31 arg4,
32 arg5);
35 namespace browser_sync {
37 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
38 public:
39 SyncBackendHostForProfileSyncTest(
40 Profile* profile,
41 const base::WeakPtr<SyncPrefs>& sync_prefs,
42 base::Closure& callback);
43 virtual ~SyncBackendHostForProfileSyncTest();
45 virtual void RequestConfigureSyncer(
46 syncer::ConfigureReason reason,
47 syncer::ModelTypeSet to_download,
48 syncer::ModelTypeSet to_purge,
49 syncer::ModelTypeSet to_journal,
50 syncer::ModelTypeSet to_unapply,
51 syncer::ModelTypeSet to_ignore,
52 const syncer::ModelSafeRoutingInfo& routing_info,
53 const base::Callback<void(syncer::ModelTypeSet,
54 syncer::ModelTypeSet)>& ready_task,
55 const base::Closure& retry_callback) OVERRIDE;
57 protected:
58 virtual void InitCore(scoped_ptr<DoInitializeOptions> options) OVERRIDE;
60 private:
61 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
62 // Allows extra initialization work to be performed before the backend comes
63 // up.
64 base::Closure& callback_;
67 } // namespace browser_sync
69 class TestProfileSyncService : public ProfileSyncService {
70 public:
71 // TODO(tim): Add ability to inject TokenService alongside SigninManager.
72 // TODO(rogerta): what does above comment mean?
73 TestProfileSyncService(
74 ProfileSyncComponentsFactory* factory,
75 Profile* profile,
76 SigninManagerBase* signin,
77 ProfileOAuth2TokenService* oauth2_token_service,
78 ProfileSyncService::StartBehavior behavior);
80 virtual ~TestProfileSyncService();
82 virtual void OnConfigureDone(
83 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE;
85 // We implement our own version to avoid some DCHECKs.
86 virtual syncer::UserShare* GetUserShare() const OVERRIDE;
88 static BrowserContextKeyedService* BuildAutoStartAsyncInit(
89 content::BrowserContext* profile);
91 ProfileSyncComponentsFactoryMock* components_factory_mock();
93 // |callback| can be used to populate nodes before the OnBackendInitialized
94 // callback fires.
95 void set_backend_init_callback(const base::Closure& callback) {
96 callback_ = callback;
99 syncer::TestIdFactory* id_factory();
101 protected:
102 virtual void CreateBackend() OVERRIDE;
104 // Return NULL handle to use in backend initialization to avoid receiving
105 // js messages on UI loop when it's being destroyed, which are not deleted
106 // and cause memory leak in test.
107 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler()
108 OVERRIDE;
110 private:
111 syncer::TestIdFactory id_factory_;
113 base::Closure callback_;
116 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_