OLD | NEW |
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 #include "chrome/browser/sync/test_profile_sync_service.h" | 5 #include "chrome/browser/sync/test_profile_sync_service.h" |
6 | 6 |
7 #include "chrome/browser/signin/signin_manager.h" | 7 #include "chrome/browser/signin/signin_manager.h" |
8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
9 #include "chrome/browser/sync/glue/data_type_controller.h" | 9 #include "chrome/browser/sync/glue/data_type_controller.h" |
10 #include "chrome/browser/sync/glue/sync_backend_host.h" | 10 #include "chrome/browser/sync/glue/sync_backend_host.h" |
11 #include "chrome/browser/sync/profile_sync_components_factory.h" | 11 #include "chrome/browser/sync/profile_sync_components_factory.h" |
12 #include "chrome/browser/sync/test/test_http_bridge_factory.h" | 12 #include "chrome/browser/sync/test/test_http_bridge_factory.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
15 #include "sync/internal_api/public/test/test_internal_components_factory.h" | |
16 #include "sync/internal_api/public/user_share.h" | 15 #include "sync/internal_api/public/user_share.h" |
17 #include "sync/js/js_reply_handler.h" | 16 #include "sync/js/js_reply_handler.h" |
18 #include "sync/protocol/encryption.pb.h" | 17 #include "sync/protocol/encryption.pb.h" |
19 #include "sync/syncable/directory.h" | 18 #include "sync/syncable/directory.h" |
20 | 19 |
21 using syncer::ModelSafeRoutingInfo; | 20 using syncer::ModelSafeRoutingInfo; |
22 using syncer::TestInternalComponentsFactory; | 21 using syncer::TestInternalComponentsFactory; |
23 using syncer::sessions::ModelNeutralState; | 22 using syncer::sessions::ModelNeutralState; |
24 using syncer::sessions::SyncSessionSnapshot; | 23 using syncer::sessions::SyncSessionSnapshot; |
25 using syncer::sessions::SyncSourceInfo; | 24 using syncer::sessions::SyncSourceInfo; |
26 using syncer::UserShare; | 25 using syncer::UserShare; |
27 using syncer::syncable::Directory; | 26 using syncer::syncable::Directory; |
28 | 27 |
29 namespace browser_sync { | 28 namespace browser_sync { |
30 | 29 |
31 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( | 30 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
32 Profile* profile, | 31 Profile* profile, |
33 const base::WeakPtr<SyncPrefs>& sync_prefs, | 32 const base::WeakPtr<SyncPrefs>& sync_prefs, |
34 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, | 33 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, |
35 syncer::TestIdFactory& id_factory, | 34 syncer::TestIdFactory& id_factory, |
36 base::Closure& callback, | 35 base::Closure& callback, |
37 bool set_initial_sync_ended_on_init, | 36 bool set_initial_sync_ended_on_init, |
38 bool synchronous_init, | 37 bool synchronous_init, |
39 bool fail_initial_download, | 38 bool fail_initial_download, |
40 bool use_real_database) | 39 syncer::StorageOption storage_option) |
41 : browser_sync::SyncBackendHost( | 40 : browser_sync::SyncBackendHost( |
42 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), | 41 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), |
43 id_factory_(id_factory), | 42 id_factory_(id_factory), |
44 callback_(callback), | 43 callback_(callback), |
45 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), | 44 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), |
46 synchronous_init_(synchronous_init), | 45 synchronous_init_(synchronous_init), |
47 fail_initial_download_(fail_initial_download), | 46 fail_initial_download_(fail_initial_download), |
48 use_real_database_(use_real_database) {} | 47 storage_option_(storage_option) {} |
49 | 48 |
50 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 49 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
51 | 50 |
52 namespace { | 51 namespace { |
53 | 52 |
54 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { | 53 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { |
55 return scoped_ptr<syncer::HttpPostProviderFactory>( | 54 return scoped_ptr<syncer::HttpPostProviderFactory>( |
56 new browser_sync::TestHttpBridgeFactory()); | 55 new browser_sync::TestHttpBridgeFactory()); |
57 } | 56 } |
58 | 57 |
59 } // namespace | 58 } // namespace |
60 | 59 |
61 void SyncBackendHostForProfileSyncTest::InitCore( | 60 void SyncBackendHostForProfileSyncTest::InitCore( |
62 const DoInitializeOptions& options) { | 61 const DoInitializeOptions& options) { |
63 DoInitializeOptions test_options = options; | 62 DoInitializeOptions test_options = options; |
64 test_options.make_http_bridge_factory_fn = | 63 test_options.make_http_bridge_factory_fn = |
65 base::Bind(&MakeTestHttpBridgeFactory); | 64 base::Bind(&MakeTestHttpBridgeFactory); |
66 test_options.credentials.email = "testuser@gmail.com"; | 65 test_options.credentials.email = "testuser@gmail.com"; |
67 test_options.credentials.sync_token = "token"; | 66 test_options.credentials.sync_token = "token"; |
68 test_options.restored_key_for_bootstrapping = ""; | 67 test_options.restored_key_for_bootstrapping = ""; |
69 TestInternalComponentsFactory::StorageOption storage = | 68 syncer::StorageOption storage = storage_option_; |
70 use_real_database_ ? TestInternalComponentsFactory::ON_DISK | |
71 : TestInternalComponentsFactory::IN_MEMORY; | |
72 | 69 |
73 // It'd be nice if we avoided creating the InternalComponentsFactory in the | 70 // It'd be nice if we avoided creating the InternalComponentsFactory in the |
74 // first place, but SyncBackendHost will have created one by now so we must | 71 // first place, but SyncBackendHost will have created one by now so we must |
75 // free it. | 72 // free it. |
76 delete test_options.internal_components_factory; | 73 delete test_options.internal_components_factory; |
77 test_options.internal_components_factory = | 74 test_options.internal_components_factory = |
78 new TestInternalComponentsFactory(storage); | 75 new TestInternalComponentsFactory(storage); |
79 SyncBackendHost::InitCore(test_options); | 76 SyncBackendHost::InitCore(test_options); |
80 // TODO(akalin): Figure out a better way to do this. | 77 // TODO(akalin): Figure out a better way to do this. |
81 if (synchronous_init_) { | 78 if (synchronous_init_) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 : ProfileSyncService(factory, | 164 : ProfileSyncService(factory, |
168 profile, | 165 profile, |
169 signin, | 166 signin, |
170 behavior), | 167 behavior), |
171 synchronous_backend_initialization_( | 168 synchronous_backend_initialization_( |
172 synchronous_backend_initialization), | 169 synchronous_backend_initialization), |
173 synchronous_sync_configuration_(false), | 170 synchronous_sync_configuration_(false), |
174 callback_(callback), | 171 callback_(callback), |
175 set_initial_sync_ended_on_init_(true), | 172 set_initial_sync_ended_on_init_(true), |
176 fail_initial_download_(false), | 173 fail_initial_download_(false), |
177 use_real_database_(false) { | 174 storage_option_(syncer::STORAGE_IN_MEMORY) { |
178 SetSyncSetupCompleted(); | 175 SetSyncSetupCompleted(); |
179 } | 176 } |
180 | 177 |
181 TestProfileSyncService::~TestProfileSyncService() { | 178 TestProfileSyncService::~TestProfileSyncService() { |
182 } | 179 } |
183 | 180 |
184 void TestProfileSyncService::OnBackendInitialized( | 181 void TestProfileSyncService::OnBackendInitialized( |
185 const syncer::WeakHandle<syncer::JsBackend>& backend, | 182 const syncer::WeakHandle<syncer::JsBackend>& backend, |
186 bool success) { | 183 bool success) { |
187 ProfileSyncService::OnBackendInitialized(backend, success); | 184 ProfileSyncService::OnBackendInitialized(backend, success); |
(...skipping 21 matching lines...) Expand all Loading... |
209 | 206 |
210 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { | 207 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { |
211 set_initial_sync_ended_on_init_ = false; | 208 set_initial_sync_ended_on_init_ = false; |
212 } | 209 } |
213 void TestProfileSyncService::set_synchronous_sync_configuration() { | 210 void TestProfileSyncService::set_synchronous_sync_configuration() { |
214 synchronous_sync_configuration_ = true; | 211 synchronous_sync_configuration_ = true; |
215 } | 212 } |
216 void TestProfileSyncService::fail_initial_download() { | 213 void TestProfileSyncService::fail_initial_download() { |
217 fail_initial_download_ = true; | 214 fail_initial_download_ = true; |
218 } | 215 } |
219 void TestProfileSyncService::set_use_real_database() { | 216 void TestProfileSyncService::set_storage_option( |
220 use_real_database_ = true; | 217 syncer::StorageOption storage_option) { |
| 218 storage_option_ = storage_option; |
221 } | 219 } |
222 | 220 |
223 void TestProfileSyncService::CreateBackend() { | 221 void TestProfileSyncService::CreateBackend() { |
224 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 222 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
225 profile(), | 223 profile(), |
226 sync_prefs_.AsWeakPtr(), | 224 sync_prefs_.AsWeakPtr(), |
227 invalidator_storage_.AsWeakPtr(), | 225 invalidator_storage_.AsWeakPtr(), |
228 id_factory_, | 226 id_factory_, |
229 callback_, | 227 callback_, |
230 set_initial_sync_ended_on_init_, | 228 set_initial_sync_ended_on_init_, |
231 synchronous_backend_initialization_, | 229 synchronous_backend_initialization_, |
232 fail_initial_download_, | 230 fail_initial_download_, |
233 use_real_database_)); | 231 storage_option_)); |
234 } | 232 } |
OLD | NEW |