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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/test/integration/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/test/integration/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 13 matching lines...) Expand all
24 #include "base/timer/timer.h" 24 #include "base/timer/timer.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/invalidation/p2p_invalidation_service.h" 26 #include "chrome/browser/invalidation/p2p_invalidation_service.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/signin/profile_oauth2_token_service.h" 28 #include "chrome/browser/signin/profile_oauth2_token_service.h"
29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
30 #include "chrome/browser/signin/signin_manager_base.h" 30 #include "chrome/browser/signin/signin_manager_base.h"
31 #include "chrome/browser/sync/about_sync_util.h" 31 #include "chrome/browser/sync/about_sync_util.h"
32 #include "chrome/browser/sync/backend_migrator.h" 32 #include "chrome/browser/sync/backend_migrator.h"
33 #include "chrome/browser/sync/profile_sync_service_factory.h" 33 #include "chrome/browser/sync/profile_sync_service_factory.h"
34 #include "chrome/browser/sync/test/integration/status_change_checker.h" 34 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h"
35 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
36 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h"
35 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
37 #include "components/sync_driver/data_type_controller.h" 39 #include "components/sync_driver/data_type_controller.h"
38 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
39 #include "google_apis/gaia/gaia_constants.h" 41 #include "google_apis/gaia/gaia_constants.h"
40 #include "sync/internal_api/public/base/progress_marker_map.h" 42 #include "sync/internal_api/public/base/progress_marker_map.h"
41 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 43 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
42 #include "sync/internal_api/public/util/sync_string_conversions.h" 44 #include "sync/internal_api/public/util/sync_string_conversions.h"
43 45
44 #if defined(ENABLE_MANAGED_USERS) 46 #if defined(ENABLE_MANAGED_USERS)
45 #include "chrome/browser/managed_mode/managed_user_constants.h" 47 #include "chrome/browser/managed_mode/managed_user_constants.h"
46 #endif 48 #endif
47 49
48 using syncer::sessions::SyncSessionSnapshot; 50 using syncer::sessions::SyncSessionSnapshot;
49 using invalidation::P2PInvalidationService; 51 using invalidation::P2PInvalidationService;
50 52
51 // The amount of time for which we wait for a sync operation to complete. 53 // The amount of time for which we wait for a sync operation to complete.
52 // TODO(sync): This timeout must eventually be made less than the default 45 54 // TODO(sync): This timeout must eventually be made less than the default 45
53 // second timeout for integration tests so that in case a sync operation times 55 // second timeout for integration tests so that in case a sync operation times
54 // out, it is able to log a useful failure message before the test is killed. 56 // out, it is able to log a useful failure message before the test is killed.
55 static const int kSyncOperationTimeoutMs = 45000; 57 static const int kSyncOperationTimeoutMs = 45000;
56 58
57 namespace { 59 namespace {
58 60
59 // Checks if a desired change in the state of the sync engine has taken place by 61 // Checks if a desired change in the state of the sync engine has taken place by
60 // running the callback passed to it. 62 // running the callback passed to it.
61 class CallbackStatusChecker : public StatusChangeChecker { 63 class CallbackStatusChecker : public SingleClientStatusChangeChecker {
62 public: 64 public:
63 CallbackStatusChecker(base::Callback<bool()> callback, 65 CallbackStatusChecker(ProfileSyncService* service,
64 const std::string& source) 66 base::Callback<bool()> callback,
65 : StatusChangeChecker(source), 67 const std::string& debug_message)
66 callback_(callback) { 68 : SingleClientStatusChangeChecker(service),
69 callback_(callback),
70 debug_message_(debug_message) {
67 } 71 }
68 72
69 virtual ~CallbackStatusChecker() { 73 virtual ~CallbackStatusChecker() {
70 } 74 }
71 75
72 virtual bool IsExitConditionSatisfied() OVERRIDE { 76 virtual bool IsExitConditionSatisfied() OVERRIDE {
73 return callback_.Run(); 77 return callback_.Run();
74 } 78 }
75 79
80 virtual std::string GetDebugMessage() const OVERRIDE {
81 return debug_message_;
82 }
83
76 private: 84 private:
77 // Callback that evaluates whether the condition we are waiting on has been 85 // Callback that evaluates whether the condition we are waiting on has been
78 // satisfied. 86 // satisfied.
79 base::Callback<bool()> callback_; 87 base::Callback<bool()> callback_;
80 88
89 const std::string debug_message_;
90
81 DISALLOW_COPY_AND_ASSIGN(CallbackStatusChecker); 91 DISALLOW_COPY_AND_ASSIGN(CallbackStatusChecker);
82 }; 92 };
83 93
84 // Helper function which returns true if the sync backend has been initialized, 94 // Helper function which returns true if the sync backend has been initialized,
85 // or if backend initialization was blocked for some reason. 95 // or if backend initialization was blocked for some reason.
86 bool DoneWaitingForBackendInitialization( 96 bool DoneWaitingForBackendInitialization(
87 const ProfileSyncServiceHarness* harness) { 97 const ProfileSyncServiceHarness* harness) {
88 DCHECK(harness); 98 DCHECK(harness);
89 // Backend is initialized. 99 // Backend is initialized.
90 if (harness->service()->sync_initialized()) 100 if (harness->service()->sync_initialized())
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const std::string& username, 170 const std::string& username,
161 const std::string& password, 171 const std::string& password,
162 P2PInvalidationService* p2p_invalidation_service) 172 P2PInvalidationService* p2p_invalidation_service)
163 : profile_(profile), 173 : profile_(profile),
164 service_(ProfileSyncServiceFactory::GetForProfile(profile)), 174 service_(ProfileSyncServiceFactory::GetForProfile(profile)),
165 p2p_invalidation_service_(p2p_invalidation_service), 175 p2p_invalidation_service_(p2p_invalidation_service),
166 progress_marker_partner_(NULL), 176 progress_marker_partner_(NULL),
167 username_(username), 177 username_(username),
168 password_(password), 178 password_(password),
169 oauth2_refesh_token_number_(0), 179 oauth2_refesh_token_number_(0),
170 profile_debug_name_(profile->GetDebugName()), 180 profile_debug_name_(profile->GetDebugName()) {
171 status_change_checker_(NULL) {
172 } 181 }
173 182
174 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { 183 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { }
175 if (service()->HasObserver(this))
176 service()->RemoveObserver(this);
177 }
178 184
179 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, 185 void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
180 const std::string& password) { 186 const std::string& password) {
181 username_ = username; 187 username_ = username;
182 password_ = password; 188 password_ = password;
183 } 189 }
184 190
185 bool ProfileSyncServiceHarness::SetupSync() { 191 bool ProfileSyncServiceHarness::SetupSync() {
186 bool result = SetupSync(syncer::ModelTypeSet::All()); 192 bool result = SetupSync(syncer::ModelTypeSet::All());
187 if (result == false) { 193 if (result == false) {
188 std::string status = GetServiceStatus(); 194 std::string status = GetServiceStatus();
189 LOG(ERROR) << profile_debug_name_ 195 LOG(ERROR) << profile_debug_name_
190 << ": SetupSync failed. Syncer status:\n" << status; 196 << ": SetupSync failed. Syncer status:\n" << status;
191 } else { 197 } else {
192 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; 198 DVLOG(1) << profile_debug_name_ << ": SetupSync successful.";
193 } 199 }
194 return result; 200 return result;
195 } 201 }
196 202
197 bool ProfileSyncServiceHarness::SetupSync( 203 bool ProfileSyncServiceHarness::SetupSync(
198 syncer::ModelTypeSet synced_datatypes) { 204 syncer::ModelTypeSet synced_datatypes) {
199 // Initialize the sync client's profile sync service object. 205 // Initialize the sync client's profile sync service object.
200 if (service() == NULL) { 206 if (service() == NULL) {
201 LOG(ERROR) << "SetupSync(): service() is null."; 207 LOG(ERROR) << "SetupSync(): service() is null.";
202 return false; 208 return false;
203 } 209 }
204 210
205 // Subscribe sync client to notifications from the profile sync service. 211 // Start listening for and emitting notifications of commits.
206 if (!service()->HasObserver(this)) 212 p2p_invalidation_forwarder_.reset(
207 service()->AddObserver(this); 213 new P2PInvalidationForwarder(service(), p2p_invalidation_service_));
208 214
209 // Tell the sync service that setup is in progress so we don't start syncing 215 // Tell the sync service that setup is in progress so we don't start syncing
210 // until we've finished configuration. 216 // until we've finished configuration.
211 service()->SetSetupInProgress(true); 217 service()->SetSetupInProgress(true);
212 218
213 // Authenticate sync client using GAIA credentials. 219 // Authenticate sync client using GAIA credentials.
214 service()->signin()->SetAuthenticatedUsername(username_); 220 service()->signin()->SetAuthenticatedUsername(username_);
215 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 221 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
216 username_); 222 username_);
217 GoogleServiceSigninSuccessDetails details(username_, password_); 223 GoogleServiceSigninSuccessDetails details(username_, password_);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return false; 300 return false;
295 } 301 }
296 302
297 return true; 303 return true;
298 } 304 }
299 305
300 void ProfileSyncServiceHarness::QuitMessageLoop() { 306 void ProfileSyncServiceHarness::QuitMessageLoop() {
301 base::MessageLoop::current()->QuitWhenIdle(); 307 base::MessageLoop::current()->QuitWhenIdle();
302 } 308 }
303 309
304 void ProfileSyncServiceHarness::OnStateChanged() {
305 if (!status_change_checker_)
306 return;
307
308 DVLOG(1) << GetClientInfoString(status_change_checker_->source());
309 if (status_change_checker_->IsExitConditionSatisfied())
310 QuitMessageLoop();
311 }
312
313 void ProfileSyncServiceHarness::OnSyncCycleCompleted() {
314 // Integration tests still use p2p notifications.
315 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
316 bool is_notifiable_commit =
317 (snap.model_neutral_state().num_successful_commits > 0);
318 if (is_notifiable_commit && p2p_invalidation_service_) {
319 syncer::ModelTypeSet model_types =
320 snap.model_neutral_state().commit_request_types;
321 syncer::ObjectIdSet ids = ModelTypeSetToObjectIdSet(model_types);
322 p2p_invalidation_service_->SendInvalidation(ids);
323 }
324 OnStateChanged();
325 }
326
327 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { 310 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() {
328 DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); 311 DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired");
329 CallbackStatusChecker passphrase_required_checker( 312 CallbackStatusChecker passphrase_required_checker(
313 service(),
330 base::Bind(&::IsPassphraseRequired, base::Unretained(this)), 314 base::Bind(&::IsPassphraseRequired, base::Unretained(this)),
331 "IsPassphraseRequired"); 315 "IsPassphraseRequired");
332 return AwaitStatusChange(&passphrase_required_checker, 316 return AwaitStatusChange(&passphrase_required_checker);
333 "AwaitPassphraseRequired");
334 } 317 }
335 318
336 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { 319 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() {
337 CallbackStatusChecker passphrase_accepted_checker( 320 CallbackStatusChecker passphrase_accepted_checker(
321 service(),
338 base::Bind(&::IsPassphraseAccepted, base::Unretained(this)), 322 base::Bind(&::IsPassphraseAccepted, base::Unretained(this)),
339 "IsPassphraseAccepted"); 323 "IsPassphraseAccepted");
340 bool return_value = AwaitStatusChange(&passphrase_accepted_checker, 324 bool return_value = AwaitStatusChange(&passphrase_accepted_checker);
341 "AwaitPassphraseAccepted");
342 if (return_value) 325 if (return_value)
343 FinishSyncSetup(); 326 FinishSyncSetup();
344 return return_value; 327 return return_value;
345 } 328 }
346 329
347 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { 330 bool ProfileSyncServiceHarness::AwaitBackendInitialized() {
348 DVLOG(1) << GetClientInfoString("AwaitBackendInitialized"); 331 DVLOG(1) << GetClientInfoString("AwaitBackendInitialized");
349 CallbackStatusChecker backend_initialized_checker( 332 CallbackStatusChecker backend_initialized_checker(
333 service(),
350 base::Bind(&DoneWaitingForBackendInitialization, 334 base::Bind(&DoneWaitingForBackendInitialization,
351 base::Unretained(this)), 335 base::Unretained(this)),
352 "DoneWaitingForBackendInitialization"); 336 "DoneWaitingForBackendInitialization");
353 AwaitStatusChange(&backend_initialized_checker, "AwaitBackendInitialized"); 337 AwaitStatusChange(&backend_initialized_checker);
354 return service()->sync_initialized(); 338 return service()->sync_initialized();
355 } 339 }
356 340
357 // TODO(sync): As of today, we wait for a client to finish its commit activity 341 // TODO(sync): As of today, we wait for a client to finish its commit activity
358 // by checking if its progress markers are up to date. In future, once we have 342 // by checking if its progress markers are up to date. In future, once we have
359 // an in-process C++ server, this function can be reimplemented without relying 343 // an in-process C++ server, this function can be reimplemented without relying
360 // on progress markers. 344 // on progress markers.
361 bool ProfileSyncServiceHarness::AwaitCommitActivityCompletion() { 345 bool ProfileSyncServiceHarness::AwaitCommitActivityCompletion() {
362 DVLOG(1) << GetClientInfoString("AwaitCommitActivityCompletion"); 346 DVLOG(1) << GetClientInfoString("AwaitCommitActivityCompletion");
363 CallbackStatusChecker latest_progress_markers_checker( 347 CallbackStatusChecker latest_progress_markers_checker(
348 service(),
364 base::Bind(&ProfileSyncServiceHarness::HasLatestProgressMarkers, 349 base::Bind(&ProfileSyncServiceHarness::HasLatestProgressMarkers,
365 base::Unretained(this)), 350 base::Unretained(this)),
366 "HasLatestProgressMarkers"); 351 "HasLatestProgressMarkers");
367 AwaitStatusChange(&latest_progress_markers_checker, 352 AwaitStatusChange(&latest_progress_markers_checker);
368 "AwaitCommitActivityCompletion");
369 return HasLatestProgressMarkers(); 353 return HasLatestProgressMarkers();
370 } 354 }
371 355
372 bool ProfileSyncServiceHarness::AwaitSyncDisabled() { 356 bool ProfileSyncServiceHarness::AwaitSyncDisabled() {
373 DCHECK(service()->HasSyncSetupCompleted()); 357 DCHECK(service()->HasSyncSetupCompleted());
374 DCHECK(!IsSyncDisabled()); 358 DCHECK(!IsSyncDisabled());
375 CallbackStatusChecker sync_disabled_checker( 359 CallbackStatusChecker sync_disabled_checker(
360 service(),
376 base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled, 361 base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled,
377 base::Unretained(this)), 362 base::Unretained(this)),
378 "IsSyncDisabled"); 363 "IsSyncDisabled");
379 return AwaitStatusChange(&sync_disabled_checker, "AwaitSyncDisabled"); 364 return AwaitStatusChange(&sync_disabled_checker);
380 } 365 }
381 366
382 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { 367 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() {
383 CallbackStatusChecker sync_setup_complete_checker( 368 CallbackStatusChecker sync_setup_complete_checker(
369 service(),
384 base::Bind(&DoneWaitingForSyncSetup, base::Unretained(this)), 370 base::Bind(&DoneWaitingForSyncSetup, base::Unretained(this)),
385 "DoneWaitingForSyncSetup"); 371 "DoneWaitingForSyncSetup");
386 return AwaitStatusChange(&sync_setup_complete_checker, 372 return AwaitStatusChange(&sync_setup_complete_checker);
387 "AwaitSyncSetupCompletion");
388 } 373 }
389 374
390 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 375 bool ProfileSyncServiceHarness::AwaitQuiescence(
391 ProfileSyncServiceHarness* partner) { 376 std::vector<ProfileSyncServiceHarness*>& clients) {
392 DVLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); 377 std::vector<ProfileSyncService*> services;
393 if (!AwaitCommitActivityCompletion()) 378
394 return false; 379 for (std::vector<ProfileSyncServiceHarness*>::iterator it = clients.begin();
395 return partner->WaitUntilProgressMarkersMatch(this); 380 it != clients.end(); ++it) {
381 services.push_back((*it)->service());
382 }
383
384 QuiesceStatusChangeChecker quiesce_checker(services);
385 return (*(clients.begin()))->AwaitStatusChange(&quiesce_checker);
396 } 386 }
397 387
398 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( 388 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
399 std::vector<ProfileSyncServiceHarness*>& partners) { 389 std::vector<ProfileSyncServiceHarness*>& partners) {
400 DVLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion"); 390 std::vector<ProfileSyncServiceHarness*> clients;
401 if (!AwaitCommitActivityCompletion()) 391 //clients.push_back(this); // Apparently not necessary.
402 return false; 392 clients.insert(clients.end(), partners.begin(), partners.end());
403 bool return_value = true; 393 return AwaitQuiescence(clients);
404 for (std::vector<ProfileSyncServiceHarness*>::iterator it =
405 partners.begin(); it != partners.end(); ++it) {
406 if ((this != *it) && (!(*it)->IsSyncDisabled())) {
407 return_value = return_value &&
408 (*it)->WaitUntilProgressMarkersMatch(this);
409 }
410 }
411 return return_value;
412 } 394 }
413 395
414 // static
415 bool ProfileSyncServiceHarness::AwaitQuiescence(
416 std::vector<ProfileSyncServiceHarness*>& clients) {
417 DVLOG(1) << "AwaitQuiescence.";
418 bool return_value = true;
419 for (std::vector<ProfileSyncServiceHarness*>::iterator it =
420 clients.begin(); it != clients.end(); ++it) {
421 if (!(*it)->IsSyncDisabled()) {
422 return_value = return_value &&
423 (*it)->AwaitGroupSyncCycleCompletion(clients);
424 }
425 }
426 return return_value;
427 }
428 396
429 bool ProfileSyncServiceHarness::WaitUntilProgressMarkersMatch( 397 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
430 ProfileSyncServiceHarness* partner) { 398 ProfileSyncServiceHarness* partner) {
431 DVLOG(1) << GetClientInfoString("WaitUntilProgressMarkersMatch"); 399 std::vector<ProfileSyncServiceHarness*> harnesses;
432 400 harnesses.push_back(this);
433 // TODO(rsimha): Replace the mechanism of matching up progress markers with 401 harnesses.push_back(partner);
434 // one that doesn't require every client to have the same progress markers. 402 return AwaitQuiescence(harnesses);
435 DCHECK(!progress_marker_partner_);
436 progress_marker_partner_ = partner;
437 bool return_value = false;
438 if (MatchesPartnerClient()) {
439 // Progress markers already match; don't wait.
440 return_value = true;
441 } else {
442 partner->service()->AddObserver(this);
443 CallbackStatusChecker matches_other_client_checker(
444 base::Bind(&ProfileSyncServiceHarness::MatchesPartnerClient,
445 base::Unretained(this)),
446 "MatchesPartnerClient");
447 return_value = AwaitStatusChange(&matches_other_client_checker,
448 "WaitUntilProgressMarkersMatch");
449 partner->service()->RemoveObserver(this);
450 }
451 progress_marker_partner_ = NULL;
452 return return_value;
453 } 403 }
454 404
455 bool ProfileSyncServiceHarness::AwaitStatusChange( 405 bool ProfileSyncServiceHarness::AwaitStatusChange(
456 StatusChangeChecker* checker, const std::string& source) { 406 StatusChangeChecker* checker) {
457 DVLOG(1) << GetClientInfoString("AwaitStatusChange"); 407 return StatusChangeChecker::Run(checker);
458
459 if (IsSyncDisabled()) {
460 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << ".";
461 return false;
462 }
463
464 DCHECK(checker);
465 if (checker->IsExitConditionSatisfied()) {
466 DVLOG(1) << GetClientInfoString("AwaitStatusChange exiting early because "
467 "condition is already satisfied");
468 return true;
469 }
470
471 DCHECK(status_change_checker_ == NULL);
472 status_change_checker_ = checker;
473
474 base::OneShotTimer<ProfileSyncServiceHarness> timer;
475 timer.Start(FROM_HERE,
476 base::TimeDelta::FromMilliseconds(kSyncOperationTimeoutMs),
477 base::Bind(&ProfileSyncServiceHarness::QuitMessageLoop,
478 base::Unretained(this)));
479 {
480 base::MessageLoop* loop = base::MessageLoop::current();
481 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
482 loop->Run();
483 }
484
485 status_change_checker_ = NULL;
486
487 if (timer.IsRunning()) {
488 DVLOG(1) << GetClientInfoString("AwaitStatusChange succeeded");
489 return true;
490 } else {
491 LOG(ERROR) << GetClientInfoString(base::StringPrintf(
492 "AwaitStatusChange called from %s timed out", source.c_str()));
493 CHECK(false) << "Ending test because of timeout.";
494 return false;
495 }
496 } 408 }
497 409
498 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { 410 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() {
499 return base::StringPrintf("oauth2_refresh_token_%d", 411 return base::StringPrintf("oauth2_refresh_token_%d",
500 ++oauth2_refesh_token_number_); 412 ++oauth2_refesh_token_number_);
501 } 413 }
502 414
503 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() const { 415 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() const {
504 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; 416 DCHECK(service() != NULL) << "GetStatus(): service() is NULL.";
505 ProfileSyncService::Status result; 417 ProfileSyncService::Status result;
(...skipping 25 matching lines...) Expand all
531 443
532 void ProfileSyncServiceHarness::FinishSyncSetup() { 444 void ProfileSyncServiceHarness::FinishSyncSetup() {
533 service()->SetSetupInProgress(false); 445 service()->SetSetupInProgress(false);
534 service()->SetSyncSetupCompleted(); 446 service()->SetSyncSetupCompleted();
535 } 447 }
536 448
537 bool ProfileSyncServiceHarness::AutoStartEnabled() { 449 bool ProfileSyncServiceHarness::AutoStartEnabled() {
538 return service()->auto_start_enabled(); 450 return service()->auto_start_enabled();
539 } 451 }
540 452
541 bool ProfileSyncServiceHarness::MatchesPartnerClient() const {
542 DCHECK(progress_marker_partner_);
543
544 // Only look for a match if we have at least one enabled datatype in
545 // common with the partner client.
546 const syncer::ModelTypeSet common_types =
547 Intersection(service()->GetActiveDataTypes(),
548 progress_marker_partner_->service()->GetActiveDataTypes());
549
550 DVLOG(2) << profile_debug_name_ << ", "
551 << progress_marker_partner_->profile_debug_name_
552 << ": common types are "
553 << syncer::ModelTypeSetToString(common_types);
554
555 for (syncer::ModelTypeSet::Iterator i = common_types.First();
556 i.Good(); i.Inc()) {
557 const std::string marker = GetSerializedProgressMarker(i.Get());
558 const std::string partner_marker =
559 progress_marker_partner_->GetSerializedProgressMarker(i.Get());
560 if (marker != partner_marker) {
561 if (VLOG_IS_ON(2)) {
562 std::string marker_base64, partner_marker_base64;
563 base::Base64Encode(marker, &marker_base64);
564 base::Base64Encode(partner_marker, &partner_marker_base64);
565 DVLOG(2) << syncer::ModelTypeToString(i.Get()) << ": "
566 << profile_debug_name_ << " progress marker = "
567 << marker_base64 << ", "
568 << progress_marker_partner_->profile_debug_name_
569 << " partner progress marker = "
570 << partner_marker_base64;
571 }
572 return false;
573 }
574 }
575 return true;
576 }
577
578 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { 453 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const {
579 DCHECK(service() != NULL) << "Sync service has not yet been set up."; 454 DCHECK(service() != NULL) << "Sync service has not yet been set up.";
580 if (service()->sync_initialized()) { 455 if (service()->sync_initialized()) {
581 return service()->GetLastSessionSnapshot(); 456 return service()->GetLastSessionSnapshot();
582 } 457 }
583 return SyncSessionSnapshot(); 458 return SyncSessionSnapshot();
584 } 459 }
585 460
586 bool ProfileSyncServiceHarness::EnableSyncForDatatype( 461 bool ProfileSyncServiceHarness::EnableSyncForDatatype(
587 syncer::ModelType datatype) { 462 syncer::ModelType datatype) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 return false; 556 return false;
682 } 557 }
683 558
684 service()->DisableForUser(); 559 service()->DisableForUser();
685 560
686 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " 561 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all "
687 << "datatypes on " << profile_debug_name_; 562 << "datatypes on " << profile_debug_name_;
688 return true; 563 return true;
689 } 564 }
690 565
691 std::string ProfileSyncServiceHarness::GetSerializedProgressMarker(
692 syncer::ModelType model_type) const {
693 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
694 const syncer::ProgressMarkerMap& markers_map =
695 snap.download_progress_markers();
696
697 syncer::ProgressMarkerMap::const_iterator it =
698 markers_map.find(model_type);
699 return (it != markers_map.end()) ? it->second : std::string();
700 }
701
702 // TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields 566 // TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields
703 // and log shorter, more meaningful messages. 567 // and log shorter, more meaningful messages.
704 std::string ProfileSyncServiceHarness::GetClientInfoString( 568 std::string ProfileSyncServiceHarness::GetClientInfoString(
705 const std::string& message) const { 569 const std::string& message) const {
706 std::stringstream os; 570 std::stringstream os;
707 os << profile_debug_name_ << ": " << message << ": "; 571 os << profile_debug_name_ << ": " << message << ": ";
708 if (service()) { 572 if (service()) {
709 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); 573 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
710 const ProfileSyncService::Status& status = GetStatus(); 574 const ProfileSyncService::Status& status = GetStatus();
711 // Capture select info from the sync session snapshot and syncer status. 575 // Capture select info from the sync session snapshot and syncer status.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 return WaitForEncryption(); 616 return WaitForEncryption();
753 } 617 }
754 618
755 bool ProfileSyncServiceHarness::WaitForEncryption() { 619 bool ProfileSyncServiceHarness::WaitForEncryption() {
756 if (IsEncryptionComplete()) { 620 if (IsEncryptionComplete()) {
757 // Encryption is already complete; do not wait. 621 // Encryption is already complete; do not wait.
758 return true; 622 return true;
759 } 623 }
760 624
761 CallbackStatusChecker encryption_complete_checker( 625 CallbackStatusChecker encryption_complete_checker(
626 service(),
762 base::Bind(&ProfileSyncServiceHarness::IsEncryptionComplete, 627 base::Bind(&ProfileSyncServiceHarness::IsEncryptionComplete,
763 base::Unretained(this)), 628 base::Unretained(this)),
764 "IsEncryptionComplete"); 629 "IsEncryptionComplete");
765 return AwaitStatusChange(&encryption_complete_checker, "WaitForEncryption"); 630 return AwaitStatusChange(&encryption_complete_checker);
766 } 631 }
767 632
768 bool ProfileSyncServiceHarness::IsEncryptionComplete() const { 633 bool ProfileSyncServiceHarness::IsEncryptionComplete() const {
769 bool is_encryption_complete = service()->EncryptEverythingEnabled() && 634 bool is_encryption_complete = service()->EncryptEverythingEnabled() &&
770 !service()->encryption_pending(); 635 !service()->encryption_pending();
771 DVLOG(2) << "Encryption is " 636 DVLOG(2) << "Encryption is "
772 << (is_encryption_complete ? "" : "not ") 637 << (is_encryption_complete ? "" : "not ")
773 << "complete; Encrypted types = " 638 << "complete; Encrypted types = "
774 << syncer::ModelTypeSetToString(service()->GetEncryptedDataTypes()); 639 << syncer::ModelTypeSetToString(service()->GetEncryptedDataTypes());
775 return is_encryption_complete; 640 return is_encryption_complete;
776 } 641 }
777 642
778 bool ProfileSyncServiceHarness::IsTypeRunning(syncer::ModelType type) { 643 bool ProfileSyncServiceHarness::IsTypeRunning(syncer::ModelType type) {
779 browser_sync::DataTypeController::StateMap state_map; 644 browser_sync::DataTypeController::StateMap state_map;
780 service()->GetDataTypeControllerStates(&state_map); 645 service()->GetDataTypeControllerStates(&state_map);
781 return (state_map.count(type) != 0 && 646 return (state_map.count(type) != 0 &&
782 state_map[type] == browser_sync::DataTypeController::RUNNING); 647 state_map[type] == browser_sync::DataTypeController::RUNNING);
783 } 648 }
784 649
785 bool ProfileSyncServiceHarness::IsTypePreferred(syncer::ModelType type) { 650 bool ProfileSyncServiceHarness::IsTypePreferred(syncer::ModelType type) {
786 return service()->GetPreferredDataTypes().Has(type); 651 return service()->GetPreferredDataTypes().Has(type);
787 } 652 }
788 653
789 size_t ProfileSyncServiceHarness::GetNumEntries() const {
790 return GetLastSessionSnapshot().num_entries();
791 }
792
793 size_t ProfileSyncServiceHarness::GetNumDatatypes() const {
794 browser_sync::DataTypeController::StateMap state_map;
795 service()->GetDataTypeControllerStates(&state_map);
796 return state_map.size();
797 }
798
799 std::string ProfileSyncServiceHarness::GetServiceStatus() { 654 std::string ProfileSyncServiceHarness::GetServiceStatus() {
800 scoped_ptr<base::DictionaryValue> value( 655 scoped_ptr<base::DictionaryValue> value(
801 sync_ui_util::ConstructAboutInformation(service())); 656 sync_ui_util::ConstructAboutInformation(service()));
802 std::string service_status; 657 std::string service_status;
803 base::JSONWriter::WriteWithOptions(value.get(), 658 base::JSONWriter::WriteWithOptions(value.get(),
804 base::JSONWriter::OPTIONS_PRETTY_PRINT, 659 base::JSONWriter::OPTIONS_PRETTY_PRINT,
805 &service_status); 660 &service_status);
806 return service_status; 661 return service_status;
807 } 662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698