| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <ostream> | 10 #include <ostream> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <sstream> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 18 #include "base/task.h" | 19 #include "base/task.h" |
| 19 #include "base/tracked.h" | 20 #include "base/tracked.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sync/sessions/session_state.h" | 22 #include "chrome/browser/sync/sessions/session_state.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 bool StateChangeTimeoutEvent::Abort() { | 85 bool StateChangeTimeoutEvent::Abort() { |
| 85 aborted_ = true; | 86 aborted_ = true; |
| 86 caller_ = NULL; | 87 caller_ = NULL; |
| 87 return !did_timeout_; | 88 return !did_timeout_; |
| 88 } | 89 } |
| 89 | 90 |
| 90 ProfileSyncServiceHarness::ProfileSyncServiceHarness( | 91 ProfileSyncServiceHarness::ProfileSyncServiceHarness( |
| 91 Profile* profile, | 92 Profile* profile, |
| 92 const std::string& username, | 93 const std::string& username, |
| 93 const std::string& password, | 94 const std::string& password) |
| 94 int id) | |
| 95 : waiting_for_encryption_type_(syncable::UNSPECIFIED), | 95 : waiting_for_encryption_type_(syncable::UNSPECIFIED), |
| 96 wait_state_(INITIAL_WAIT_STATE), | 96 wait_state_(INITIAL_WAIT_STATE), |
| 97 profile_(profile), | 97 profile_(profile), |
| 98 service_(NULL), | 98 service_(NULL), |
| 99 timestamp_match_partner_(NULL), | 99 timestamp_match_partner_(NULL), |
| 100 username_(username), | 100 username_(username), |
| 101 password_(password), | 101 password_(password), |
| 102 id_(id) { | 102 profile_debug_name_(profile->GetDebugName()) { |
| 103 if (IsSyncAlreadySetup()) { | 103 if (IsSyncAlreadySetup()) { |
| 104 service_ = profile_->GetProfileSyncService(); | 104 service_ = profile_->GetProfileSyncService(); |
| 105 service_->AddObserver(this); | 105 service_->AddObserver(this); |
| 106 wait_state_ = FULLY_SYNCED; | 106 wait_state_ = FULLY_SYNCED; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( | 111 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( |
| 112 Profile* profile) { | 112 Profile* profile) { |
| 113 if (!profile->HasProfileSyncService()) { | 113 if (!profile->HasProfileSyncService()) { |
| 114 NOTREACHED() << "Profile has never signed into sync."; | 114 NOTREACHED() << "Profile has never signed into sync."; |
| 115 return NULL; | 115 return NULL; |
| 116 } | 116 } |
| 117 return new ProfileSyncServiceHarness(profile, "", "", 0); | 117 return new ProfileSyncServiceHarness(profile, "", ""); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, | 120 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, |
| 121 const std::string& password) { | 121 const std::string& password) { |
| 122 username_ = username; | 122 username_ = username; |
| 123 password_ = password; | 123 password_ = password; |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { | 126 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { |
| 127 return profile_->HasProfileSyncService(); | 127 return profile_->HasProfileSyncService(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool ProfileSyncServiceHarness::SetupSync() { | 130 bool ProfileSyncServiceHarness::SetupSync() { |
| 131 syncable::ModelTypeSet synced_datatypes; | 131 syncable::ModelTypeSet synced_datatypes; |
| 132 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 132 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 133 i < syncable::MODEL_TYPE_COUNT; ++i) { | 133 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 134 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 134 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
| 135 } | 135 } |
| 136 bool result = SetupSync(synced_datatypes); | 136 bool result = SetupSync(synced_datatypes); |
| 137 if (result == false) { | 137 if (result == false) { |
| 138 std::string status = GetServiceStatus(); | 138 std::string status = GetServiceStatus(); |
| 139 LOG(ERROR) << "Client " << id_ << ": SetupSync failed. Syncer status:\n" | 139 LOG(ERROR) << profile_debug_name_ |
| 140 << status; | 140 << ": SetupSync failed. Syncer status:\n" << status; |
| 141 } else { | 141 } else { |
| 142 VLOG(1) << "Client " << id_ << ": SetupSync successful."; | 142 VLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
| 143 } | 143 } |
| 144 return result; | 144 return result; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool ProfileSyncServiceHarness::SetupSync( | 147 bool ProfileSyncServiceHarness::SetupSync( |
| 148 const syncable::ModelTypeSet& synced_datatypes) { | 148 const syncable::ModelTypeSet& synced_datatypes) { |
| 149 // Initialize the sync client's profile sync service object. | 149 // Initialize the sync client's profile sync service object. |
| 150 service_ = profile_->GetProfileSyncService(""); | 150 service_ = profile_->GetProfileSyncService(""); |
| 151 if (service_ == NULL) { | 151 if (service_ == NULL) { |
| 152 LOG(ERROR) << "SetupSync(): service_ is null."; | 152 LOG(ERROR) << "SetupSync(): service_ is null."; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 203 } |
| 204 | 204 |
| 205 void ProfileSyncServiceHarness::SignalStateComplete() { | 205 void ProfileSyncServiceHarness::SignalStateComplete() { |
| 206 MessageLoop::current()->Quit(); | 206 MessageLoop::current()->Quit(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool ProfileSyncServiceHarness::RunStateChangeMachine() { | 209 bool ProfileSyncServiceHarness::RunStateChangeMachine() { |
| 210 WaitState original_wait_state = wait_state_; | 210 WaitState original_wait_state = wait_state_; |
| 211 switch (wait_state_) { | 211 switch (wait_state_) { |
| 212 case WAITING_FOR_ON_BACKEND_INITIALIZED: { | 212 case WAITING_FOR_ON_BACKEND_INITIALIZED: { |
| 213 LogClientInfo("WAITING_FOR_ON_BACKEND_INITIALIZED", 1); | 213 VLOG(1) << "WAITING_FOR_ON_BACKEND_INITIALIZED: " << GetClientInfo(); |
| 214 if (service()->sync_initialized()) { | 214 if (service()->sync_initialized()) { |
| 215 // The sync backend is initialized. | 215 // The sync backend is initialized. |
| 216 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 216 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
| 217 } | 217 } |
| 218 break; | 218 break; |
| 219 } | 219 } |
| 220 case WAITING_FOR_INITIAL_SYNC: { | 220 case WAITING_FOR_INITIAL_SYNC: { |
| 221 LogClientInfo("WAITING_FOR_INITIAL_SYNC", 1); | 221 VLOG(1) << "WAITING_FOR_INITIAL_SYNC: " << GetClientInfo(); |
| 222 if (IsSynced()) { | 222 if (IsSynced()) { |
| 223 // The first sync cycle is now complete. We can start running tests. | 223 // The first sync cycle is now complete. We can start running tests. |
| 224 SignalStateCompleteWithNextState(FULLY_SYNCED); | 224 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 225 break; | 225 break; |
| 226 } | 226 } |
| 227 if (service()->passphrase_required_reason() == | 227 if (service()->passphrase_required_reason() == |
| 228 sync_api::REASON_SET_PASSPHRASE_FAILED) { | 228 sync_api::REASON_SET_PASSPHRASE_FAILED) { |
| 229 // A passphrase is required for decryption and we don't have it. Do not | 229 // A passphrase is required for decryption and we don't have it. Do not |
| 230 // wait any more. | 230 // wait any more. |
| 231 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); | 231 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); |
| 232 break; | 232 break; |
| 233 } | 233 } |
| 234 break; | 234 break; |
| 235 } | 235 } |
| 236 case WAITING_FOR_SYNC_TO_FINISH: { | 236 case WAITING_FOR_SYNC_TO_FINISH: { |
| 237 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH", 1); | 237 VLOG(1) << "WAITING_FOR_SYNC_TO_FINISH: " << GetClientInfo(); |
| 238 if (IsSynced()) { | 238 if (IsSynced()) { |
| 239 // The sync cycle we were waiting for is complete. | 239 // The sync cycle we were waiting for is complete. |
| 240 SignalStateCompleteWithNextState(FULLY_SYNCED); | 240 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 241 break; | 241 break; |
| 242 } | 242 } |
| 243 if (service()->passphrase_required_reason() == | 243 if (service()->passphrase_required_reason() == |
| 244 sync_api::REASON_SET_PASSPHRASE_FAILED) { | 244 sync_api::REASON_SET_PASSPHRASE_FAILED) { |
| 245 // A passphrase is required for decryption and we don't have it. Do not | 245 // A passphrase is required for decryption and we don't have it. Do not |
| 246 // wait any more. | 246 // wait any more. |
| 247 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); | 247 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); |
| 248 break; | 248 break; |
| 249 } | 249 } |
| 250 if (!GetStatus().server_reachable) { | 250 if (!GetStatus().server_reachable) { |
| 251 // The client cannot reach the sync server because the network is | 251 // The client cannot reach the sync server because the network is |
| 252 // disabled. There is no need to wait anymore. | 252 // disabled. There is no need to wait anymore. |
| 253 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | 253 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
| 254 break; | 254 break; |
| 255 } | 255 } |
| 256 break; | 256 break; |
| 257 } | 257 } |
| 258 case WAITING_FOR_UPDATES: { | 258 case WAITING_FOR_UPDATES: { |
| 259 LogClientInfo("WAITING_FOR_UPDATES", 1); | 259 VLOG(1) << "WAITING_FOR_UPDATES: " << GetClientInfo(); |
| 260 DCHECK(timestamp_match_partner_); | 260 DCHECK(timestamp_match_partner_); |
| 261 if (!MatchesOtherClient(timestamp_match_partner_)) { | 261 if (!MatchesOtherClient(timestamp_match_partner_)) { |
| 262 // The client is not yet fully synced; keep waiting until we converge. | 262 // The client is not yet fully synced; keep waiting until we converge. |
| 263 break; | 263 break; |
| 264 } | 264 } |
| 265 timestamp_match_partner_->service()->RemoveObserver(this); | 265 timestamp_match_partner_->service()->RemoveObserver(this); |
| 266 timestamp_match_partner_ = NULL; | 266 timestamp_match_partner_ = NULL; |
| 267 | 267 |
| 268 SignalStateCompleteWithNextState(FULLY_SYNCED); | 268 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 269 break; | 269 break; |
| 270 } | 270 } |
| 271 case WAITING_FOR_PASSPHRASE_REQUIRED: { | 271 case WAITING_FOR_PASSPHRASE_REQUIRED: { |
| 272 LogClientInfo("WAITING_FOR_PASSPHRASE_REQUIRED", 1); | 272 VLOG(1) << "WAITING_FOR_PASSPHRASE_REQUIRED: " << GetClientInfo(); |
| 273 if (service()->IsPassphraseRequired()) { | 273 if (service()->IsPassphraseRequired()) { |
| 274 // A passphrase is now required. Wait for it to be accepted. | 274 // A passphrase is now required. Wait for it to be accepted. |
| 275 SignalStateCompleteWithNextState(WAITING_FOR_PASSPHRASE_ACCEPTED); | 275 SignalStateCompleteWithNextState(WAITING_FOR_PASSPHRASE_ACCEPTED); |
| 276 } | 276 } |
| 277 break; | 277 break; |
| 278 } | 278 } |
| 279 case WAITING_FOR_PASSPHRASE_ACCEPTED: { | 279 case WAITING_FOR_PASSPHRASE_ACCEPTED: { |
| 280 LogClientInfo("WAITING_FOR_PASSPHRASE_ACCEPTED", 1); | 280 VLOG(1) << "WAITING_FOR_PASSPHRASE_ACCEPTED: " << GetClientInfo(); |
| 281 if (service()->ShouldPushChanges() && | 281 if (service()->ShouldPushChanges() && |
| 282 !service()->IsPassphraseRequired()) { | 282 !service()->IsPassphraseRequired()) { |
| 283 // The passphrase has been accepted, and sync has been restarted. | 283 // The passphrase has been accepted, and sync has been restarted. |
| 284 SignalStateCompleteWithNextState(FULLY_SYNCED); | 284 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 285 } | 285 } |
| 286 break; | 286 break; |
| 287 } | 287 } |
| 288 case WAITING_FOR_ENCRYPTION: { | 288 case WAITING_FOR_ENCRYPTION: { |
| 289 LogClientInfo("WAITING_FOR_ENCRYPTION", 1); | 289 VLOG(1) << "WAITING_FOR_ENCRYPTION: " << GetClientInfo(); |
| 290 if (IsSynced() && | 290 if (IsSynced() && |
| 291 IsTypeEncrypted(waiting_for_encryption_type_) && | 291 IsTypeEncrypted(waiting_for_encryption_type_) && |
| 292 GetLastSessionSnapshot()->num_conflicting_updates == 0) { | 292 GetLastSessionSnapshot()->num_conflicting_updates == 0) { |
| 293 // Encryption is now complete for the the type in which we were waiting. | 293 // Encryption is now complete for the the type in which we were waiting. |
| 294 SignalStateCompleteWithNextState(FULLY_SYNCED); | 294 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 295 break; | 295 break; |
| 296 } | 296 } |
| 297 if (!GetStatus().server_reachable) { | 297 if (!GetStatus().server_reachable) { |
| 298 // The client cannot reach the sync server because the network is | 298 // The client cannot reach the sync server because the network is |
| 299 // disabled. There is no need to wait anymore. | 299 // disabled. There is no need to wait anymore. |
| 300 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | 300 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 break; | 303 break; |
| 304 } | 304 } |
| 305 case WAITING_FOR_SYNC_CONFIGURATION: { | 305 case WAITING_FOR_SYNC_CONFIGURATION: { |
| 306 LogClientInfo("WAITING_FOR_SYNC_CONFIGURATION", 1); | 306 VLOG(1) << "WAITING_FOR_SYNC_CONFIGURATION: " << GetClientInfo(); |
| 307 if (service()->ShouldPushChanges()) { | 307 if (service()->ShouldPushChanges()) { |
| 308 // The Datatype manager is configured and sync is fully initialized. | 308 // The Datatype manager is configured and sync is fully initialized. |
| 309 SignalStateCompleteWithNextState(FULLY_SYNCED); | 309 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 310 } | 310 } |
| 311 break; | 311 break; |
| 312 } | 312 } |
| 313 case SERVER_UNREACHABLE: { | 313 case SERVER_UNREACHABLE: { |
| 314 LogClientInfo("SERVER_UNREACHABLE", 1); | 314 VLOG(1) << "SERVER_UNREACHABLE: " << GetClientInfo(); |
| 315 if (GetStatus().server_reachable) { | 315 if (GetStatus().server_reachable) { |
| 316 // The client was offline due to the network being disabled, but is now | 316 // The client was offline due to the network being disabled, but is now |
| 317 // back online. Wait for the pending sync cycle to complete. | 317 // back online. Wait for the pending sync cycle to complete. |
| 318 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 318 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
| 319 } | 319 } |
| 320 break; | 320 break; |
| 321 } | 321 } |
| 322 case SET_PASSPHRASE_FAILED: { | 322 case SET_PASSPHRASE_FAILED: { |
| 323 // A passphrase is required for decryption. There is nothing the sync | 323 // A passphrase is required for decryption. There is nothing the sync |
| 324 // client can do until SetPassphrase() is called. | 324 // client can do until SetPassphrase() is called. |
| 325 LogClientInfo("SET_PASSPHRASE_FAILED", 1); | 325 VLOG(1) << "SET_PASSPHRASE_FAILED: " << GetClientInfo(); |
| 326 break; | 326 break; |
| 327 } | 327 } |
| 328 case FULLY_SYNCED: { | 328 case FULLY_SYNCED: { |
| 329 // The client is online and fully synced. There is nothing to do. | 329 // The client is online and fully synced. There is nothing to do. |
| 330 LogClientInfo("FULLY_SYNCED", 1); | 330 VLOG(1) << "FULLY_SYNCED: " << GetClientInfo(); |
| 331 break; | 331 break; |
| 332 } | 332 } |
| 333 case SYNC_DISABLED: { | 333 case SYNC_DISABLED: { |
| 334 // Syncing is disabled for the client. There is nothing to do. | 334 // Syncing is disabled for the client. There is nothing to do. |
| 335 LogClientInfo("SYNC_DISABLED", 1); | 335 VLOG(1) << "SYNC_DISABLED: " << GetClientInfo(); |
| 336 break; | 336 break; |
| 337 } | 337 } |
| 338 default: | 338 default: |
| 339 // Invalid state during observer callback which may be triggered by other | 339 // Invalid state during observer callback which may be triggered by other |
| 340 // classes using the the UI message loop. Defer to their handling. | 340 // classes using the the UI message loop. Defer to their handling. |
| 341 break; | 341 break; |
| 342 } | 342 } |
| 343 return original_wait_state != wait_state_; | 343 return original_wait_state != wait_state_; |
| 344 } | 344 } |
| 345 | 345 |
| 346 void ProfileSyncServiceHarness::OnStateChanged() { | 346 void ProfileSyncServiceHarness::OnStateChanged() { |
| 347 RunStateChangeMachine(); | 347 RunStateChangeMachine(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { | 350 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { |
| 351 LogClientInfo("AwaitPassphraseRequired", 1); | 351 VLOG(1) << "AwaitPassphraseRequired: " << GetClientInfo(); |
| 352 if (wait_state_ == SYNC_DISABLED) { | 352 if (wait_state_ == SYNC_DISABLED) { |
| 353 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 353 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 354 return false; | 354 return false; |
| 355 } | 355 } |
| 356 | 356 |
| 357 if (service()->IsPassphraseRequired()) { | 357 if (service()->IsPassphraseRequired()) { |
| 358 // It's already true that a passphrase is required; don't wait. | 358 // It's already true that a passphrase is required; don't wait. |
| 359 return true; | 359 return true; |
| 360 } | 360 } |
| 361 | 361 |
| 362 wait_state_ = WAITING_FOR_PASSPHRASE_REQUIRED; | 362 wait_state_ = WAITING_FOR_PASSPHRASE_REQUIRED; |
| 363 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 363 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 364 "Waiting for passphrase to be required."); | 364 "Waiting for passphrase to be required."); |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { | 367 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { |
| 368 LogClientInfo("AwaitPassphraseAccepted", 1); | 368 VLOG(1) << "AwaitPassphraseAccepted: " << GetClientInfo(); |
| 369 if (wait_state_ == SYNC_DISABLED) { | 369 if (wait_state_ == SYNC_DISABLED) { |
| 370 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 370 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 371 return false; | 371 return false; |
| 372 } | 372 } |
| 373 | 373 |
| 374 if (service()->ShouldPushChanges() && | 374 if (service()->ShouldPushChanges() && |
| 375 !service()->IsPassphraseRequired()) { | 375 !service()->IsPassphraseRequired()) { |
| 376 // Passphrase is already accepted; don't wait. | 376 // Passphrase is already accepted; don't wait. |
| 377 return true; | 377 return true; |
| 378 } | 378 } |
| 379 | 379 |
| 380 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; | 380 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; |
| 381 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 381 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 382 "Waiting for passphrase to be accepted."); | 382 "Waiting for passphrase to be accepted."); |
| 383 } | 383 } |
| 384 | 384 |
| 385 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { | 385 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { |
| 386 LogClientInfo("AwaitBackendInitialized", 1); | 386 VLOG(1) << "AwaitBackendInitialized: " << GetClientInfo(); |
| 387 if (service()->sync_initialized()) { | 387 if (service()->sync_initialized()) { |
| 388 // The sync backend host has already been initialized; don't wait. | 388 // The sync backend host has already been initialized; don't wait. |
| 389 return true; | 389 return true; |
| 390 } | 390 } |
| 391 | 391 |
| 392 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; | 392 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; |
| 393 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 393 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 394 "Waiting for OnBackendInitialized()."); | 394 "Waiting for OnBackendInitialized()."); |
| 395 } | 395 } |
| 396 | 396 |
| 397 bool ProfileSyncServiceHarness::AwaitSyncRestart() { | 397 bool ProfileSyncServiceHarness::AwaitSyncRestart() { |
| 398 LogClientInfo("AwaitSyncRestart", 1); | 398 VLOG(1) << "AwaitSyncRestart: " << GetClientInfo(); |
| 399 if (service()->ShouldPushChanges()) { | 399 if (service()->ShouldPushChanges()) { |
| 400 // Sync has already been restarted; don't wait. | 400 // Sync has already been restarted; don't wait. |
| 401 return true; | 401 return true; |
| 402 } | 402 } |
| 403 | 403 |
| 404 // Wait for the sync backend to be initialized. | 404 // Wait for the sync backend to be initialized. |
| 405 if (!AwaitBackendInitialized()) { | 405 if (!AwaitBackendInitialized()) { |
| 406 LOG(ERROR) << "OnBackendInitialized() not seen after " | 406 LOG(ERROR) << "OnBackendInitialized() not seen after " |
| 407 << kLiveSyncOperationTimeoutMs / 1000 | 407 << kLiveSyncOperationTimeoutMs / 1000 |
| 408 << " seconds."; | 408 << " seconds."; |
| 409 return false; | 409 return false; |
| 410 } | 410 } |
| 411 | 411 |
| 412 // Wait for sync configuration to complete. | 412 // Wait for sync configuration to complete. |
| 413 wait_state_ = WAITING_FOR_SYNC_CONFIGURATION; | 413 wait_state_ = WAITING_FOR_SYNC_CONFIGURATION; |
| 414 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 414 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 415 "Waiting for sync configuration."); | 415 "Waiting for sync configuration."); |
| 416 } | 416 } |
| 417 | 417 |
| 418 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( | 418 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( |
| 419 const std::string& reason) { | 419 const std::string& reason) { |
| 420 LogClientInfo("AwaitSyncCycleCompletion", 1); | 420 VLOG(1) << "AwaitSyncCycleCompletion: " << GetClientInfo(); |
| 421 if (wait_state_ == SYNC_DISABLED) { | 421 if (wait_state_ == SYNC_DISABLED) { |
| 422 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 422 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 423 return false; | 423 return false; |
| 424 } | 424 } |
| 425 | 425 |
| 426 if (IsSynced()) { | 426 if (IsSynced()) { |
| 427 // Client is already synced; don't wait. | 427 // Client is already synced; don't wait. |
| 428 return true; | 428 return true; |
| 429 } | 429 } |
| 430 | 430 |
| 431 if (wait_state_ == SERVER_UNREACHABLE) { | 431 if (wait_state_ == SERVER_UNREACHABLE) { |
| 432 // Client was offline; wait for it to go online, and then wait for sync. | 432 // Client was offline; wait for it to go online, and then wait for sync. |
| 433 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 433 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 434 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); | 434 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); |
| 435 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 435 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 436 } |
| 437 |
| 438 DCHECK(service()->sync_initialized()); |
| 439 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; |
| 440 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 441 if (wait_state_ == FULLY_SYNCED) { |
| 442 // Client is online; sync was successful. |
| 443 return true; |
| 444 } else if (wait_state_ == SERVER_UNREACHABLE) { |
| 445 // Client is offline; sync was unsuccessful. |
| 446 LOG(ERROR) << "Client went offline after waiting for sync to finish"; |
| 447 return false; |
| 436 } else { | 448 } else { |
| 437 DCHECK(service()->sync_initialized()); | 449 LOG(ERROR) << "Invalid wait state: " << wait_state_; |
| 438 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 450 return false; |
| 439 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | |
| 440 if (wait_state_ == FULLY_SYNCED) { | |
| 441 // Client is online; sync was successful. | |
| 442 return true; | |
| 443 } else if (wait_state_ == SERVER_UNREACHABLE) { | |
| 444 // Client is offline; sync was unsuccessful. | |
| 445 return false; | |
| 446 } else { | |
| 447 LOG(ERROR) << "Invalid wait state:" << wait_state_; | |
| 448 return false; | |
| 449 } | |
| 450 } | 451 } |
| 451 } | 452 } |
| 452 | 453 |
| 453 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 454 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 454 ProfileSyncServiceHarness* partner) { | 455 ProfileSyncServiceHarness* partner) { |
| 455 LogClientInfo("AwaitMutualSyncCycleCompletion", 1); | 456 VLOG(1) << "AwaitMutualSyncCycleCompletion: " << GetClientInfo(); |
| 456 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 457 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
| 457 return false; | 458 return false; |
| 458 return partner->WaitUntilTimestampMatches(this, | 459 return partner->WaitUntilTimestampMatches(this, |
| 459 "Sync cycle completion on passive client."); | 460 "Sync cycle completion on passive client."); |
| 460 } | 461 } |
| 461 | 462 |
| 462 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 463 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| 463 std::vector<ProfileSyncServiceHarness*>& partners) { | 464 std::vector<ProfileSyncServiceHarness*>& partners) { |
| 464 LogClientInfo("AwaitGroupSyncCycleCompletion", 1); | 465 VLOG(1) << "AwaitGroupSyncCycleCompletion: " << GetClientInfo(); |
| 465 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 466 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
| 466 return false; | 467 return false; |
| 467 bool return_value = true; | 468 bool return_value = true; |
| 468 for (std::vector<ProfileSyncServiceHarness*>::iterator it = | 469 for (std::vector<ProfileSyncServiceHarness*>::iterator it = |
| 469 partners.begin(); it != partners.end(); ++it) { | 470 partners.begin(); it != partners.end(); ++it) { |
| 470 if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { | 471 if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { |
| 471 return_value = return_value && | 472 return_value = return_value && |
| 472 (*it)->WaitUntilTimestampMatches(this, | 473 (*it)->WaitUntilTimestampMatches(this, |
| 473 "Sync cycle completion on partner client."); | 474 "Sync cycle completion on partner client."); |
| 474 } | 475 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 485 clients.begin(); it != clients.end(); ++it) { | 486 clients.begin(); it != clients.end(); ++it) { |
| 486 if ((*it)->wait_state_ != SYNC_DISABLED) | 487 if ((*it)->wait_state_ != SYNC_DISABLED) |
| 487 return_value = return_value && | 488 return_value = return_value && |
| 488 (*it)->AwaitGroupSyncCycleCompletion(clients); | 489 (*it)->AwaitGroupSyncCycleCompletion(clients); |
| 489 } | 490 } |
| 490 return return_value; | 491 return return_value; |
| 491 } | 492 } |
| 492 | 493 |
| 493 bool ProfileSyncServiceHarness::WaitUntilTimestampMatches( | 494 bool ProfileSyncServiceHarness::WaitUntilTimestampMatches( |
| 494 ProfileSyncServiceHarness* partner, const std::string& reason) { | 495 ProfileSyncServiceHarness* partner, const std::string& reason) { |
| 495 LogClientInfo("WaitUntilTimestampMatches", 1); | 496 VLOG(1) << "WaitUntilTimestampMatches: " << GetClientInfo(); |
| 496 if (wait_state_ == SYNC_DISABLED) { | 497 if (wait_state_ == SYNC_DISABLED) { |
| 497 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 498 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 498 return false; | 499 return false; |
| 499 } | 500 } |
| 500 | 501 |
| 501 if (MatchesOtherClient(partner)) { | 502 if (MatchesOtherClient(partner)) { |
| 502 // Timestamps already match; don't wait. | 503 // Timestamps already match; don't wait. |
| 503 return true; | 504 return true; |
| 504 } | 505 } |
| 505 | 506 |
| 506 DCHECK(!timestamp_match_partner_); | 507 DCHECK(!timestamp_match_partner_); |
| 507 timestamp_match_partner_ = partner; | 508 timestamp_match_partner_ = partner; |
| 508 partner->service()->AddObserver(this); | 509 partner->service()->AddObserver(this); |
| 509 wait_state_ = WAITING_FOR_UPDATES; | 510 wait_state_ = WAITING_FOR_UPDATES; |
| 510 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 511 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 511 } | 512 } |
| 512 | 513 |
| 513 bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout( | 514 bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout( |
| 514 int timeout_milliseconds, | 515 int timeout_milliseconds, |
| 515 const std::string& reason) { | 516 const std::string& reason) { |
| 516 LogClientInfo("AwaitStatusChangeWithTimeout", 1); | 517 VLOG(1) << "AwaitStatusChangeWithTimeout: " << GetClientInfo(); |
| 517 if (wait_state_ == SYNC_DISABLED) { | 518 if (wait_state_ == SYNC_DISABLED) { |
| 518 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 519 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 519 return false; | 520 return false; |
| 520 } | 521 } |
| 521 scoped_refptr<StateChangeTimeoutEvent> timeout_signal( | 522 scoped_refptr<StateChangeTimeoutEvent> timeout_signal( |
| 522 new StateChangeTimeoutEvent(this, reason)); | 523 new StateChangeTimeoutEvent(this, reason)); |
| 523 MessageLoop* loop = MessageLoop::current(); | 524 MessageLoop* loop = MessageLoop::current(); |
| 524 bool did_allow_nestable_tasks = loop->NestableTasksAllowed(); | 525 bool did_allow_nestable_tasks = loop->NestableTasksAllowed(); |
| 525 loop->SetNestableTasksAllowed(true); | 526 loop->SetNestableTasksAllowed(true); |
| 526 loop->PostDelayedTask( | 527 loop->PostDelayedTask( |
| 527 FROM_HERE, | 528 FROM_HERE, |
| 528 NewRunnableMethod(timeout_signal.get(), | 529 NewRunnableMethod(timeout_signal.get(), |
| 529 &StateChangeTimeoutEvent::Callback), | 530 &StateChangeTimeoutEvent::Callback), |
| 530 timeout_milliseconds); | 531 timeout_milliseconds); |
| 531 loop->Run(); | 532 loop->Run(); |
| 532 loop->SetNestableTasksAllowed(did_allow_nestable_tasks); | 533 loop->SetNestableTasksAllowed(did_allow_nestable_tasks); |
| 533 if (timeout_signal->Abort()) { | 534 if (timeout_signal->Abort()) { |
| 534 LogClientInfo("AwaitStatusChangeWithTimeout succeeded", 1); | 535 VLOG(1) << "AwaitStatusChangeWithTimeout succeeded: " << GetClientInfo(); |
| 535 return true; | 536 return true; |
| 536 } else { | 537 } else { |
| 537 LogClientInfo("AwaitStatusChangeWithTimeout timed out", 0); | 538 VLOG(0) << "AwaitStatusChangeWithTimeout timed out: " << GetClientInfo(); |
| 538 return false; | 539 return false; |
| 539 } | 540 } |
| 540 } | 541 } |
| 541 | 542 |
| 542 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { | 543 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { |
| 543 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; | 544 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; |
| 544 return service()->QueryDetailedSyncStatus(); | 545 return service()->QueryDetailedSyncStatus(); |
| 545 } | 546 } |
| 546 | 547 |
| 547 bool ProfileSyncServiceHarness::IsSynced() { | 548 bool ProfileSyncServiceHarness::IsSynced() { |
| 548 LogClientInfo("IsSynced", 1); | 549 VLOG(1) << "IsSynced: " << GetClientInfo(); |
| 549 if (service() == NULL) | 550 if (service() == NULL) { |
| 551 VLOG(1) << "NULL service; assuming not synced"; |
| 550 return false; | 552 return false; |
| 553 } |
| 551 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 554 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 552 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and | 555 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and |
| 553 // snap->unsynced_count once http://crbug.com/48989 is fixed. | 556 // snap->unsynced_count once http://crbug.com/48989 is fixed. |
| 554 return (snap && | 557 bool is_synced = snap && |
| 555 snap->num_blocking_conflicting_updates == 0 && | 558 snap->num_blocking_conflicting_updates == 0 && |
| 556 ServiceIsPushingChanges() && | 559 ServiceIsPushingChanges() && |
| 557 GetStatus().notifications_enabled && | 560 GetStatus().notifications_enabled && |
| 558 !service()->HasUnsyncedItems() && | 561 !service()->HasUnsyncedItems() && |
| 559 !snap->has_more_to_sync && | 562 !snap->has_more_to_sync && |
| 560 snap->unsynced_count == 0 && | 563 snap->unsynced_count == 0 && |
| 561 !service()->HasPendingBackendMigration() && | 564 !service()->HasPendingBackendMigration() && |
| 562 service()->passphrase_required_reason() != | 565 service()->passphrase_required_reason() != |
| 563 sync_api::REASON_SET_PASSPHRASE_FAILED); | 566 sync_api::REASON_SET_PASSPHRASE_FAILED; |
| 567 VLOG(1) << "IsSynced: " << is_synced; |
| 568 return is_synced; |
| 564 } | 569 } |
| 565 | 570 |
| 566 bool ProfileSyncServiceHarness::MatchesOtherClient( | 571 bool ProfileSyncServiceHarness::MatchesOtherClient( |
| 567 ProfileSyncServiceHarness* partner) { | 572 ProfileSyncServiceHarness* partner) { |
| 568 if (!IsSynced()) | 573 if (!IsSynced()) |
| 569 return false; | 574 return false; |
| 570 | 575 |
| 571 // Only look for a match if we have at least one enabled datatype in | 576 // Only look for a match if we have at least one enabled datatype in |
| 572 // common with the partner client. | 577 // common with the partner client. |
| 573 syncable::ModelTypeSet types, other_types, intersection_types; | 578 syncable::ModelTypeSet types, other_types, intersection_types; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 592 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 597 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
| 593 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; | 598 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; |
| 594 if (service_->sync_initialized()) { | 599 if (service_->sync_initialized()) { |
| 595 return service_->GetLastSessionSnapshot(); | 600 return service_->GetLastSessionSnapshot(); |
| 596 } | 601 } |
| 597 return NULL; | 602 return NULL; |
| 598 } | 603 } |
| 599 | 604 |
| 600 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 605 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
| 601 syncable::ModelType datatype) { | 606 syncable::ModelType datatype) { |
| 602 LogClientInfo("EnableSyncForDatatype", 1); | 607 VLOG(1) << "EnableSyncForDatatype: " << GetClientInfo(); |
| 603 | 608 |
| 604 syncable::ModelTypeSet synced_datatypes; | 609 syncable::ModelTypeSet synced_datatypes; |
| 605 if (wait_state_ == SYNC_DISABLED) { | 610 if (wait_state_ == SYNC_DISABLED) { |
| 606 synced_datatypes.insert(datatype); | 611 synced_datatypes.insert(datatype); |
| 607 return SetupSync(synced_datatypes); | 612 return SetupSync(synced_datatypes); |
| 608 } | 613 } |
| 609 | 614 |
| 610 if (service() == NULL) { | 615 if (service() == NULL) { |
| 611 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; | 616 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; |
| 612 return false; | 617 return false; |
| 613 } | 618 } |
| 614 | 619 |
| 615 service()->GetPreferredDataTypes(&synced_datatypes); | 620 service()->GetPreferredDataTypes(&synced_datatypes); |
| 616 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 621 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
| 617 if (it != synced_datatypes.end()) { | 622 if (it != synced_datatypes.end()) { |
| 618 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 623 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
| 619 << syncable::ModelTypeToString(datatype) | 624 << syncable::ModelTypeToString(datatype) |
| 620 << " on Client " << id_ << "."; | 625 << " on " << profile_debug_name_ << "."; |
| 621 return true; | 626 return true; |
| 622 } | 627 } |
| 623 | 628 |
| 624 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); | 629 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); |
| 625 service()->OnUserChoseDatatypes(false, synced_datatypes); | 630 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 626 if (AwaitSyncCycleCompletion("Datatype configuration.")) { | 631 if (AwaitSyncCycleCompletion("Datatype configuration.")) { |
| 627 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 632 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
| 628 << syncable::ModelTypeToString(datatype) | 633 << syncable::ModelTypeToString(datatype) |
| 629 << " on Client " << id_ << "."; | 634 << " on " << profile_debug_name_ << "."; |
| 630 return true; | 635 return true; |
| 631 } | 636 } |
| 632 | 637 |
| 633 LogClientInfo("EnableSyncForDatatype failed", 0); | 638 VLOG(0) << "EnableSyncForDatatype failed: " << GetClientInfo(); |
| 634 return false; | 639 return false; |
| 635 } | 640 } |
| 636 | 641 |
| 637 bool ProfileSyncServiceHarness::DisableSyncForDatatype( | 642 bool ProfileSyncServiceHarness::DisableSyncForDatatype( |
| 638 syncable::ModelType datatype) { | 643 syncable::ModelType datatype) { |
| 639 LogClientInfo("DisableSyncForDatatype", 1); | 644 VLOG(1) << "DisableSyncForDatatype: " << GetClientInfo(); |
| 640 | 645 |
| 641 syncable::ModelTypeSet synced_datatypes; | 646 syncable::ModelTypeSet synced_datatypes; |
| 642 if (service() == NULL) { | 647 if (service() == NULL) { |
| 643 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; | 648 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; |
| 644 return false; | 649 return false; |
| 645 } | 650 } |
| 646 | 651 |
| 647 service()->GetPreferredDataTypes(&synced_datatypes); | 652 service()->GetPreferredDataTypes(&synced_datatypes); |
| 648 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 653 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
| 649 if (it == synced_datatypes.end()) { | 654 if (it == synced_datatypes.end()) { |
| 650 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 655 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
| 651 << syncable::ModelTypeToString(datatype) | 656 << syncable::ModelTypeToString(datatype) |
| 652 << " on Client " << id_ << "."; | 657 << " on " << profile_debug_name_ << "."; |
| 653 return true; | 658 return true; |
| 654 } | 659 } |
| 655 | 660 |
| 656 synced_datatypes.erase(it); | 661 synced_datatypes.erase(it); |
| 657 service()->OnUserChoseDatatypes(false, synced_datatypes); | 662 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 658 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { | 663 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { |
| 659 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 664 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
| 660 << syncable::ModelTypeToString(datatype) | 665 << syncable::ModelTypeToString(datatype) |
| 661 << " on Client " << id_ << "."; | 666 << " on " << profile_debug_name_ << "."; |
| 662 return true; | 667 return true; |
| 663 } | 668 } |
| 664 | 669 |
| 665 LogClientInfo("DisableSyncForDatatype failed", 0); | 670 VLOG(0) << "DisableSyncForDatatype failed: " << GetClientInfo(); |
| 666 return false; | 671 return false; |
| 667 } | 672 } |
| 668 | 673 |
| 669 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 674 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
| 670 LogClientInfo("EnableSyncForAllDatatypes", 1); | 675 VLOG(1) << "EnableSyncForAllDatatypes: " << GetClientInfo(); |
| 671 | 676 |
| 672 if (wait_state_ == SYNC_DISABLED) { | 677 if (wait_state_ == SYNC_DISABLED) { |
| 673 return SetupSync(); | 678 return SetupSync(); |
| 674 } | 679 } |
| 675 | 680 |
| 676 if (service() == NULL) { | 681 if (service() == NULL) { |
| 677 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 682 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
| 678 return false; | 683 return false; |
| 679 } | 684 } |
| 680 | 685 |
| 681 syncable::ModelTypeSet synced_datatypes; | 686 syncable::ModelTypeSet synced_datatypes; |
| 682 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 687 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 683 i < syncable::MODEL_TYPE_COUNT; | 688 i < syncable::MODEL_TYPE_COUNT; |
| 684 ++i) { | 689 ++i) { |
| 685 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 690 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
| 686 } | 691 } |
| 687 service()->OnUserChoseDatatypes(true, synced_datatypes); | 692 service()->OnUserChoseDatatypes(true, synced_datatypes); |
| 688 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { | 693 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { |
| 689 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " | 694 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " |
| 690 "Client " << id_ << "."; | 695 << profile_debug_name_ << "."; |
| 691 return true; | 696 return true; |
| 692 } | 697 } |
| 693 | 698 |
| 694 LogClientInfo("EnableSyncForAllDatatypes failed", 0); | 699 VLOG(0) << "EnableSyncForAllDatatypes failed: " << GetClientInfo(); |
| 695 return false; | 700 return false; |
| 696 } | 701 } |
| 697 | 702 |
| 698 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 703 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
| 699 LogClientInfo("DisableSyncForAllDatatypes", 1); | 704 VLOG(1) << "DisableSyncForAllDatatypes: " << GetClientInfo(); |
| 700 | 705 |
| 701 if (service() == NULL) { | 706 if (service() == NULL) { |
| 702 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; | 707 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; |
| 703 return false; | 708 return false; |
| 704 } | 709 } |
| 705 | 710 |
| 706 service()->DisableForUser(); | 711 service()->DisableForUser(); |
| 707 wait_state_ = SYNC_DISABLED; | 712 wait_state_ = SYNC_DISABLED; |
| 708 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " | 713 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " |
| 709 "Client " << id_; | 714 << profile_debug_name_; |
| 710 return true; | 715 return true; |
| 711 } | 716 } |
| 712 | 717 |
| 713 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 718 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
| 714 syncable::ModelType model_type) { | 719 syncable::ModelType model_type) { |
| 715 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 720 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 716 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 721 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
| 717 return snap->download_progress_markers[model_type]; | 722 return snap->download_progress_markers[model_type]; |
| 718 } | 723 } |
| 719 | 724 |
| 720 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message, | 725 std::string ProfileSyncServiceHarness::GetClientInfo() { |
| 721 int log_level) { | 726 std::stringstream os; |
| 727 os << profile_debug_name_ << ": "; |
| 722 if (service()) { | 728 if (service()) { |
| 723 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 729 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 730 const ProfileSyncService::Status& status = GetStatus(); |
| 724 if (snap) { | 731 if (snap) { |
| 725 VLOG(log_level) << "Client " << id_ << ": " << message | 732 os << "snapshot: " << snap->ToString() |
| 726 << ": num_updates_downloaded : " | 733 << ", has_unsynced_items: " |
| 727 << snap->syncer_status.num_updates_downloaded_total | 734 << service()->HasUnsyncedItems() |
| 728 << ", has_more_to_sync: " << snap->has_more_to_sync | 735 << ", passphrase_required_reason: " |
| 729 << ", unsynced_count: " << snap->unsynced_count | 736 << sync_api::PassphraseRequiredReasonToString( |
| 730 << ", num_blocking_conflicting_updates: " | 737 service()->passphrase_required_reason()) |
| 731 << snap->num_blocking_conflicting_updates | 738 << ", notifications_enabled: " |
| 732 << ", num_conflicting_updates: " | 739 << status.notifications_enabled |
| 733 << snap->num_conflicting_updates | 740 << ", local_overwrites_total: " |
| 734 << ", has_unsynced_items: " | 741 << status.num_local_overwrites_total |
| 735 << service()->HasUnsyncedItems() | 742 << ", server_overwrites_total: " |
| 736 << ", passphrase_required_reason: " | 743 << status.num_server_overwrites_total |
| 737 << sync_api::PassphraseRequiredReasonToString( | 744 << ", service_is_pushing_changes: " |
| 738 service()->passphrase_required_reason()) | 745 << ServiceIsPushingChanges() |
| 739 << ", notifications_enabled: " | 746 << ", has_pending_backend_migration: " |
| 740 << GetStatus().notifications_enabled | 747 << service()->HasPendingBackendMigration(); |
| 741 << ", service_is_pushing_changes: " | |
| 742 << ServiceIsPushingChanges() | |
| 743 << ", has_pending_backend_migration: " | |
| 744 << service()->HasPendingBackendMigration(); | |
| 745 } else { | 748 } else { |
| 746 VLOG(log_level) << "Client " << id_ << ": " << message | 749 os << "Sync session snapshot not available"; |
| 747 << ": Sync session snapshot not available."; | |
| 748 } | 750 } |
| 749 } else { | 751 } else { |
| 750 VLOG(log_level) << "Client " << id_ << ": " << message | 752 os << "Sync service not available"; |
| 751 << ": Sync service not available."; | |
| 752 } | 753 } |
| 754 return os.str(); |
| 753 } | 755 } |
| 754 | 756 |
| 755 bool ProfileSyncServiceHarness::EnableEncryptionForType( | 757 bool ProfileSyncServiceHarness::EnableEncryptionForType( |
| 756 syncable::ModelType type) { | 758 syncable::ModelType type) { |
| 757 syncable::ModelTypeSet encrypted_types; | 759 syncable::ModelTypeSet encrypted_types; |
| 758 service_->GetEncryptedDataTypes(&encrypted_types); | 760 service_->GetEncryptedDataTypes(&encrypted_types); |
| 759 if (encrypted_types.count(type) > 0) | 761 if (encrypted_types.count(type) > 0) |
| 760 return true; | 762 return true; |
| 761 encrypted_types.insert(type); | 763 encrypted_types.insert(type); |
| 762 service_->EncryptDataTypes(encrypted_types); | 764 service_->EncryptDataTypes(encrypted_types); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 return true; | 797 return true; |
| 796 } | 798 } |
| 797 | 799 |
| 798 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 800 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 799 DictionaryValue value; | 801 DictionaryValue value; |
| 800 sync_ui_util::ConstructAboutInformation(service_, &value); | 802 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 801 std::string service_status; | 803 std::string service_status; |
| 802 base::JSONWriter::Write(&value, true, &service_status); | 804 base::JSONWriter::Write(&value, true, &service_status); |
| 803 return service_status; | 805 return service_status; |
| 804 } | 806 } |
| OLD | NEW |