Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/browser/sync/test_profile_sync_service.h

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/signin/oauth2_token_service.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/browser/sync/glue/data_type_manager_impl.h" 16 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
14 #include "chrome/browser/sync/invalidations/invalidator_storage.h" 17 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
15 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 18 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 19 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/sync_prefs.h" 20 #include "chrome/browser/sync/sync_prefs.h"
18 #include "chrome/test/base/profile_mock.h" 21 #include "chrome/test/base/profile_mock.h"
19 #include "sync/internal_api/public/test/test_internal_components_factory.h" 22 #include "sync/internal_api/public/test/test_internal_components_factory.h"
20 #include "sync/test/engine/test_id_factory.h" 23 #include "sync/test/engine/test_id_factory.h"
21 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
22 25
23 class Profile; 26 class Profile;
24 class Task; 27 class Task;
25 class TestProfileSyncService; 28 class TestProfileSyncService;
26 29
27 ACTION(ReturnNewDataTypeManager) { 30 ACTION(ReturnNewDataTypeManager) {
28 return new browser_sync::DataTypeManagerImpl(arg0, arg1, arg2, arg3, arg4); 31 return new browser_sync::DataTypeManagerImpl(arg0, arg1, arg2, arg3, arg4);
29 } 32 }
30 33
31 namespace browser_sync { 34 namespace browser_sync {
32 35
36 // MessageLoopRunner::Run() may be called multiple times recursively. Only first
tim (not reviewing) 2013/05/23 19:03:42 Hmm.. this kind of thing (nested Run() calls -- se
37 // call will execute MessageLoop::current()->Run().
38 class MessageLoopRunner {
39 public:
40 MessageLoopRunner();
41 ~MessageLoopRunner();
42
43 void Run();
44 void Quit();
45
46 private:
47 bool running_;
48 };
49
33 class SyncBackendHostForProfileSyncTest : public SyncBackendHost { 50 class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
34 public: 51 public:
35 // |synchronous_init| causes initialization to block until the syncapi has 52 // |synchronous_init| causes initialization to block until the syncapi has
36 // completed setting itself up and called us back. 53 // completed setting itself up and called us back.
37 // TOOD(akalin): Remove |synchronous_init| (http://crbug.com/140354). 54 // TOOD(akalin): Remove |synchronous_init| (http://crbug.com/140354).
38 SyncBackendHostForProfileSyncTest( 55 SyncBackendHostForProfileSyncTest(
39 Profile* profile, 56 Profile* profile,
40 const base::WeakPtr<SyncPrefs>& sync_prefs, 57 const base::WeakPtr<SyncPrefs>& sync_prefs,
41 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, 58 const base::WeakPtr<InvalidatorStorage>& invalidator_storage,
42 syncer::TestIdFactory& id_factory, 59 syncer::TestIdFactory& id_factory,
43 base::Closure& callback, 60 base::Closure& callback,
44 bool set_initial_sync_ended_on_init, 61 bool set_initial_sync_ended_on_init,
45 bool synchronous_init, 62 bool synchronous_init,
46 bool fail_initial_download, 63 bool fail_initial_download,
47 syncer::StorageOption storage_option); 64 syncer::StorageOption storage_option,
65 MessageLoopRunner* message_loop_runner);
48 virtual ~SyncBackendHostForProfileSyncTest(); 66 virtual ~SyncBackendHostForProfileSyncTest();
49 67
50 MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&)); 68 MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&));
51 69
52 virtual void UpdateCredentials( 70 virtual void UpdateCredentials(
53 const syncer::SyncCredentials& credentials) OVERRIDE; 71 const syncer::SyncCredentials& credentials) OVERRIDE;
54 72
55 virtual void RequestConfigureSyncer( 73 virtual void RequestConfigureSyncer(
56 syncer::ConfigureReason reason, 74 syncer::ConfigureReason reason,
57 syncer::ModelTypeSet types_to_config, 75 syncer::ModelTypeSet types_to_config,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // new credentials. Holds the results of 113 // new credentials. Holds the results of
96 // HandleSyncManagerInitializationOnFrontendLoop, and if 114 // HandleSyncManagerInitializationOnFrontendLoop, and if
97 // |fail_initial_download_| was true, finishes the initialization process 115 // |fail_initial_download_| was true, finishes the initialization process
98 // once we receive new credentials. 116 // once we receive new credentials.
99 base::Closure initial_download_closure_; 117 base::Closure initial_download_closure_;
100 bool fail_initial_download_; 118 bool fail_initial_download_;
101 119
102 bool set_initial_sync_ended_on_init_; 120 bool set_initial_sync_ended_on_init_;
103 bool synchronous_init_; 121 bool synchronous_init_;
104 syncer::StorageOption storage_option_; 122 syncer::StorageOption storage_option_;
123 MessageLoopRunner* message_loop_runner_;
105 }; 124 };
106 125
107 } // namespace browser_sync 126 } // namespace browser_sync
108 127
109 class TestProfileSyncService : public ProfileSyncService { 128 class TestProfileSyncService : public ProfileSyncService {
110 public: 129 public:
111 // TODO(tim): Remove |synchronous_backend_initialization|, and add ability to 130 // TODO(tim): Remove |synchronous_backend_initialization|, and add ability to
112 // inject TokenService alongside SigninManager. 131 // inject TokenService alongside SigninManager.
113 TestProfileSyncService( 132 TestProfileSyncService(
114 ProfileSyncComponentsFactory* factory, 133 ProfileSyncComponentsFactory* factory,
115 Profile* profile, 134 Profile* profile,
116 SigninManagerBase* signin, 135 SigninManagerBase* signin,
117 ProfileSyncService::StartBehavior behavior, 136 ProfileSyncService::StartBehavior behavior,
118 bool synchronous_backend_initialization); 137 bool synchronous_backend_initialization);
119 138
120 virtual ~TestProfileSyncService(); 139 virtual ~TestProfileSyncService();
121 140
141 virtual void RequestAccessToken(
142 bool invalidate_previous_token,
143 bool invoke_callback) OVERRIDE;
144 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
145 const GoogleServiceAuthError& error) OVERRIDE;
146
122 virtual void OnBackendInitialized( 147 virtual void OnBackendInitialized(
123 const syncer::WeakHandle<syncer::JsBackend>& backend, 148 const syncer::WeakHandle<syncer::JsBackend>& backend,
124 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 149 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
125 debug_info_listener, 150 debug_info_listener,
126 bool success) OVERRIDE; 151 bool success) OVERRIDE;
127 152
128 virtual void OnConfigureDone( 153 virtual void OnConfigureDone(
129 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE; 154 const browser_sync::DataTypeManager::ConfigureResult& result) OVERRIDE;
130 155
131 // We implement our own version to avoid some DCHECKs. 156 // We implement our own version to avoid some DCHECKs.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 195
171 // Set to true when a mock data type manager is being used and the configure 196 // Set to true when a mock data type manager is being used and the configure
172 // step is performed synchronously. 197 // step is performed synchronously.
173 bool synchronous_sync_configuration_; 198 bool synchronous_sync_configuration_;
174 199
175 base::Closure callback_; 200 base::Closure callback_;
176 bool set_initial_sync_ended_on_init_; 201 bool set_initial_sync_ended_on_init_;
177 202
178 bool fail_initial_download_; 203 bool fail_initial_download_;
179 syncer::StorageOption storage_option_; 204 syncer::StorageOption storage_option_;
205 browser_sync::MessageLoopRunner message_loop_runner_;
206 };
207
208
209 class FakeOAuth2TokenService : public ProfileOAuth2TokenService {
210 public:
211 explicit FakeOAuth2TokenService(net::URLRequestContextGetter* getter)
212 : ProfileOAuth2TokenService(getter) {}
213
214 virtual scoped_ptr<OAuth2TokenService::Request> StartRequest(
215 const OAuth2TokenService::ScopeSet& scopes,
216 OAuth2TokenService::Consumer* consumer);
217
218 static ProfileKeyedService* BuildTokenService(
219 content::BrowserContext* context);
180 }; 220 };
181 221
182 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 222 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698