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

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

Issue 165393010: Draft: Moving code out of ProfileSyncServiceHarness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months 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
Index: chrome/browser/sync/test/integration/profile_sync_service_harness.cc
diff --git a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
index c311344c52b3fc291a93eccbfe40e5482250ab4b..3b4c073b5cf145ae7c339c934d6c647ecad0c3d7 100644
--- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
@@ -31,7 +31,9 @@
#include "chrome/browser/sync/about_sync_util.h"
#include "chrome/browser/sync/backend_migrator.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
-#include "chrome/browser/sync/test/integration/status_change_checker.h"
+#include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h"
+#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
+#include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/sync_driver/data_type_controller.h"
@@ -58,12 +60,14 @@ namespace {
// Checks if a desired change in the state of the sync engine has taken place by
// running the callback passed to it.
-class CallbackStatusChecker : public StatusChangeChecker {
+class CallbackStatusChecker : public SingleClientStatusChangeChecker {
public:
- CallbackStatusChecker(base::Callback<bool()> callback,
- const std::string& source)
- : StatusChangeChecker(source),
- callback_(callback) {
+ CallbackStatusChecker(ProfileSyncService* service,
+ base::Callback<bool()> callback,
+ const std::string& debug_message)
+ : SingleClientStatusChangeChecker(service),
+ callback_(callback),
+ debug_message_(debug_message) {
}
virtual ~CallbackStatusChecker() {
@@ -73,11 +77,17 @@ class CallbackStatusChecker : public StatusChangeChecker {
return callback_.Run();
}
+ virtual std::string GetDebugMessage() const OVERRIDE {
+ return debug_message_;
+ }
+
private:
// Callback that evaluates whether the condition we are waiting on has been
// satisfied.
base::Callback<bool()> callback_;
+ const std::string debug_message_;
+
DISALLOW_COPY_AND_ASSIGN(CallbackStatusChecker);
};
@@ -167,14 +177,10 @@ ProfileSyncServiceHarness::ProfileSyncServiceHarness(
username_(username),
password_(password),
oauth2_refesh_token_number_(0),
- profile_debug_name_(profile->GetDebugName()),
- status_change_checker_(NULL) {
+ profile_debug_name_(profile->GetDebugName()) {
}
-ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {
- if (service()->HasObserver(this))
- service()->RemoveObserver(this);
-}
+ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { }
void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
const std::string& password) {
@@ -202,9 +208,9 @@ bool ProfileSyncServiceHarness::SetupSync(
return false;
}
- // Subscribe sync client to notifications from the profile sync service.
- if (!service()->HasObserver(this))
- service()->AddObserver(this);
+ // Start listening for and emitting notifications of commits.
+ p2p_invalidation_forwarder_.reset(
+ new P2PInvalidationForwarder(service(), p2p_invalidation_service_));
// Tell the sync service that setup is in progress so we don't start syncing
// until we've finished configuration.
@@ -301,44 +307,21 @@ void ProfileSyncServiceHarness::QuitMessageLoop() {
base::MessageLoop::current()->QuitWhenIdle();
}
-void ProfileSyncServiceHarness::OnStateChanged() {
- if (!status_change_checker_)
- return;
-
- DVLOG(1) << GetClientInfoString(status_change_checker_->source());
- if (status_change_checker_->IsExitConditionSatisfied())
- QuitMessageLoop();
-}
-
-void ProfileSyncServiceHarness::OnSyncCycleCompleted() {
- // Integration tests still use p2p notifications.
- const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
- bool is_notifiable_commit =
- (snap.model_neutral_state().num_successful_commits > 0);
- if (is_notifiable_commit && p2p_invalidation_service_) {
- syncer::ModelTypeSet model_types =
- snap.model_neutral_state().commit_request_types;
- syncer::ObjectIdSet ids = ModelTypeSetToObjectIdSet(model_types);
- p2p_invalidation_service_->SendInvalidation(ids);
- }
- OnStateChanged();
-}
-
bool ProfileSyncServiceHarness::AwaitPassphraseRequired() {
DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired");
CallbackStatusChecker passphrase_required_checker(
+ service(),
base::Bind(&::IsPassphraseRequired, base::Unretained(this)),
"IsPassphraseRequired");
- return AwaitStatusChange(&passphrase_required_checker,
- "AwaitPassphraseRequired");
+ return AwaitStatusChange(&passphrase_required_checker);
}
bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() {
CallbackStatusChecker passphrase_accepted_checker(
+ service(),
base::Bind(&::IsPassphraseAccepted, base::Unretained(this)),
"IsPassphraseAccepted");
- bool return_value = AwaitStatusChange(&passphrase_accepted_checker,
- "AwaitPassphraseAccepted");
+ bool return_value = AwaitStatusChange(&passphrase_accepted_checker);
if (return_value)
FinishSyncSetup();
return return_value;
@@ -347,10 +330,11 @@ bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() {
bool ProfileSyncServiceHarness::AwaitBackendInitialized() {
DVLOG(1) << GetClientInfoString("AwaitBackendInitialized");
CallbackStatusChecker backend_initialized_checker(
+ service(),
base::Bind(&DoneWaitingForBackendInitialization,
base::Unretained(this)),
"DoneWaitingForBackendInitialization");
- AwaitStatusChange(&backend_initialized_checker, "AwaitBackendInitialized");
+ AwaitStatusChange(&backend_initialized_checker);
return service()->sync_initialized();
}
@@ -361,11 +345,11 @@ bool ProfileSyncServiceHarness::AwaitBackendInitialized() {
bool ProfileSyncServiceHarness::AwaitCommitActivityCompletion() {
DVLOG(1) << GetClientInfoString("AwaitCommitActivityCompletion");
CallbackStatusChecker latest_progress_markers_checker(
+ service(),
base::Bind(&ProfileSyncServiceHarness::HasLatestProgressMarkers,
base::Unretained(this)),
"HasLatestProgressMarkers");
- AwaitStatusChange(&latest_progress_markers_checker,
- "AwaitCommitActivityCompletion");
+ AwaitStatusChange(&latest_progress_markers_checker);
return HasLatestProgressMarkers();
}
@@ -373,126 +357,54 @@ bool ProfileSyncServiceHarness::AwaitSyncDisabled() {
DCHECK(service()->HasSyncSetupCompleted());
DCHECK(!IsSyncDisabled());
CallbackStatusChecker sync_disabled_checker(
+ service(),
base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled,
base::Unretained(this)),
"IsSyncDisabled");
- return AwaitStatusChange(&sync_disabled_checker, "AwaitSyncDisabled");
+ return AwaitStatusChange(&sync_disabled_checker);
}
bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() {
CallbackStatusChecker sync_setup_complete_checker(
+ service(),
base::Bind(&DoneWaitingForSyncSetup, base::Unretained(this)),
"DoneWaitingForSyncSetup");
- return AwaitStatusChange(&sync_setup_complete_checker,
- "AwaitSyncSetupCompletion");
+ return AwaitStatusChange(&sync_setup_complete_checker);
}
-bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
- ProfileSyncServiceHarness* partner) {
- DVLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion");
- if (!AwaitCommitActivityCompletion())
- return false;
- return partner->WaitUntilProgressMarkersMatch(this);
+bool ProfileSyncServiceHarness::AwaitQuiescence(
+ std::vector<ProfileSyncServiceHarness*>& clients) {
+ std::vector<ProfileSyncService*> services;
+
+ for (std::vector<ProfileSyncServiceHarness*>::iterator it = clients.begin();
+ it != clients.end(); ++it) {
+ services.push_back((*it)->service());
+ }
+
+ QuiesceStatusChangeChecker quiesce_checker(services);
+ return (*(clients.begin()))->AwaitStatusChange(&quiesce_checker);
}
bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
std::vector<ProfileSyncServiceHarness*>& partners) {
- DVLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion");
- if (!AwaitCommitActivityCompletion())
- return false;
- bool return_value = true;
- for (std::vector<ProfileSyncServiceHarness*>::iterator it =
- partners.begin(); it != partners.end(); ++it) {
- if ((this != *it) && (!(*it)->IsSyncDisabled())) {
- return_value = return_value &&
- (*it)->WaitUntilProgressMarkersMatch(this);
- }
- }
- return return_value;
+ std::vector<ProfileSyncServiceHarness*> clients;
+ //clients.push_back(this); // Apparently not necessary.
+ clients.insert(clients.end(), partners.begin(), partners.end());
+ return AwaitQuiescence(clients);
}
-// static
-bool ProfileSyncServiceHarness::AwaitQuiescence(
- std::vector<ProfileSyncServiceHarness*>& clients) {
- DVLOG(1) << "AwaitQuiescence.";
- bool return_value = true;
- for (std::vector<ProfileSyncServiceHarness*>::iterator it =
- clients.begin(); it != clients.end(); ++it) {
- if (!(*it)->IsSyncDisabled()) {
- return_value = return_value &&
- (*it)->AwaitGroupSyncCycleCompletion(clients);
- }
- }
- return return_value;
-}
-bool ProfileSyncServiceHarness::WaitUntilProgressMarkersMatch(
+bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
ProfileSyncServiceHarness* partner) {
- DVLOG(1) << GetClientInfoString("WaitUntilProgressMarkersMatch");
-
- // TODO(rsimha): Replace the mechanism of matching up progress markers with
- // one that doesn't require every client to have the same progress markers.
- DCHECK(!progress_marker_partner_);
- progress_marker_partner_ = partner;
- bool return_value = false;
- if (MatchesPartnerClient()) {
- // Progress markers already match; don't wait.
- return_value = true;
- } else {
- partner->service()->AddObserver(this);
- CallbackStatusChecker matches_other_client_checker(
- base::Bind(&ProfileSyncServiceHarness::MatchesPartnerClient,
- base::Unretained(this)),
- "MatchesPartnerClient");
- return_value = AwaitStatusChange(&matches_other_client_checker,
- "WaitUntilProgressMarkersMatch");
- partner->service()->RemoveObserver(this);
- }
- progress_marker_partner_ = NULL;
- return return_value;
+ std::vector<ProfileSyncServiceHarness*> harnesses;
+ harnesses.push_back(this);
+ harnesses.push_back(partner);
+ return AwaitQuiescence(harnesses);
}
bool ProfileSyncServiceHarness::AwaitStatusChange(
- StatusChangeChecker* checker, const std::string& source) {
- DVLOG(1) << GetClientInfoString("AwaitStatusChange");
-
- if (IsSyncDisabled()) {
- LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << ".";
- return false;
- }
-
- DCHECK(checker);
- if (checker->IsExitConditionSatisfied()) {
- DVLOG(1) << GetClientInfoString("AwaitStatusChange exiting early because "
- "condition is already satisfied");
- return true;
- }
-
- DCHECK(status_change_checker_ == NULL);
- status_change_checker_ = checker;
-
- base::OneShotTimer<ProfileSyncServiceHarness> timer;
- timer.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kSyncOperationTimeoutMs),
- base::Bind(&ProfileSyncServiceHarness::QuitMessageLoop,
- base::Unretained(this)));
- {
- base::MessageLoop* loop = base::MessageLoop::current();
- base::MessageLoop::ScopedNestableTaskAllower allow(loop);
- loop->Run();
- }
-
- status_change_checker_ = NULL;
-
- if (timer.IsRunning()) {
- DVLOG(1) << GetClientInfoString("AwaitStatusChange succeeded");
- return true;
- } else {
- LOG(ERROR) << GetClientInfoString(base::StringPrintf(
- "AwaitStatusChange called from %s timed out", source.c_str()));
- CHECK(false) << "Ending test because of timeout.";
- return false;
- }
+ StatusChangeChecker* checker) {
+ return StatusChangeChecker::Run(checker);
}
std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() {
@@ -538,43 +450,6 @@ bool ProfileSyncServiceHarness::AutoStartEnabled() {
return service()->auto_start_enabled();
}
-bool ProfileSyncServiceHarness::MatchesPartnerClient() const {
- DCHECK(progress_marker_partner_);
-
- // Only look for a match if we have at least one enabled datatype in
- // common with the partner client.
- const syncer::ModelTypeSet common_types =
- Intersection(service()->GetActiveDataTypes(),
- progress_marker_partner_->service()->GetActiveDataTypes());
-
- DVLOG(2) << profile_debug_name_ << ", "
- << progress_marker_partner_->profile_debug_name_
- << ": common types are "
- << syncer::ModelTypeSetToString(common_types);
-
- for (syncer::ModelTypeSet::Iterator i = common_types.First();
- i.Good(); i.Inc()) {
- const std::string marker = GetSerializedProgressMarker(i.Get());
- const std::string partner_marker =
- progress_marker_partner_->GetSerializedProgressMarker(i.Get());
- if (marker != partner_marker) {
- if (VLOG_IS_ON(2)) {
- std::string marker_base64, partner_marker_base64;
- base::Base64Encode(marker, &marker_base64);
- base::Base64Encode(partner_marker, &partner_marker_base64);
- DVLOG(2) << syncer::ModelTypeToString(i.Get()) << ": "
- << profile_debug_name_ << " progress marker = "
- << marker_base64 << ", "
- << progress_marker_partner_->profile_debug_name_
- << " partner progress marker = "
- << partner_marker_base64;
- }
- return false;
- }
- }
- return true;
-}
-
SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const {
DCHECK(service() != NULL) << "Sync service has not yet been set up.";
if (service()->sync_initialized()) {
@@ -688,17 +563,6 @@ bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() {
return true;
}
-std::string ProfileSyncServiceHarness::GetSerializedProgressMarker(
- syncer::ModelType model_type) const {
- const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
- const syncer::ProgressMarkerMap& markers_map =
- snap.download_progress_markers();
-
- syncer::ProgressMarkerMap::const_iterator it =
- markers_map.find(model_type);
- return (it != markers_map.end()) ? it->second : std::string();
-}
-
// TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields
// and log shorter, more meaningful messages.
std::string ProfileSyncServiceHarness::GetClientInfoString(
@@ -759,10 +623,11 @@ bool ProfileSyncServiceHarness::WaitForEncryption() {
}
CallbackStatusChecker encryption_complete_checker(
+ service(),
base::Bind(&ProfileSyncServiceHarness::IsEncryptionComplete,
base::Unretained(this)),
"IsEncryptionComplete");
- return AwaitStatusChange(&encryption_complete_checker, "WaitForEncryption");
+ return AwaitStatusChange(&encryption_complete_checker);
}
bool ProfileSyncServiceHarness::IsEncryptionComplete() const {
@@ -786,16 +651,6 @@ bool ProfileSyncServiceHarness::IsTypePreferred(syncer::ModelType type) {
return service()->GetPreferredDataTypes().Has(type);
}
-size_t ProfileSyncServiceHarness::GetNumEntries() const {
- return GetLastSessionSnapshot().num_entries();
-}
-
-size_t ProfileSyncServiceHarness::GetNumDatatypes() const {
- browser_sync::DataTypeController::StateMap state_map;
- service()->GetDataTypeControllerStates(&state_map);
- return state_map.size();
-}
-
std::string ProfileSyncServiceHarness::GetServiceStatus() {
scoped_ptr<base::DictionaryValue> value(
sync_ui_util::ConstructAboutInformation(service()));

Powered by Google App Engine
This is Rietveld 408576698