| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 << "SetupSync should not be used for legacy supervised users."; | 148 << "SetupSync should not be used for legacy supervised users."; |
| 149 | 149 |
| 150 // Initialize the sync client's profile sync service object. | 150 // Initialize the sync client's profile sync service object. |
| 151 if (service() == NULL) { | 151 if (service() == NULL) { |
| 152 LOG(ERROR) << "SetupSync(): service() is null."; | 152 LOG(ERROR) << "SetupSync(): service() is null."; |
| 153 return false; | 153 return false; |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Tell the sync service that setup is in progress so we don't start syncing | 156 // Tell the sync service that setup is in progress so we don't start syncing |
| 157 // until we've finished configuration. | 157 // until we've finished configuration. |
| 158 service()->SetSetupInProgress(true); | 158 setup_handle_ = service()->GetSetupInProgressHandle(); |
| 159 | 159 |
| 160 DCHECK(!username_.empty()); | 160 DCHECK(!username_.empty()); |
| 161 if (signin_type_ == SigninType::UI_SIGNIN) { | 161 if (signin_type_ == SigninType::UI_SIGNIN) { |
| 162 Browser* browser = chrome::FindBrowserWithProfile(profile_); | 162 Browser* browser = chrome::FindBrowserWithProfile(profile_); |
| 163 DCHECK(browser); | 163 DCHECK(browser); |
| 164 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { | 164 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { |
| 165 LOG(ERROR) << "Could not sign in to GAIA servers."; | 165 LOG(ERROR) << "Could not sign in to GAIA servers."; |
| 166 setup_handle_.reset(); |
| 166 return false; | 167 return false; |
| 167 } | 168 } |
| 168 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { | 169 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { |
| 169 // Authenticate sync client using GAIA credentials. | 170 // Authenticate sync client using GAIA credentials. |
| 170 std::string gaia_id = GetGaiaIdForUsername(username_); | 171 std::string gaia_id = GetGaiaIdForUsername(username_); |
| 171 service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); | 172 service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); |
| 172 std::string account_id = service()->signin()->GetAuthenticatedAccountId(); | 173 std::string account_id = service()->signin()->GetAuthenticatedAccountId(); |
| 173 service()->GoogleSigninSucceeded(account_id, username_, password_); | 174 service()->GoogleSigninSucceeded(account_id, username_, password_); |
| 174 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 175 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 175 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); | 176 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); |
| 176 } else { | 177 } else { |
| 177 LOG(ERROR) << "Unsupported profile signin type."; | 178 LOG(ERROR) << "Unsupported profile signin type."; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Now that auth is completed, request that sync actually start. | 181 // Now that auth is completed, request that sync actually start. |
| 181 service()->RequestStart(); | 182 service()->RequestStart(); |
| 182 | 183 |
| 183 if (!AwaitBackendInitialization()) { | 184 if (!AwaitBackendInitialization()) { |
| 185 setup_handle_.reset(); |
| 184 return false; | 186 return false; |
| 185 } | 187 } |
| 186 | 188 |
| 187 // Choose the datatypes to be synced. If all datatypes are to be synced, | 189 // Choose the datatypes to be synced. If all datatypes are to be synced, |
| 188 // set sync_everything to true; otherwise, set it to false. | 190 // set sync_everything to true; otherwise, set it to false. |
| 189 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); | 191 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); |
| 190 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 192 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 191 | 193 |
| 192 // Notify ProfileSyncService that we are done with configuration. | 194 // Notify ProfileSyncService that we are done with configuration. |
| 193 FinishSyncSetup(); | 195 FinishSyncSetup(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { | 300 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { |
| 299 return base::StringPrintf("oauth2_refresh_token_%d", | 301 return base::StringPrintf("oauth2_refresh_token_%d", |
| 300 ++oauth2_refesh_token_number_); | 302 ++oauth2_refesh_token_number_); |
| 301 } | 303 } |
| 302 | 304 |
| 303 bool ProfileSyncServiceHarness::IsSyncDisabled() const { | 305 bool ProfileSyncServiceHarness::IsSyncDisabled() const { |
| 304 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); | 306 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void ProfileSyncServiceHarness::FinishSyncSetup() { | 309 void ProfileSyncServiceHarness::FinishSyncSetup() { |
| 308 service()->SetSetupInProgress(false); | 310 setup_handle_.reset(); |
| 309 service()->SetFirstSetupComplete(); | 311 service()->SetFirstSetupComplete(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 314 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
| 313 DCHECK(service() != NULL) << "Sync service has not yet been set up."; | 315 DCHECK(service() != NULL) << "Sync service has not yet been set up."; |
| 314 if (service()->IsSyncActive()) { | 316 if (service()->IsSyncActive()) { |
| 315 return service()->GetLastSessionSnapshot(); | 317 return service()->GetLastSessionSnapshot(); |
| 316 } | 318 } |
| 317 return SyncSessionSnapshot(); | 319 return SyncSessionSnapshot(); |
| 318 } | 320 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 468 |
| 467 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 469 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 468 std::unique_ptr<base::DictionaryValue> value( | 470 std::unique_ptr<base::DictionaryValue> value( |
| 469 sync_driver::sync_ui_util::ConstructAboutInformation( | 471 sync_driver::sync_ui_util::ConstructAboutInformation( |
| 470 service(), service()->signin(), chrome::GetChannel())); | 472 service(), service()->signin(), chrome::GetChannel())); |
| 471 std::string service_status; | 473 std::string service_status; |
| 472 base::JSONWriter::WriteWithOptions( | 474 base::JSONWriter::WriteWithOptions( |
| 473 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 475 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
| 474 return service_status; | 476 return service_status; |
| 475 } | 477 } |
| OLD | NEW |