| 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> |
| 11 #include <vector> | |
| 12 | 11 |
| 13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 14 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 15 #include "base/logging.h" | 14 #include "base/logging.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" | 19 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" |
| 21 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" | 20 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 222 |
| 224 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 223 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 225 ProfileSyncServiceHarness* partner) { | 224 ProfileSyncServiceHarness* partner) { |
| 226 std::vector<ProfileSyncServiceHarness*> harnesses; | 225 std::vector<ProfileSyncServiceHarness*> harnesses; |
| 227 harnesses.push_back(this); | 226 harnesses.push_back(this); |
| 228 harnesses.push_back(partner); | 227 harnesses.push_back(partner); |
| 229 return AwaitQuiescence(harnesses); | 228 return AwaitQuiescence(harnesses); |
| 230 } | 229 } |
| 231 | 230 |
| 232 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 231 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| 233 std::vector<ProfileSyncServiceHarness*>& partners) { | 232 const std::vector<ProfileSyncServiceHarness*>& partners) { |
| 234 return AwaitQuiescence(partners); | 233 return AwaitQuiescence(partners); |
| 235 } | 234 } |
| 236 | 235 |
| 237 // static | 236 // static |
| 238 bool ProfileSyncServiceHarness::AwaitQuiescence( | 237 bool ProfileSyncServiceHarness::AwaitQuiescence( |
| 239 std::vector<ProfileSyncServiceHarness*>& clients) { | 238 const std::vector<ProfileSyncServiceHarness*>& clients) { |
| 240 std::vector<ProfileSyncService*> services; | 239 std::vector<ProfileSyncService*> services; |
| 241 if (clients.empty()) { | 240 if (clients.empty()) { |
| 242 return true; | 241 return true; |
| 243 } | 242 } |
| 244 | 243 |
| 245 for (std::vector<ProfileSyncServiceHarness*>::iterator it = clients.begin(); | 244 for (const ProfileSyncServiceHarness* harness : clients) { |
| 246 it != clients.end(); ++it) { | 245 services.push_back(harness->service()); |
| 247 services.push_back((*it)->service()); | |
| 248 } | 246 } |
| 249 QuiesceStatusChangeChecker checker(services); | 247 return QuiesceStatusChangeChecker(services).Wait(); |
| 250 checker.Wait(); | |
| 251 return !checker.TimedOut(); | |
| 252 } | 248 } |
| 253 | 249 |
| 254 bool ProfileSyncServiceHarness::AwaitBackendInitialization() { | 250 bool ProfileSyncServiceHarness::AwaitBackendInitialization() { |
| 255 BackendInitializeChecker checker(service()); | 251 if (!BackendInitializeChecker(service()).Wait()) { |
| 256 checker.Wait(); | |
| 257 | |
| 258 if (checker.TimedOut()) { | |
| 259 LOG(ERROR) << "BackendInitializeChecker timed out."; | 252 LOG(ERROR) << "BackendInitializeChecker timed out."; |
| 260 return false; | 253 return false; |
| 261 } | 254 } |
| 262 | 255 |
| 263 if (!service()->IsBackendInitialized()) { | 256 if (!service()->IsBackendInitialized()) { |
| 264 LOG(ERROR) << "Service backend not initialized."; | 257 LOG(ERROR) << "Service backend not initialized."; |
| 265 return false; | 258 return false; |
| 266 } | 259 } |
| 267 | 260 |
| 268 // Make sure that initial sync wasn't blocked by a missing passphrase. | 261 // Make sure that initial sync wasn't blocked by a missing passphrase. |
| 269 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 262 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
| 270 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 263 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 271 " until SetDecryptionPassphrase is called."; | 264 " until SetDecryptionPassphrase is called."; |
| 272 return false; | 265 return false; |
| 273 } | 266 } |
| 274 | 267 |
| 275 if (HasAuthError(service())) { | 268 if (HasAuthError(service())) { |
| 276 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | 269 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; |
| 277 return false; | 270 return false; |
| 278 } | 271 } |
| 279 | 272 |
| 280 return true; | 273 return true; |
| 281 } | 274 } |
| 282 | 275 |
| 283 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { | 276 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { |
| 284 SyncSetupChecker checker(service()); | 277 if (!SyncSetupChecker(service()).Wait()) { |
| 285 checker.Wait(); | |
| 286 | |
| 287 if (checker.TimedOut()) { | |
| 288 LOG(ERROR) << "SyncSetupChecker timed out."; | 278 LOG(ERROR) << "SyncSetupChecker timed out."; |
| 289 return false; | 279 return false; |
| 290 } | 280 } |
| 291 | 281 |
| 292 // Make sure that initial sync wasn't blocked by a missing passphrase. | 282 // Make sure that initial sync wasn't blocked by a missing passphrase. |
| 293 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 283 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
| 294 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 284 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 295 " until SetDecryptionPassphrase is called."; | 285 " until SetDecryptionPassphrase is called."; |
| 296 return false; | 286 return false; |
| 297 } | 287 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 465 |
| 476 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 466 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 477 std::unique_ptr<base::DictionaryValue> value( | 467 std::unique_ptr<base::DictionaryValue> value( |
| 478 sync_driver::sync_ui_util::ConstructAboutInformation( | 468 sync_driver::sync_ui_util::ConstructAboutInformation( |
| 479 service(), service()->signin(), chrome::GetChannel())); | 469 service(), service()->signin(), chrome::GetChannel())); |
| 480 std::string service_status; | 470 std::string service_status; |
| 481 base::JSONWriter::WriteWithOptions( | 471 base::JSONWriter::WriteWithOptions( |
| 482 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 472 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
| 483 return service_status; | 473 return service_status; |
| 484 } | 474 } |
| OLD | NEW |