Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/integration/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 syncer::ModelTypeSet synced_datatypes) { | 145 syncer::ModelTypeSet synced_datatypes) { |
| 146 DCHECK(!profile_->IsLegacySupervised()) | 146 DCHECK(!profile_->IsLegacySupervised()) |
| 147 << "SetupSync should not be used for legacy supervised users."; | 147 << "SetupSync should not be used for legacy supervised users."; |
| 148 | 148 |
| 149 // Initialize the sync client's profile sync service object. | 149 // Initialize the sync client's profile sync service object. |
| 150 if (service() == nullptr) { | 150 if (service() == nullptr) { |
| 151 LOG(ERROR) << "SetupSync(): service() is null."; | 151 LOG(ERROR) << "SetupSync(): service() is null."; |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Tell the sync service that setup is in progress so we don't start syncing | |
| 156 // until we've finished configuration. | |
| 157 sync_blocker_ = service()->GetSetupInProgressHandle(); | |
|
pavely
2017/03/07 22:57:53
Sync blocker guarantees that configuration will no
skym
2017/03/07 23:31:10
My understanding is that Sync will not start until
pavely
2017/03/08 01:13:52
Actually login_ui_test_utils::SignInWithUI only si
| |
| 158 | |
| 159 DCHECK(!username_.empty()); | 155 DCHECK(!username_.empty()); |
| 160 if (signin_type_ == SigninType::UI_SIGNIN) { | 156 if (signin_type_ == SigninType::UI_SIGNIN) { |
| 161 Browser* browser = chrome::FindBrowserWithProfile(profile_); | 157 Browser* browser = chrome::FindBrowserWithProfile(profile_); |
| 162 DCHECK(browser); | 158 DCHECK(browser); |
| 163 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { | 159 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { |
| 164 LOG(ERROR) << "Could not sign in to GAIA servers."; | 160 LOG(ERROR) << "Could not sign in to GAIA servers."; |
| 165 return false; | 161 return false; |
| 166 } | 162 } |
| 167 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { | 163 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { |
| 168 // Authenticate sync client using GAIA credentials. | 164 // Authenticate sync client using GAIA credentials. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 181 | 177 |
| 182 if (!AwaitEngineInitialization()) { | 178 if (!AwaitEngineInitialization()) { |
| 183 return false; | 179 return false; |
| 184 } | 180 } |
| 185 | 181 |
| 186 // Choose the datatypes to be synced. If all datatypes are to be synced, | 182 // Choose the datatypes to be synced. If all datatypes are to be synced, |
| 187 // set sync_everything to true; otherwise, set it to false. | 183 // set sync_everything to true; otherwise, set it to false. |
| 188 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); | 184 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); |
| 189 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 185 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 190 | 186 |
| 191 // Notify ProfileSyncService that we are done with configuration. | 187 // Notify ProfileSyncService that it should begin configuration. This |
| 192 FinishSyncSetup(); | 188 // corresponds to the user confirming it's okay to start Sync. |
| 189 service()->SetFirstSetupComplete(); | |
| 193 | 190 |
| 194 if ((signin_type_ == SigninType::UI_SIGNIN) && | 191 if ((signin_type_ == SigninType::UI_SIGNIN) && |
| 195 !login_ui_test_utils::DismissSyncConfirmationDialog( | 192 !login_ui_test_utils::DismissSyncConfirmationDialog( |
| 196 chrome::FindBrowserWithProfile(profile_), | 193 chrome::FindBrowserWithProfile(profile_), |
| 197 base::TimeDelta::FromSeconds(30))) { | 194 base::TimeDelta::FromSeconds(30))) { |
| 198 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; | 195 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; |
| 199 return false; | 196 return false; |
| 200 } | 197 } |
| 201 | 198 |
| 202 // Set an implicit passphrase for encryption if an explicit one hasn't already | 199 // Set an implicit passphrase for encryption if an explicit one hasn't already |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 | 292 |
| 296 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { | 293 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { |
| 297 return base::StringPrintf("oauth2_refresh_token_%d", | 294 return base::StringPrintf("oauth2_refresh_token_%d", |
| 298 ++oauth2_refesh_token_number_); | 295 ++oauth2_refesh_token_number_); |
| 299 } | 296 } |
| 300 | 297 |
| 301 bool ProfileSyncServiceHarness::IsSyncDisabled() const { | 298 bool ProfileSyncServiceHarness::IsSyncDisabled() const { |
| 302 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); | 299 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); |
| 303 } | 300 } |
| 304 | 301 |
| 305 void ProfileSyncServiceHarness::FinishSyncSetup() { | |
| 306 sync_blocker_.reset(); | |
| 307 service()->SetFirstSetupComplete(); | |
| 308 } | |
| 309 | |
| 310 SyncCycleSnapshot ProfileSyncServiceHarness::GetLastCycleSnapshot() const { | 302 SyncCycleSnapshot ProfileSyncServiceHarness::GetLastCycleSnapshot() const { |
| 311 DCHECK(service() != nullptr) << "Sync service has not yet been set up."; | 303 DCHECK(service() != nullptr) << "Sync service has not yet been set up."; |
| 312 if (service()->IsSyncActive()) { | 304 if (service()->IsSyncActive()) { |
| 313 return service()->GetLastCycleSnapshot(); | 305 return service()->GetLastCycleSnapshot(); |
| 314 } | 306 } |
| 315 return SyncCycleSnapshot(); | 307 return SyncCycleSnapshot(); |
| 316 } | 308 } |
| 317 | 309 |
| 318 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 310 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
| 319 syncer::ModelType datatype) { | 311 syncer::ModelType datatype) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 468 |
| 477 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 469 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 478 std::unique_ptr<base::DictionaryValue> value( | 470 std::unique_ptr<base::DictionaryValue> value( |
| 479 syncer::sync_ui_util::ConstructAboutInformation( | 471 syncer::sync_ui_util::ConstructAboutInformation( |
| 480 service(), service()->signin(), chrome::GetChannel())); | 472 service(), service()->signin(), chrome::GetChannel())); |
| 481 std::string service_status; | 473 std::string service_status; |
| 482 base::JSONWriter::WriteWithOptions( | 474 base::JSONWriter::WriteWithOptions( |
| 483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 475 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
| 484 return service_status; | 476 return service_status; |
| 485 } | 477 } |
| OLD | NEW |