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 service()->IsUsingSecondaryPassphrase()) { | 283 service()->IsUsingSecondaryPassphrase()) { |
284 // The passphrase has been accepted, and sync has been restarted. | 284 // The passphrase has been accepted, and sync has been restarted. |
285 SignalStateCompleteWithNextState(FULLY_SYNCED); | 285 SignalStateCompleteWithNextState(FULLY_SYNCED); |
286 } | 286 } |
287 break; | 287 break; |
288 } | 288 } |
289 case WAITING_FOR_ENCRYPTION: { | 289 case WAITING_FOR_ENCRYPTION: { |
290 LogClientInfo("WAITING_FOR_ENCRYPTION", 1); | 290 VLOG(1) << "WAITING_FOR_ENCRYPTION: " << GetClientInfo(); |
291 if (IsSynced() && | 291 if (IsSynced() && |
292 IsTypeEncrypted(waiting_for_encryption_type_) && | 292 IsTypeEncrypted(waiting_for_encryption_type_) && |
293 GetLastSessionSnapshot()->num_conflicting_updates == 0) { | 293 GetLastSessionSnapshot()->num_conflicting_updates == 0) { |
294 // Encryption is now complete for the the type in which we were waiting. | 294 // Encryption is now complete for the the type in which we were waiting. |
295 SignalStateCompleteWithNextState(FULLY_SYNCED); | 295 SignalStateCompleteWithNextState(FULLY_SYNCED); |
296 break; | 296 break; |
297 } | 297 } |
298 if (!GetStatus().server_reachable) { | 298 if (!GetStatus().server_reachable) { |
299 // The client cannot reach the sync server because the network is | 299 // The client cannot reach the sync server because the network is |
300 // disabled. There is no need to wait anymore. | 300 // disabled. There is no need to wait anymore. |
301 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | 301 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
302 break; | 302 break; |
303 } | 303 } |
304 break; | 304 break; |
305 } | 305 } |
306 case WAITING_FOR_SYNC_CONFIGURATION: { | 306 case WAITING_FOR_SYNC_CONFIGURATION: { |
307 LogClientInfo("WAITING_FOR_SYNC_CONFIGURATION", 1); | 307 VLOG(1) << "WAITING_FOR_SYNC_CONFIGURATION: " << GetClientInfo(); |
308 if (service()->ShouldPushChanges()) { | 308 if (service()->ShouldPushChanges()) { |
309 // The Datatype manager is configured and sync is fully initialized. | 309 // The Datatype manager is configured and sync is fully initialized. |
310 SignalStateCompleteWithNextState(FULLY_SYNCED); | 310 SignalStateCompleteWithNextState(FULLY_SYNCED); |
311 } | 311 } |
312 break; | 312 break; |
313 } | 313 } |
314 case SERVER_UNREACHABLE: { | 314 case SERVER_UNREACHABLE: { |
315 LogClientInfo("SERVER_UNREACHABLE", 1); | 315 VLOG(1) << "SERVER_UNREACHABLE: " << GetClientInfo(); |
316 if (GetStatus().server_reachable) { | 316 if (GetStatus().server_reachable) { |
317 // The client was offline due to the network being disabled, but is now | 317 // The client was offline due to the network being disabled, but is now |
318 // back online. Wait for the pending sync cycle to complete. | 318 // back online. Wait for the pending sync cycle to complete. |
319 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 319 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
320 } | 320 } |
321 break; | 321 break; |
322 } | 322 } |
323 case SET_PASSPHRASE_FAILED: { | 323 case SET_PASSPHRASE_FAILED: { |
324 // A passphrase is required for decryption. There is nothing the sync | 324 // A passphrase is required for decryption. There is nothing the sync |
325 // client can do until SetPassphrase() is called. | 325 // client can do until SetPassphrase() is called. |
326 LogClientInfo("SET_PASSPHRASE_FAILED", 1); | 326 VLOG(1) << "SET_PASSPHRASE_FAILED: " << GetClientInfo(); |
327 break; | 327 break; |
328 } | 328 } |
329 case FULLY_SYNCED: { | 329 case FULLY_SYNCED: { |
330 // The client is online and fully synced. There is nothing to do. | 330 // The client is online and fully synced. There is nothing to do. |
331 LogClientInfo("FULLY_SYNCED", 1); | 331 VLOG(1) << "FULLY_SYNCED: " << GetClientInfo(); |
332 break; | 332 break; |
333 } | 333 } |
334 case SYNC_DISABLED: { | 334 case SYNC_DISABLED: { |
335 // Syncing is disabled for the client. There is nothing to do. | 335 // Syncing is disabled for the client. There is nothing to do. |
336 LogClientInfo("SYNC_DISABLED", 1); | 336 VLOG(1) << "SYNC_DISABLED: " << GetClientInfo(); |
337 break; | 337 break; |
338 } | 338 } |
339 default: | 339 default: |
340 // Invalid state during observer callback which may be triggered by other | 340 // Invalid state during observer callback which may be triggered by other |
341 // classes using the the UI message loop. Defer to their handling. | 341 // classes using the the UI message loop. Defer to their handling. |
342 break; | 342 break; |
343 } | 343 } |
344 return original_wait_state != wait_state_; | 344 return original_wait_state != wait_state_; |
345 } | 345 } |
346 | 346 |
347 void ProfileSyncServiceHarness::OnStateChanged() { | 347 void ProfileSyncServiceHarness::OnStateChanged() { |
348 RunStateChangeMachine(); | 348 RunStateChangeMachine(); |
349 } | 349 } |
350 | 350 |
351 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { | 351 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { |
352 LogClientInfo("AwaitPassphraseRequired", 1); | 352 VLOG(1) << "AwaitPassphraseRequired: " << GetClientInfo(); |
353 if (wait_state_ == SYNC_DISABLED) { | 353 if (wait_state_ == SYNC_DISABLED) { |
354 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 354 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
355 return false; | 355 return false; |
356 } | 356 } |
357 | 357 |
358 if (service()->IsPassphraseRequired()) { | 358 if (service()->IsPassphraseRequired()) { |
359 // It's already true that a passphrase is required; don't wait. | 359 // It's already true that a passphrase is required; don't wait. |
360 return true; | 360 return true; |
361 } | 361 } |
362 | 362 |
363 wait_state_ = WAITING_FOR_PASSPHRASE_REQUIRED; | 363 wait_state_ = WAITING_FOR_PASSPHRASE_REQUIRED; |
364 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 364 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
365 "Waiting for passphrase to be required."); | 365 "Waiting for passphrase to be required."); |
366 } | 366 } |
367 | 367 |
368 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { | 368 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { |
369 LogClientInfo("AwaitPassphraseAccepted", 1); | 369 VLOG(1) << "AwaitPassphraseAccepted: " << GetClientInfo(); |
370 if (wait_state_ == SYNC_DISABLED) { | 370 if (wait_state_ == SYNC_DISABLED) { |
371 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 371 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
372 return false; | 372 return false; |
373 } | 373 } |
374 | 374 |
375 if (service()->ShouldPushChanges() && | 375 if (service()->ShouldPushChanges() && |
376 !service()->IsPassphraseRequired() && | 376 !service()->IsPassphraseRequired() && |
377 service()->IsUsingSecondaryPassphrase()) { | 377 service()->IsUsingSecondaryPassphrase()) { |
378 // Passphrase is already accepted; don't wait. | 378 // Passphrase is already accepted; don't wait. |
379 return true; | 379 return true; |
380 } | 380 } |
381 | 381 |
382 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; | 382 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; |
383 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 383 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
384 "Waiting for passphrase to be accepted."); | 384 "Waiting for passphrase to be accepted."); |
385 } | 385 } |
386 | 386 |
387 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { | 387 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { |
388 LogClientInfo("AwaitBackendInitialized", 1); | 388 VLOG(1) << "AwaitBackendInitialized: " << GetClientInfo(); |
389 if (service()->sync_initialized()) { | 389 if (service()->sync_initialized()) { |
390 // The sync backend host has already been initialized; don't wait. | 390 // The sync backend host has already been initialized; don't wait. |
391 return true; | 391 return true; |
392 } | 392 } |
393 | 393 |
394 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; | 394 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; |
395 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 395 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
396 "Waiting for OnBackendInitialized()."); | 396 "Waiting for OnBackendInitialized()."); |
397 } | 397 } |
398 | 398 |
399 bool ProfileSyncServiceHarness::AwaitSyncRestart() { | 399 bool ProfileSyncServiceHarness::AwaitSyncRestart() { |
400 LogClientInfo("AwaitSyncRestart", 1); | 400 VLOG(1) << "AwaitSyncRestart: " << GetClientInfo(); |
401 if (service()->ShouldPushChanges()) { | 401 if (service()->ShouldPushChanges()) { |
402 // Sync has already been restarted; don't wait. | 402 // Sync has already been restarted; don't wait. |
403 return true; | 403 return true; |
404 } | 404 } |
405 | 405 |
406 // Wait for the sync backend to be initialized. | 406 // Wait for the sync backend to be initialized. |
407 if (!AwaitBackendInitialized()) { | 407 if (!AwaitBackendInitialized()) { |
408 LOG(ERROR) << "OnBackendInitialized() not seen after " | 408 LOG(ERROR) << "OnBackendInitialized() not seen after " |
409 << kLiveSyncOperationTimeoutMs / 1000 | 409 << kLiveSyncOperationTimeoutMs / 1000 |
410 << " seconds."; | 410 << " seconds."; |
411 return false; | 411 return false; |
412 } | 412 } |
413 | 413 |
414 // Wait for sync configuration to complete. | 414 // Wait for sync configuration to complete. |
415 wait_state_ = WAITING_FOR_SYNC_CONFIGURATION; | 415 wait_state_ = WAITING_FOR_SYNC_CONFIGURATION; |
416 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 416 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
417 "Waiting for sync configuration."); | 417 "Waiting for sync configuration."); |
418 } | 418 } |
419 | 419 |
420 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( | 420 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( |
421 const std::string& reason) { | 421 const std::string& reason) { |
422 LogClientInfo("AwaitSyncCycleCompletion", 1); | 422 VLOG(1) << "AwaitSyncCycleCompletion: " << GetClientInfo(); |
423 if (wait_state_ == SYNC_DISABLED) { | 423 if (wait_state_ == SYNC_DISABLED) { |
424 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 424 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
425 return false; | 425 return false; |
426 } | 426 } |
427 | 427 |
428 if (IsSynced()) { | 428 if (IsSynced()) { |
429 // Client is already synced; don't wait. | 429 // Client is already synced; don't wait. |
430 return true; | 430 return true; |
431 } | 431 } |
432 | 432 |
433 if (wait_state_ == SERVER_UNREACHABLE) { | 433 if (wait_state_ == SERVER_UNREACHABLE) { |
434 // Client was offline; wait for it to go online, and then wait for sync. | 434 // Client was offline; wait for it to go online, and then wait for sync. |
435 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 435 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
436 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); | 436 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); |
437 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 437 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 438 } |
| 439 |
| 440 DCHECK(service()->sync_initialized()); |
| 441 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; |
| 442 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 443 if (wait_state_ == FULLY_SYNCED) { |
| 444 // Client is online; sync was successful. |
| 445 return true; |
| 446 } else if (wait_state_ == SERVER_UNREACHABLE) { |
| 447 // Client is offline; sync was unsuccessful. |
| 448 LOG(ERROR) << "Client went offline after waiting for sync to finish"; |
| 449 return false; |
438 } else { | 450 } else { |
439 DCHECK(service()->sync_initialized()); | 451 LOG(ERROR) << "Invalid wait state: " << wait_state_; |
440 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 452 return false; |
441 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | |
442 if (wait_state_ == FULLY_SYNCED) { | |
443 // Client is online; sync was successful. | |
444 return true; | |
445 } else if (wait_state_ == SERVER_UNREACHABLE) { | |
446 // Client is offline; sync was unsuccessful. | |
447 return false; | |
448 } else { | |
449 LOG(ERROR) << "Invalid wait state:" << wait_state_; | |
450 return false; | |
451 } | |
452 } | 453 } |
453 } | 454 } |
454 | 455 |
455 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 456 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
456 ProfileSyncServiceHarness* partner) { | 457 ProfileSyncServiceHarness* partner) { |
457 LogClientInfo("AwaitMutualSyncCycleCompletion", 1); | 458 VLOG(1) << "AwaitMutualSyncCycleCompletion: " << GetClientInfo(); |
458 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 459 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
459 return false; | 460 return false; |
460 return partner->WaitUntilTimestampMatches(this, | 461 return partner->WaitUntilTimestampMatches(this, |
461 "Sync cycle completion on passive client."); | 462 "Sync cycle completion on passive client."); |
462 } | 463 } |
463 | 464 |
464 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 465 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
465 std::vector<ProfileSyncServiceHarness*>& partners) { | 466 std::vector<ProfileSyncServiceHarness*>& partners) { |
466 LogClientInfo("AwaitGroupSyncCycleCompletion", 1); | 467 VLOG(1) << "AwaitGroupSyncCycleCompletion: " << GetClientInfo(); |
467 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 468 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
468 return false; | 469 return false; |
469 bool return_value = true; | 470 bool return_value = true; |
470 for (std::vector<ProfileSyncServiceHarness*>::iterator it = | 471 for (std::vector<ProfileSyncServiceHarness*>::iterator it = |
471 partners.begin(); it != partners.end(); ++it) { | 472 partners.begin(); it != partners.end(); ++it) { |
472 if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { | 473 if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { |
473 return_value = return_value && | 474 return_value = return_value && |
474 (*it)->WaitUntilTimestampMatches(this, | 475 (*it)->WaitUntilTimestampMatches(this, |
475 "Sync cycle completion on partner client."); | 476 "Sync cycle completion on partner client."); |
476 } | 477 } |
(...skipping 10 matching lines...) Expand all Loading... |
487 clients.begin(); it != clients.end(); ++it) { | 488 clients.begin(); it != clients.end(); ++it) { |
488 if ((*it)->wait_state_ != SYNC_DISABLED) | 489 if ((*it)->wait_state_ != SYNC_DISABLED) |
489 return_value = return_value && | 490 return_value = return_value && |
490 (*it)->AwaitGroupSyncCycleCompletion(clients); | 491 (*it)->AwaitGroupSyncCycleCompletion(clients); |
491 } | 492 } |
492 return return_value; | 493 return return_value; |
493 } | 494 } |
494 | 495 |
495 bool ProfileSyncServiceHarness::WaitUntilTimestampMatches( | 496 bool ProfileSyncServiceHarness::WaitUntilTimestampMatches( |
496 ProfileSyncServiceHarness* partner, const std::string& reason) { | 497 ProfileSyncServiceHarness* partner, const std::string& reason) { |
497 LogClientInfo("WaitUntilTimestampMatches", 1); | 498 VLOG(1) << "WaitUntilTimestampMatches: " << GetClientInfo(); |
498 if (wait_state_ == SYNC_DISABLED) { | 499 if (wait_state_ == SYNC_DISABLED) { |
499 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 500 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
500 return false; | 501 return false; |
501 } | 502 } |
502 | 503 |
503 if (MatchesOtherClient(partner)) { | 504 if (MatchesOtherClient(partner)) { |
504 // Timestamps already match; don't wait. | 505 // Timestamps already match; don't wait. |
505 return true; | 506 return true; |
506 } | 507 } |
507 | 508 |
508 DCHECK(!timestamp_match_partner_); | 509 DCHECK(!timestamp_match_partner_); |
509 timestamp_match_partner_ = partner; | 510 timestamp_match_partner_ = partner; |
510 partner->service()->AddObserver(this); | 511 partner->service()->AddObserver(this); |
511 wait_state_ = WAITING_FOR_UPDATES; | 512 wait_state_ = WAITING_FOR_UPDATES; |
512 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 513 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
513 } | 514 } |
514 | 515 |
515 bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout( | 516 bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout( |
516 int timeout_milliseconds, | 517 int timeout_milliseconds, |
517 const std::string& reason) { | 518 const std::string& reason) { |
518 LogClientInfo("AwaitStatusChangeWithTimeout", 1); | 519 VLOG(1) << "AwaitStatusChangeWithTimeout: " << GetClientInfo(); |
519 if (wait_state_ == SYNC_DISABLED) { | 520 if (wait_state_ == SYNC_DISABLED) { |
520 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 521 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
521 return false; | 522 return false; |
522 } | 523 } |
523 scoped_refptr<StateChangeTimeoutEvent> timeout_signal( | 524 scoped_refptr<StateChangeTimeoutEvent> timeout_signal( |
524 new StateChangeTimeoutEvent(this, reason)); | 525 new StateChangeTimeoutEvent(this, reason)); |
525 MessageLoop* loop = MessageLoop::current(); | 526 MessageLoop* loop = MessageLoop::current(); |
526 bool did_allow_nestable_tasks = loop->NestableTasksAllowed(); | 527 bool did_allow_nestable_tasks = loop->NestableTasksAllowed(); |
527 loop->SetNestableTasksAllowed(true); | 528 loop->SetNestableTasksAllowed(true); |
528 loop->PostDelayedTask( | 529 loop->PostDelayedTask( |
529 FROM_HERE, | 530 FROM_HERE, |
530 NewRunnableMethod(timeout_signal.get(), | 531 NewRunnableMethod(timeout_signal.get(), |
531 &StateChangeTimeoutEvent::Callback), | 532 &StateChangeTimeoutEvent::Callback), |
532 timeout_milliseconds); | 533 timeout_milliseconds); |
533 loop->Run(); | 534 loop->Run(); |
534 loop->SetNestableTasksAllowed(did_allow_nestable_tasks); | 535 loop->SetNestableTasksAllowed(did_allow_nestable_tasks); |
535 if (timeout_signal->Abort()) { | 536 if (timeout_signal->Abort()) { |
536 LogClientInfo("AwaitStatusChangeWithTimeout succeeded", 1); | 537 VLOG(1) << "AwaitStatusChangeWithTimeout succeeded: " << GetClientInfo(); |
537 return true; | 538 return true; |
538 } else { | 539 } else { |
539 LogClientInfo("AwaitStatusChangeWithTimeout timed out", 0); | 540 VLOG(0) << "AwaitStatusChangeWithTimeout timed out: " << GetClientInfo(); |
540 return false; | 541 return false; |
541 } | 542 } |
542 } | 543 } |
543 | 544 |
544 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { | 545 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { |
545 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; | 546 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; |
546 return service()->QueryDetailedSyncStatus(); | 547 return service()->QueryDetailedSyncStatus(); |
547 } | 548 } |
548 | 549 |
549 bool ProfileSyncServiceHarness::IsSynced() { | 550 bool ProfileSyncServiceHarness::IsSynced() { |
550 LogClientInfo("IsSynced", 1); | 551 VLOG(1) << "IsSynced: " << GetClientInfo(); |
551 if (service() == NULL) | 552 if (service() == NULL) { |
| 553 VLOG(1) << "NULL service; assuming not synced"; |
552 return false; | 554 return false; |
| 555 } |
553 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 556 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
554 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and | 557 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and |
555 // snap->unsynced_count once http://crbug.com/48989 is fixed. | 558 // snap->unsynced_count once http://crbug.com/48989 is fixed. |
556 return (snap && | 559 bool is_synced = snap && |
557 snap->num_blocking_conflicting_updates == 0 && | 560 snap->num_blocking_conflicting_updates == 0 && |
558 ServiceIsPushingChanges() && | 561 ServiceIsPushingChanges() && |
559 GetStatus().notifications_enabled && | 562 GetStatus().notifications_enabled && |
560 !service()->HasUnsyncedItems() && | 563 !service()->HasUnsyncedItems() && |
561 !snap->has_more_to_sync && | 564 !snap->has_more_to_sync && |
562 snap->unsynced_count == 0 && | 565 snap->unsynced_count == 0 && |
563 !service()->HasPendingBackendMigration() && | 566 !service()->HasPendingBackendMigration() && |
564 service()->passphrase_required_reason() != | 567 service()->passphrase_required_reason() != |
565 sync_api::REASON_SET_PASSPHRASE_FAILED); | 568 sync_api::REASON_SET_PASSPHRASE_FAILED; |
| 569 VLOG(1) << "IsSynced: " << is_synced; |
| 570 return is_synced; |
566 } | 571 } |
567 | 572 |
568 bool ProfileSyncServiceHarness::MatchesOtherClient( | 573 bool ProfileSyncServiceHarness::MatchesOtherClient( |
569 ProfileSyncServiceHarness* partner) { | 574 ProfileSyncServiceHarness* partner) { |
570 if (!IsSynced()) | 575 if (!IsSynced()) |
571 return false; | 576 return false; |
572 | 577 |
573 // Only look for a match if we have at least one enabled datatype in | 578 // Only look for a match if we have at least one enabled datatype in |
574 // common with the partner client. | 579 // common with the partner client. |
575 syncable::ModelTypeSet types, other_types, intersection_types; | 580 syncable::ModelTypeSet types, other_types, intersection_types; |
(...skipping 18 matching lines...) Expand all Loading... |
594 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 599 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
595 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; | 600 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; |
596 if (service_->sync_initialized()) { | 601 if (service_->sync_initialized()) { |
597 return service_->GetLastSessionSnapshot(); | 602 return service_->GetLastSessionSnapshot(); |
598 } | 603 } |
599 return NULL; | 604 return NULL; |
600 } | 605 } |
601 | 606 |
602 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 607 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
603 syncable::ModelType datatype) { | 608 syncable::ModelType datatype) { |
604 LogClientInfo("EnableSyncForDatatype", 1); | 609 VLOG(1) << "EnableSyncForDatatype: " << GetClientInfo(); |
605 | 610 |
606 syncable::ModelTypeSet synced_datatypes; | 611 syncable::ModelTypeSet synced_datatypes; |
607 if (wait_state_ == SYNC_DISABLED) { | 612 if (wait_state_ == SYNC_DISABLED) { |
608 synced_datatypes.insert(datatype); | 613 synced_datatypes.insert(datatype); |
609 return SetupSync(synced_datatypes); | 614 return SetupSync(synced_datatypes); |
610 } | 615 } |
611 | 616 |
612 if (service() == NULL) { | 617 if (service() == NULL) { |
613 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; | 618 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; |
614 return false; | 619 return false; |
615 } | 620 } |
616 | 621 |
617 service()->GetPreferredDataTypes(&synced_datatypes); | 622 service()->GetPreferredDataTypes(&synced_datatypes); |
618 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 623 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
619 if (it != synced_datatypes.end()) { | 624 if (it != synced_datatypes.end()) { |
620 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 625 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
621 << syncable::ModelTypeToString(datatype) | 626 << syncable::ModelTypeToString(datatype) |
622 << " on Client " << id_ << "."; | 627 << " on " << profile_debug_name_ << "."; |
623 return true; | 628 return true; |
624 } | 629 } |
625 | 630 |
626 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); | 631 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); |
627 service()->OnUserChoseDatatypes(false, synced_datatypes); | 632 service()->OnUserChoseDatatypes(false, synced_datatypes); |
628 if (AwaitSyncCycleCompletion("Datatype configuration.")) { | 633 if (AwaitSyncCycleCompletion("Datatype configuration.")) { |
629 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 634 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
630 << syncable::ModelTypeToString(datatype) | 635 << syncable::ModelTypeToString(datatype) |
631 << " on Client " << id_ << "."; | 636 << " on " << profile_debug_name_ << "."; |
632 return true; | 637 return true; |
633 } | 638 } |
634 | 639 |
635 LogClientInfo("EnableSyncForDatatype failed", 0); | 640 VLOG(0) << "EnableSyncForDatatype failed: " << GetClientInfo(); |
636 return false; | 641 return false; |
637 } | 642 } |
638 | 643 |
639 bool ProfileSyncServiceHarness::DisableSyncForDatatype( | 644 bool ProfileSyncServiceHarness::DisableSyncForDatatype( |
640 syncable::ModelType datatype) { | 645 syncable::ModelType datatype) { |
641 LogClientInfo("DisableSyncForDatatype", 1); | 646 VLOG(1) << "DisableSyncForDatatype: " << GetClientInfo(); |
642 | 647 |
643 syncable::ModelTypeSet synced_datatypes; | 648 syncable::ModelTypeSet synced_datatypes; |
644 if (service() == NULL) { | 649 if (service() == NULL) { |
645 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; | 650 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; |
646 return false; | 651 return false; |
647 } | 652 } |
648 | 653 |
649 service()->GetPreferredDataTypes(&synced_datatypes); | 654 service()->GetPreferredDataTypes(&synced_datatypes); |
650 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 655 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
651 if (it == synced_datatypes.end()) { | 656 if (it == synced_datatypes.end()) { |
652 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 657 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
653 << syncable::ModelTypeToString(datatype) | 658 << syncable::ModelTypeToString(datatype) |
654 << " on Client " << id_ << "."; | 659 << " on " << profile_debug_name_ << "."; |
655 return true; | 660 return true; |
656 } | 661 } |
657 | 662 |
658 synced_datatypes.erase(it); | 663 synced_datatypes.erase(it); |
659 service()->OnUserChoseDatatypes(false, synced_datatypes); | 664 service()->OnUserChoseDatatypes(false, synced_datatypes); |
660 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { | 665 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { |
661 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 666 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
662 << syncable::ModelTypeToString(datatype) | 667 << syncable::ModelTypeToString(datatype) |
663 << " on Client " << id_ << "."; | 668 << " on " << profile_debug_name_ << "."; |
664 return true; | 669 return true; |
665 } | 670 } |
666 | 671 |
667 LogClientInfo("DisableSyncForDatatype failed", 0); | 672 VLOG(0) << "DisableSyncForDatatype failed: " << GetClientInfo(); |
668 return false; | 673 return false; |
669 } | 674 } |
670 | 675 |
671 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 676 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
672 LogClientInfo("EnableSyncForAllDatatypes", 1); | 677 VLOG(1) << "EnableSyncForAllDatatypes: " << GetClientInfo(); |
673 | 678 |
674 if (wait_state_ == SYNC_DISABLED) { | 679 if (wait_state_ == SYNC_DISABLED) { |
675 return SetupSync(); | 680 return SetupSync(); |
676 } | 681 } |
677 | 682 |
678 if (service() == NULL) { | 683 if (service() == NULL) { |
679 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 684 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
680 return false; | 685 return false; |
681 } | 686 } |
682 | 687 |
683 syncable::ModelTypeSet synced_datatypes; | 688 syncable::ModelTypeSet synced_datatypes; |
684 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 689 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
685 i < syncable::MODEL_TYPE_COUNT; | 690 i < syncable::MODEL_TYPE_COUNT; |
686 ++i) { | 691 ++i) { |
687 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 692 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
688 } | 693 } |
689 service()->OnUserChoseDatatypes(true, synced_datatypes); | 694 service()->OnUserChoseDatatypes(true, synced_datatypes); |
690 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { | 695 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { |
691 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " | 696 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " |
692 "Client " << id_ << "."; | 697 << profile_debug_name_ << "."; |
693 return true; | 698 return true; |
694 } | 699 } |
695 | 700 |
696 LogClientInfo("EnableSyncForAllDatatypes failed", 0); | 701 VLOG(0) << "EnableSyncForAllDatatypes failed: " << GetClientInfo(); |
697 return false; | 702 return false; |
698 } | 703 } |
699 | 704 |
700 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 705 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
701 LogClientInfo("DisableSyncForAllDatatypes", 1); | 706 VLOG(1) << "DisableSyncForAllDatatypes: " << GetClientInfo(); |
702 | 707 |
703 if (service() == NULL) { | 708 if (service() == NULL) { |
704 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; | 709 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; |
705 return false; | 710 return false; |
706 } | 711 } |
707 | 712 |
708 service()->DisableForUser(); | 713 service()->DisableForUser(); |
709 wait_state_ = SYNC_DISABLED; | 714 wait_state_ = SYNC_DISABLED; |
710 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " | 715 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " |
711 "Client " << id_; | 716 << profile_debug_name_; |
712 return true; | 717 return true; |
713 } | 718 } |
714 | 719 |
715 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 720 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
716 syncable::ModelType model_type) { | 721 syncable::ModelType model_type) { |
717 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 722 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
718 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 723 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
719 return snap->download_progress_markers[model_type]; | 724 return snap->download_progress_markers[model_type]; |
720 } | 725 } |
721 | 726 |
722 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message, | 727 std::string ProfileSyncServiceHarness::GetClientInfo() { |
723 int log_level) { | 728 std::stringstream os; |
| 729 os << profile_debug_name_ << ": "; |
724 if (service()) { | 730 if (service()) { |
725 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 731 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 732 const ProfileSyncService::Status& status = GetStatus(); |
726 if (snap) { | 733 if (snap) { |
727 VLOG(log_level) << "Client " << id_ << ": " << message | 734 os << "snapshot: " << snap->ToString() |
728 << ": num_updates_downloaded : " | 735 << ", has_unsynced_items: " |
729 << snap->syncer_status.num_updates_downloaded_total | 736 << service()->HasUnsyncedItems() |
730 << ", has_more_to_sync: " << snap->has_more_to_sync | 737 << ", passphrase_required_reason: " |
731 << ", unsynced_count: " << snap->unsynced_count | 738 << sync_api::PassphraseRequiredReasonToString( |
732 << ", num_blocking_conflicting_updates: " | 739 service()->passphrase_required_reason()) |
733 << snap->num_blocking_conflicting_updates | 740 << ", notifications_enabled: " |
734 << ", num_conflicting_updates: " | 741 << status.notifications_enabled |
735 << snap->num_conflicting_updates | 742 << ", local_overwrites_total: " |
736 << ", has_unsynced_items: " | 743 << status.num_local_overwrites_total |
737 << service()->HasUnsyncedItems() | 744 << ", server_overwrites_total: " |
738 << ", passphrase_required_reason: " | 745 << status.num_server_overwrites_total |
739 << sync_api::PassphraseRequiredReasonToString( | 746 << ", service_is_pushing_changes: " |
740 service()->passphrase_required_reason()) | 747 << ServiceIsPushingChanges() |
741 << ", notifications_enabled: " | 748 << ", has_pending_backend_migration: " |
742 << GetStatus().notifications_enabled | 749 << service()->HasPendingBackendMigration(); |
743 << ", service_is_pushing_changes: " | |
744 << ServiceIsPushingChanges() | |
745 << ", has_pending_backend_migration: " | |
746 << service()->HasPendingBackendMigration(); | |
747 } else { | 750 } else { |
748 VLOG(log_level) << "Client " << id_ << ": " << message | 751 os << "Sync session snapshot not available"; |
749 << ": Sync session snapshot not available."; | |
750 } | 752 } |
751 } else { | 753 } else { |
752 VLOG(log_level) << "Client " << id_ << ": " << message | 754 os << "Sync service not available"; |
753 << ": Sync service not available."; | |
754 } | 755 } |
| 756 return os.str(); |
755 } | 757 } |
756 | 758 |
757 bool ProfileSyncServiceHarness::EnableEncryptionForType( | 759 bool ProfileSyncServiceHarness::EnableEncryptionForType( |
758 syncable::ModelType type) { | 760 syncable::ModelType type) { |
759 syncable::ModelTypeSet encrypted_types; | 761 syncable::ModelTypeSet encrypted_types; |
760 service_->GetEncryptedDataTypes(&encrypted_types); | 762 service_->GetEncryptedDataTypes(&encrypted_types); |
761 if (encrypted_types.count(type) > 0) | 763 if (encrypted_types.count(type) > 0) |
762 return true; | 764 return true; |
763 encrypted_types.insert(type); | 765 encrypted_types.insert(type); |
764 service_->EncryptDataTypes(encrypted_types); | 766 service_->EncryptDataTypes(encrypted_types); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 return true; | 799 return true; |
798 } | 800 } |
799 | 801 |
800 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 802 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
801 DictionaryValue value; | 803 DictionaryValue value; |
802 sync_ui_util::ConstructAboutInformation(service_, &value); | 804 sync_ui_util::ConstructAboutInformation(service_, &value); |
803 std::string service_status; | 805 std::string service_status; |
804 base::JSONWriter::Write(&value, true, &service_status); | 806 base::JSONWriter::Write(&value, true, &service_status); |
805 return service_status; | 807 return service_status; |
806 } | 808 } |
OLD | NEW |