Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3285)

Unified Diff: chrome/browser/sync/profile_sync_service_harness.cc

Issue 4096004: PyAuto hooks for Sync in TestingAutomationProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase; Addressing final review comment. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/profile_sync_service_harness.h ('k') | chrome/browser/sync/syncable/model_type.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/profile_sync_service_harness.cc
diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc
index 3ecafb74fa1c467ea2cc91d2cfd11e56bebbf5e1..475003370104991df4f8e27dfc1b9cad1ec15988 100644
--- a/chrome/browser/sync/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/profile_sync_service_harness.cc
@@ -84,18 +84,44 @@ bool StateChangeTimeoutEvent::Abort() {
}
ProfileSyncServiceHarness::ProfileSyncServiceHarness(
- Profile* p,
+ Profile* profile,
const std::string& username,
const std::string& password,
int id)
- : wait_state_(WAITING_FOR_ON_BACKEND_INITIALIZED),
- profile_(p),
+ : wait_state_(INITIAL_WAIT_STATE),
+ profile_(profile),
service_(NULL),
last_timestamp_(0),
min_timestamp_needed_(kMinTimestampNeededNone),
username_(username),
password_(password),
- id_(id) {}
+ id_(id) {
+ if (IsSyncAlreadySetup()) {
+ service_ = profile_->GetProfileSyncService();
+ service_->AddObserver(this);
+ wait_state_ = FULLY_SYNCED;
+ }
+}
+
+// static
+ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach(
+ Profile* profile) {
+ if (!profile->HasProfileSyncService()) {
+ NOTREACHED() << "Profile has never signed into sync.";
+ return NULL;
+ }
+ return new ProfileSyncServiceHarness(profile, "", "", 0);
+}
+
+void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
+ const std::string& password) {
+ username_ = username;
+ password_ = password;
+}
+
+bool ProfileSyncServiceHarness::IsSyncAlreadySetup() {
+ return profile_->HasProfileSyncService();
+}
bool ProfileSyncServiceHarness::SetupSync() {
syncable::ModelTypeSet synced_datatypes;
@@ -109,7 +135,7 @@ bool ProfileSyncServiceHarness::SetupSync() {
bool ProfileSyncServiceHarness::SetupSync(
const syncable::ModelTypeSet& synced_datatypes) {
// Initialize the sync client's profile sync service object.
- service_ = profile_->GetProfileSyncService("");
+ service_ = profile_->GetProfileSyncService();
if (service_ == NULL) {
LOG(ERROR) << "SetupSync(): service_ is null.";
return false;
@@ -123,7 +149,7 @@ bool ProfileSyncServiceHarness::SetupSync(
service_->signin()->StartSignIn(username_, password_, "", "");
// Wait for the OnBackendInitialized() callback.
- DCHECK_EQ(wait_state_, WAITING_FOR_ON_BACKEND_INITIALIZED);
+ wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED;
if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs,
"Waiting for OnBackendInitialized().")) {
LOG(ERROR) << "OnBackendInitialized() not seen after "
@@ -148,6 +174,9 @@ bool ProfileSyncServiceHarness::SetupSync(
return false;
}
+ // Indicate to the browser that sync setup is complete.
+ service()->SetSyncSetupCompleted();
+
return true;
}
@@ -157,6 +186,10 @@ void ProfileSyncServiceHarness::SignalStateCompleteWithNextState(
SignalStateComplete();
}
+void ProfileSyncServiceHarness::SignalStateComplete() {
+ MessageLoop::current()->Quit();
+}
+
bool ProfileSyncServiceHarness::RunStateChangeMachine() {
WaitState original_wait_state = wait_state_;
switch (wait_state_) {
@@ -353,13 +386,16 @@ bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout(
}
scoped_refptr<StateChangeTimeoutEvent> timeout_signal(
new StateChangeTimeoutEvent(this, reason));
- MessageLoopForUI* loop = MessageLoopForUI::current();
+ MessageLoop* loop = MessageLoop::current();
+ bool did_allow_nestable_tasks = loop->NestableTasksAllowed();
+ loop->SetNestableTasksAllowed(true);
loop->PostDelayedTask(
FROM_HERE,
NewRunnableMethod(timeout_signal.get(),
&StateChangeTimeoutEvent::Callback),
timeout_milliseconds);
- AwaitStatusChange();
+ loop->Run();
+ loop->SetNestableTasksAllowed(did_allow_nestable_tasks);
LogClientInfo("AwaitStatusChangeWithTimeout succeeded");
return timeout_signal->Abort();
}
@@ -370,11 +406,12 @@ ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() {
}
bool ProfileSyncServiceHarness::IsSynced() {
+ if (service() == NULL)
+ return false;
const SyncSessionSnapshot* snap = GetLastSessionSnapshot();
// TODO(rsimha): Remove additional checks of snap->has_more_to_sync and
// snap->unsynced_count once http://crbug.com/48989 is fixed.
- return (service() &&
- snap &&
+ return (snap &&
ServiceIsPushingChanges() &&
GetStatus().notifications_enabled &&
!service()->backend()->HasUnsyncedItems() &&
@@ -478,19 +515,24 @@ int64 ProfileSyncServiceHarness::GetUpdatedTimestamp() {
}
void ProfileSyncServiceHarness::LogClientInfo(std::string message) {
- const SyncSessionSnapshot* snap = GetLastSessionSnapshot();
- if (snap) {
- VLOG(1) << "Client " << id_ << ": " << message
- << ": max_local_timestamp: " << snap->max_local_timestamp
- << ", has_more_to_sync: " << snap->has_more_to_sync
- << ", unsynced_count: " << snap->unsynced_count
- << ", has_unsynced_items: "
- << service()->backend()->HasUnsyncedItems()
- << ", notifications_enabled: "
- << GetStatus().notifications_enabled
- << ", service_is_pushing_changes: " << ServiceIsPushingChanges();
+ if (service()) {
+ const SyncSessionSnapshot* snap = GetLastSessionSnapshot();
+ if (snap) {
+ VLOG(1) << "Client " << id_ << ": " << message
+ << ": max_local_timestamp: " << snap->max_local_timestamp
+ << ", has_more_to_sync: " << snap->has_more_to_sync
+ << ", unsynced_count: " << snap->unsynced_count
+ << ", has_unsynced_items: "
+ << service()->backend()->HasUnsyncedItems()
+ << ", notifications_enabled: "
+ << GetStatus().notifications_enabled
+ << ", service_is_pushing_changes: " << ServiceIsPushingChanges();
+ } else {
+ VLOG(1) << "Client " << id_ << ": " << message
+ << ": Sync session snapshot not available.";
+ }
} else {
VLOG(1) << "Client " << id_ << ": " << message
- << ": Sync session snapshot not available.";
+ << ": Sync service not available.";
}
}
« no previous file with comments | « chrome/browser/sync/profile_sync_service_harness.h ('k') | chrome/browser/sync/syncable/model_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698