| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 7 #include <cstddef> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 Profile* profile, | 101 Profile* profile, |
| 102 const std::string& username, | 102 const std::string& username, |
| 103 const std::string& password) | 103 const std::string& password) |
| 104 : waiting_for_encryption_type_(syncable::UNSPECIFIED), | 104 : waiting_for_encryption_type_(syncable::UNSPECIFIED), |
| 105 wait_state_(INITIAL_WAIT_STATE), | 105 wait_state_(INITIAL_WAIT_STATE), |
| 106 profile_(profile), | 106 profile_(profile), |
| 107 service_(NULL), | 107 service_(NULL), |
| 108 timestamp_match_partner_(NULL), | 108 timestamp_match_partner_(NULL), |
| 109 username_(username), | 109 username_(username), |
| 110 password_(password), | 110 password_(password), |
| 111 profile_debug_name_(profile->GetDebugName()) { | 111 profile_debug_name_(profile->GetDebugName()), |
| 112 waiting_for_status_change_(false) { |
| 112 if (IsSyncAlreadySetup()) { | 113 if (IsSyncAlreadySetup()) { |
| 113 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 114 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 114 profile_); | 115 profile_); |
| 115 service_->AddObserver(this); | 116 service_->AddObserver(this); |
| 116 ignore_result(TryListeningToMigrationEvents()); | 117 ignore_result(TryListeningToMigrationEvents()); |
| 117 wait_state_ = FULLY_SYNCED; | 118 wait_state_ = FULLY_SYNCED; |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {} | 122 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {} |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return false; | 256 return false; |
| 256 } | 257 } |
| 257 | 258 |
| 258 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( | 259 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( |
| 259 WaitState next_state) { | 260 WaitState next_state) { |
| 260 wait_state_ = next_state; | 261 wait_state_ = next_state; |
| 261 SignalStateComplete(); | 262 SignalStateComplete(); |
| 262 } | 263 } |
| 263 | 264 |
| 264 void ProfileSyncServiceHarness::SignalStateComplete() { | 265 void ProfileSyncServiceHarness::SignalStateComplete() { |
| 265 MessageLoop::current()->Quit(); | 266 if (waiting_for_status_change_) |
| 267 MessageLoop::current()->Quit(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 bool ProfileSyncServiceHarness::RunStateChangeMachine() { | 270 bool ProfileSyncServiceHarness::RunStateChangeMachine() { |
| 269 WaitState original_wait_state = wait_state_; | 271 WaitState original_wait_state = wait_state_; |
| 270 switch (wait_state_) { | 272 switch (wait_state_) { |
| 271 case WAITING_FOR_ON_BACKEND_INITIALIZED: { | 273 case WAITING_FOR_ON_BACKEND_INITIALIZED: { |
| 272 DVLOG(1) << GetClientInfoString("WAITING_FOR_ON_BACKEND_INITIALIZED"); | 274 DVLOG(1) << GetClientInfoString("WAITING_FOR_ON_BACKEND_INITIALIZED"); |
| 273 if (service()->sync_initialized()) { | 275 if (service()->sync_initialized()) { |
| 274 // The sync backend is initialized. | 276 // The sync backend is initialized. |
| 275 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 277 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 int timeout_milliseconds, | 725 int timeout_milliseconds, |
| 724 const std::string& reason) { | 726 const std::string& reason) { |
| 725 DVLOG(1) << GetClientInfoString("AwaitStatusChangeWithTimeout"); | 727 DVLOG(1) << GetClientInfoString("AwaitStatusChangeWithTimeout"); |
| 726 if (wait_state_ == SYNC_DISABLED) { | 728 if (wait_state_ == SYNC_DISABLED) { |
| 727 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 729 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 728 return false; | 730 return false; |
| 729 } | 731 } |
| 730 scoped_refptr<StateChangeTimeoutEvent> timeout_signal( | 732 scoped_refptr<StateChangeTimeoutEvent> timeout_signal( |
| 731 new StateChangeTimeoutEvent(this, reason)); | 733 new StateChangeTimeoutEvent(this, reason)); |
| 732 { | 734 { |
| 735 // Set the flag to tell SignalStateComplete() that it's OK to quit out of |
| 736 // the MessageLoop if we hit a state transition. |
| 737 waiting_for_status_change_ = true; |
| 733 MessageLoop* loop = MessageLoop::current(); | 738 MessageLoop* loop = MessageLoop::current(); |
| 734 MessageLoop::ScopedNestableTaskAllower allow(loop); | 739 MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 735 loop->PostDelayedTask( | 740 loop->PostDelayedTask( |
| 736 FROM_HERE, | 741 FROM_HERE, |
| 737 base::Bind(&StateChangeTimeoutEvent::Callback, | 742 base::Bind(&StateChangeTimeoutEvent::Callback, |
| 738 timeout_signal.get()), | 743 timeout_signal.get()), |
| 739 base::TimeDelta::FromMilliseconds(timeout_milliseconds)); | 744 base::TimeDelta::FromMilliseconds(timeout_milliseconds)); |
| 740 loop->Run(); | 745 loop->Run(); |
| 746 waiting_for_status_change_ = false; |
| 741 } | 747 } |
| 742 | 748 |
| 743 if (timeout_signal->Abort()) { | 749 if (timeout_signal->Abort()) { |
| 744 DVLOG(1) << GetClientInfoString("AwaitStatusChangeWithTimeout succeeded"); | 750 DVLOG(1) << GetClientInfoString("AwaitStatusChangeWithTimeout succeeded"); |
| 745 return true; | 751 return true; |
| 746 } else { | 752 } else { |
| 747 DVLOG(0) << GetClientInfoString("AwaitStatusChangeWithTimeout timed out"); | 753 DVLOG(0) << GetClientInfoString("AwaitStatusChangeWithTimeout timed out"); |
| 748 return false; | 754 return false; |
| 749 } | 755 } |
| 750 } | 756 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 const std::string& message) { | 990 const std::string& message) { |
| 985 std::stringstream os; | 991 std::stringstream os; |
| 986 os << profile_debug_name_ << ": " << message << ": "; | 992 os << profile_debug_name_ << ": " << message << ": "; |
| 987 if (service()) { | 993 if (service()) { |
| 988 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 994 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 989 const ProfileSyncService::Status& status = GetStatus(); | 995 const ProfileSyncService::Status& status = GetStatus(); |
| 990 // Capture select info from the sync session snapshot and syncer status. | 996 // Capture select info from the sync session snapshot and syncer status. |
| 991 os << "has_more_to_sync: " | 997 os << "has_more_to_sync: " |
| 992 << snap.has_more_to_sync() | 998 << snap.has_more_to_sync() |
| 993 << ", has_unsynced_items: " | 999 << ", has_unsynced_items: " |
| 994 << service()->HasUnsyncedItems() | 1000 << (service()->sync_initialized() ? service()->HasUnsyncedItems() : 0) |
| 995 << ", unsynced_count: " | 1001 << ", unsynced_count: " |
| 996 << snap.unsynced_count() | 1002 << snap.unsynced_count() |
| 997 << ", encryption conflicts: " | 1003 << ", encryption conflicts: " |
| 998 << snap.num_encryption_conflicts() | 1004 << snap.num_encryption_conflicts() |
| 999 << ", hierarchy conflicts: " | 1005 << ", hierarchy conflicts: " |
| 1000 << snap.num_hierarchy_conflicts() | 1006 << snap.num_hierarchy_conflicts() |
| 1001 << ", simple conflicts: " | 1007 << ", simple conflicts: " |
| 1002 << snap.num_simple_conflicts() | 1008 << snap.num_simple_conflicts() |
| 1003 << ", server conflicts: " | 1009 << ", server conflicts: " |
| 1004 << snap.num_server_conflicts() | 1010 << snap.num_server_conflicts() |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 | 1105 |
| 1100 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1106 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 1101 DictionaryValue value; | 1107 DictionaryValue value; |
| 1102 sync_ui_util::ConstructAboutInformation(service_, &value); | 1108 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 1103 std::string service_status; | 1109 std::string service_status; |
| 1104 base::JSONWriter::WriteWithOptions(&value, | 1110 base::JSONWriter::WriteWithOptions(&value, |
| 1105 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1111 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 1106 &service_status); | 1112 &service_status); |
| 1107 return service_status; | 1113 return service_status; |
| 1108 } | 1114 } |
| OLD | NEW |