| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 using syncer::sessions::SyncSourceInfo; | 25 using syncer::sessions::SyncSourceInfo; |
| 26 using syncer::UserShare; | 26 using syncer::UserShare; |
| 27 using syncer::syncable::Directory; | 27 using syncer::syncable::Directory; |
| 28 | 28 |
| 29 namespace browser_sync { | 29 namespace browser_sync { |
| 30 | 30 |
| 31 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( | 31 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| 32 Profile* profile, | 32 Profile* profile, |
| 33 const base::WeakPtr<SyncPrefs>& sync_prefs, | 33 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 34 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, | 34 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, |
| 35 syncer::TestIdFactory& id_factory, |
| 36 base::Closure& callback, |
| 35 bool set_initial_sync_ended_on_init, | 37 bool set_initial_sync_ended_on_init, |
| 36 bool synchronous_init, | 38 bool synchronous_init, |
| 37 bool fail_initial_download, | 39 bool fail_initial_download, |
| 38 bool use_real_database) | 40 bool use_real_database) |
| 39 : browser_sync::SyncBackendHost( | 41 : browser_sync::SyncBackendHost( |
| 40 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), | 42 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), |
| 43 id_factory_(id_factory), |
| 44 callback_(callback), |
| 45 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), |
| 41 synchronous_init_(synchronous_init), | 46 synchronous_init_(synchronous_init), |
| 42 fail_initial_download_(fail_initial_download), | 47 fail_initial_download_(fail_initial_download), |
| 43 use_real_database_(use_real_database) {} | 48 use_real_database_(use_real_database) {} |
| 44 | 49 |
| 45 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 50 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
| 46 | 51 |
| 47 namespace { | 52 namespace { |
| 48 | 53 |
| 49 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { | 54 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { |
| 50 return scoped_ptr<syncer::HttpPostProviderFactory>( | 55 return scoped_ptr<syncer::HttpPostProviderFactory>( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 92 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
| 88 const base::Closure& retry_callback) { | 93 const base::Closure& retry_callback) { |
| 89 syncer::ModelTypeSet failed_configuration_types; | 94 syncer::ModelTypeSet failed_configuration_types; |
| 90 if (fail_initial_download_) | 95 if (fail_initial_download_) |
| 91 failed_configuration_types = types_to_config; | 96 failed_configuration_types = types_to_config; |
| 92 | 97 |
| 93 FinishConfigureDataTypesOnFrontendLoop(failed_configuration_types, | 98 FinishConfigureDataTypesOnFrontendLoop(failed_configuration_types, |
| 94 ready_task); | 99 ready_task); |
| 95 } | 100 } |
| 96 | 101 |
| 102 void SyncBackendHostForProfileSyncTest |
| 103 ::HandleSyncManagerInitializationOnFrontendLoop( |
| 104 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success, |
| 105 syncer::ModelTypeSet restored_types) { |
| 106 // Here's our opportunity to pretend to do things that the SyncManager would |
| 107 // normally do during initialization, but can't because this is a test. |
| 108 bool send_passphrase_required = false; |
| 109 if (success) { |
| 110 // Set up any nodes the test wants around before model association. |
| 111 if (!callback_.is_null()) { |
| 112 callback_.Run(); |
| 113 } |
| 114 |
| 115 // Pretend we downloaded initial updates and set initial sync ended bits |
| 116 // if we were asked to. |
| 117 if (set_initial_sync_ended_on_init_) { |
| 118 UserShare* user_share = GetUserShare(); |
| 119 Directory* directory = user_share->directory.get(); |
| 120 |
| 121 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) { |
| 122 ProfileSyncServiceTestHelper::CreateRoot( |
| 123 syncer::NIGORI, user_share, &id_factory_); |
| 124 |
| 125 // A side effect of adding the NIGORI mode (normally done by the |
| 126 // syncer) is a decryption attempt, which will fail the first time. |
| 127 send_passphrase_required = true; |
| 128 } |
| 129 |
| 130 SetInitialSyncEndedForAllTypes(); |
| 131 restored_types = syncer::ModelTypeSet::All(); |
| 132 } |
| 133 } |
| 134 |
| 135 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
| 136 js_backend, success, restored_types); |
| 137 } |
| 138 |
| 139 void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() { |
| 140 UserShare* user_share = GetUserShare(); |
| 141 Directory* directory = user_share->directory.get(); |
| 142 |
| 143 for (int i = syncer::FIRST_REAL_MODEL_TYPE; |
| 144 i < syncer::MODEL_TYPE_COUNT; ++i) { |
| 145 directory->set_initial_sync_ended_for_type( |
| 146 syncer::ModelTypeFromInt(i), true); |
| 147 } |
| 148 } |
| 149 |
| 97 } // namespace browser_sync | 150 } // namespace browser_sync |
| 98 | 151 |
| 99 syncer::TestIdFactory* TestProfileSyncService::id_factory() { | 152 syncer::TestIdFactory* TestProfileSyncService::id_factory() { |
| 100 return &id_factory_; | 153 return &id_factory_; |
| 101 } | 154 } |
| 102 | 155 |
| 103 browser_sync::SyncBackendHostForProfileSyncTest* | 156 browser_sync::SyncBackendHostForProfileSyncTest* |
| 104 TestProfileSyncService::GetBackendForTest() { | 157 TestProfileSyncService::GetBackendForTest() { |
| 105 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( | 158 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( |
| 106 ProfileSyncService::GetBackendForTest()); | 159 ProfileSyncService::GetBackendForTest()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 callback_(callback), | 176 callback_(callback), |
| 124 set_initial_sync_ended_on_init_(true), | 177 set_initial_sync_ended_on_init_(true), |
| 125 fail_initial_download_(false), | 178 fail_initial_download_(false), |
| 126 use_real_database_(false) { | 179 use_real_database_(false) { |
| 127 SetSyncSetupCompleted(); | 180 SetSyncSetupCompleted(); |
| 128 } | 181 } |
| 129 | 182 |
| 130 TestProfileSyncService::~TestProfileSyncService() { | 183 TestProfileSyncService::~TestProfileSyncService() { |
| 131 } | 184 } |
| 132 | 185 |
| 133 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() { | |
| 134 UserShare* user_share = GetUserShare(); | |
| 135 Directory* directory = user_share->directory.get(); | |
| 136 | |
| 137 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | |
| 138 i < syncer::MODEL_TYPE_COUNT; ++i) { | |
| 139 directory->set_initial_sync_ended_for_type( | |
| 140 syncer::ModelTypeFromInt(i), true); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 void TestProfileSyncService::OnBackendInitialized( | 186 void TestProfileSyncService::OnBackendInitialized( |
| 145 const syncer::WeakHandle<syncer::JsBackend>& backend, | 187 const syncer::WeakHandle<syncer::JsBackend>& backend, |
| 146 bool success) { | 188 bool success) { |
| 147 bool send_passphrase_required = false; | |
| 148 if (success) { | |
| 149 // Set this so below code can access GetUserShare(). | |
| 150 backend_initialized_ = true; | |
| 151 | |
| 152 // Set up any nodes the test wants around before model association. | |
| 153 if (!callback_.is_null()) { | |
| 154 callback_.Run(); | |
| 155 callback_.Reset(); | |
| 156 } | |
| 157 | |
| 158 // Pretend we downloaded initial updates and set initial sync ended bits | |
| 159 // if we were asked to. | |
| 160 if (set_initial_sync_ended_on_init_) { | |
| 161 UserShare* user_share = GetUserShare(); | |
| 162 Directory* directory = user_share->directory.get(); | |
| 163 | |
| 164 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) { | |
| 165 ProfileSyncServiceTestHelper::CreateRoot( | |
| 166 syncer::NIGORI, GetUserShare(), | |
| 167 id_factory()); | |
| 168 | |
| 169 // A side effect of adding the NIGORI mode (normally done by the | |
| 170 // syncer) is a decryption attempt, which will fail the first time. | |
| 171 send_passphrase_required = true; | |
| 172 } | |
| 173 | |
| 174 SetInitialSyncEndedForAllTypes(); | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 ProfileSyncService::OnBackendInitialized(backend, success); | 189 ProfileSyncService::OnBackendInitialized(backend, success); |
| 179 if (success && send_passphrase_required) | |
| 180 OnPassphraseRequired(syncer::REASON_DECRYPTION, sync_pb::EncryptedData()); | |
| 181 | 190 |
| 182 // TODO(akalin): Figure out a better way to do this. | 191 // TODO(akalin): Figure out a better way to do this. |
| 183 if (synchronous_backend_initialization_) { | 192 if (synchronous_backend_initialization_) { |
| 184 MessageLoop::current()->Quit(); | 193 MessageLoop::current()->Quit(); |
| 185 } | 194 } |
| 186 } | 195 } |
| 187 | 196 |
| 188 void TestProfileSyncService::Observe( | 197 void TestProfileSyncService::Observe( |
| 189 int type, | 198 int type, |
| 190 const content::NotificationSource& source, | 199 const content::NotificationSource& source, |
| 191 const content::NotificationDetails& details) { | 200 const content::NotificationDetails& details) { |
| 192 ProfileSyncService::Observe(type, source, details); | 201 ProfileSyncService::Observe(type, source, details); |
| 193 if (type == chrome::NOTIFICATION_SYNC_CONFIGURE_DONE && | 202 if (type == chrome::NOTIFICATION_SYNC_CONFIGURE_DONE && |
| 194 !synchronous_sync_configuration_) { | 203 !synchronous_sync_configuration_) { |
| 195 MessageLoop::current()->Quit(); | 204 MessageLoop::current()->Quit(); |
| 196 } | 205 } |
| 197 } | 206 } |
| 198 | 207 |
| 208 UserShare* TestProfileSyncService::GetUserShare() const { |
| 209 return backend_->GetUserShare(); |
| 210 } |
| 211 |
| 199 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { | 212 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { |
| 200 set_initial_sync_ended_on_init_ = false; | 213 set_initial_sync_ended_on_init_ = false; |
| 201 } | 214 } |
| 202 void TestProfileSyncService::set_synchronous_sync_configuration() { | 215 void TestProfileSyncService::set_synchronous_sync_configuration() { |
| 203 synchronous_sync_configuration_ = true; | 216 synchronous_sync_configuration_ = true; |
| 204 } | 217 } |
| 205 void TestProfileSyncService::fail_initial_download() { | 218 void TestProfileSyncService::fail_initial_download() { |
| 206 fail_initial_download_ = true; | 219 fail_initial_download_ = true; |
| 207 } | 220 } |
| 208 void TestProfileSyncService::set_use_real_database() { | 221 void TestProfileSyncService::set_use_real_database() { |
| 209 use_real_database_ = true; | 222 use_real_database_ = true; |
| 210 } | 223 } |
| 211 | 224 |
| 212 void TestProfileSyncService::CreateBackend() { | 225 void TestProfileSyncService::CreateBackend() { |
| 213 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 226 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
| 214 profile(), | 227 profile(), |
| 215 sync_prefs_.AsWeakPtr(), | 228 sync_prefs_.AsWeakPtr(), |
| 216 invalidator_storage_.AsWeakPtr(), | 229 invalidator_storage_.AsWeakPtr(), |
| 230 id_factory_, |
| 231 callback_, |
| 217 set_initial_sync_ended_on_init_, | 232 set_initial_sync_ended_on_init_, |
| 218 synchronous_backend_initialization_, | 233 synchronous_backend_initialization_, |
| 219 fail_initial_download_, | 234 fail_initial_download_, |
| 220 use_real_database_)); | 235 use_real_database_)); |
| 221 } | 236 } |
| OLD | NEW |