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

Side by Side Diff: chrome/browser/sync/profile_sync_service_harness.cc

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responses to Fred's comments Created 7 years, 6 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
OLDNEW
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>
11 #include <sstream> 11 #include <sstream>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/base64.h" 14 #include "base/base64.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/message_loop.h" 22 #include "base/message_loop.h"
23 #include "base/prefs/pref_service.h" 23 #include "base/prefs/pref_service.h"
24 #include "chrome/browser/invalidation/p2p_invalidation_service.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/signin/signin_manager_base.h" 26 #include "chrome/browser/signin/signin_manager_base.h"
26 #include "chrome/browser/signin/token_service.h" 27 #include "chrome/browser/signin/token_service.h"
27 #include "chrome/browser/signin/token_service_factory.h" 28 #include "chrome/browser/signin/token_service_factory.h"
28 #include "chrome/browser/sync/about_sync_util.h" 29 #include "chrome/browser/sync/about_sync_util.h"
29 #include "chrome/browser/sync/glue/data_type_controller.h" 30 #include "chrome/browser/sync/glue/data_type_controller.h"
30 #include "chrome/browser/sync/profile_sync_service_factory.h" 31 #include "chrome/browser/sync/profile_sync_service_factory.h"
31 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
34 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
35 #include "google_apis/gaia/gaia_constants.h" 36 #include "google_apis/gaia/gaia_constants.h"
36 #include "sync/internal_api/public/base/progress_marker_map.h" 37 #include "sync/internal_api/public/base/progress_marker_map.h"
37 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 38 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
38 #include "sync/internal_api/public/util/sync_string_conversions.h" 39 #include "sync/internal_api/public/util/sync_string_conversions.h"
39 40
40 using syncer::sessions::SyncSessionSnapshot; 41 using syncer::sessions::SyncSessionSnapshot;
42 using invalidation::P2PInvalidationService;
41 43
42 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. 44 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed.
43 // The amount of time for which we wait for a live sync operation to complete. 45 // The amount of time for which we wait for a live sync operation to complete.
44 static const int kLiveSyncOperationTimeoutMs = 45000; 46 static const int kLiveSyncOperationTimeoutMs = 45000;
45 47
46 // The amount of time we wait for test cases that verify exponential backoff. 48 // The amount of time we wait for test cases that verify exponential backoff.
47 static const int kExponentialBackoffVerificationTimeoutMs = 60000; 49 static const int kExponentialBackoffVerificationTimeoutMs = 60000;
48 50
49 // Simple class to implement a timeout using PostDelayedTask. If it is not 51 // Simple class to implement a timeout using PostDelayedTask. If it is not
50 // aborted before picked up by a message queue, then it asserts with the message 52 // aborted before picked up by a message queue, then it asserts with the message
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 101 }
100 } 102 }
101 } 103 }
102 104
103 bool StateChangeTimeoutEvent::Abort() { 105 bool StateChangeTimeoutEvent::Abort() {
104 aborted_ = true; 106 aborted_ = true;
105 caller_ = NULL; 107 caller_ = NULL;
106 return !did_timeout_; 108 return !did_timeout_;
107 } 109 }
108 110
111 // static
112 ProfileSyncServiceHarness* ProfileSyncServiceHarness::Create(
113 Profile* profile,
114 const std::string& username,
115 const std::string& password) {
116 return new ProfileSyncServiceHarness(profile, username, password, NULL);
117 }
118
119 // static
120 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateForIntegrationTest(
121 Profile* profile,
122 const std::string& username,
123 const std::string& password,
124 P2PInvalidationService* p2p_invalidation_service) {
125 return new ProfileSyncServiceHarness(profile,
126 username,
127 password,
128 p2p_invalidation_service);
129 }
130
109 ProfileSyncServiceHarness::ProfileSyncServiceHarness( 131 ProfileSyncServiceHarness::ProfileSyncServiceHarness(
110 Profile* profile, 132 Profile* profile,
111 const std::string& username, 133 const std::string& username,
112 const std::string& password) 134 const std::string& password,
135 P2PInvalidationService* p2p_invalidation_service)
113 : waiting_for_encryption_type_(syncer::UNSPECIFIED), 136 : waiting_for_encryption_type_(syncer::UNSPECIFIED),
114 wait_state_(INITIAL_WAIT_STATE), 137 wait_state_(INITIAL_WAIT_STATE),
115 profile_(profile), 138 profile_(profile),
116 service_(NULL), 139 service_(NULL),
140 p2p_invalidation_service_(p2p_invalidation_service),
117 progress_marker_partner_(NULL), 141 progress_marker_partner_(NULL),
118 username_(username), 142 username_(username),
119 password_(password), 143 password_(password),
120 profile_debug_name_(profile->GetDebugName()), 144 profile_debug_name_(profile->GetDebugName()),
121 waiting_for_status_change_(false) { 145 waiting_for_status_change_(false) {
122 if (IsSyncAlreadySetup()) { 146 if (IsSyncAlreadySetup()) {
123 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( 147 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile(
124 profile_); 148 profile_);
125 service_->AddObserver(this); 149 service_->AddObserver(this);
126 ignore_result(TryListeningToMigrationEvents()); 150 ignore_result(TryListeningToMigrationEvents());
127 wait_state_ = FULLY_SYNCED; 151 wait_state_ = FULLY_SYNCED;
128 } 152 }
129 } 153 }
130 154
131 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { 155 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {
132 if (service_->HasObserver(this)) 156 if (service_->HasObserver(this))
133 service_->RemoveObserver(this); 157 service_->RemoveObserver(this);
134 } 158 }
135 159
136 // static
137 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach(
138 Profile* profile) {
139 ProfileSyncServiceFactory* f = ProfileSyncServiceFactory::GetInstance();
140 if (!f->HasProfileSyncService(profile)) {
141 NOTREACHED() << "Profile has never signed into sync.";
142 return NULL;
143 }
144 return new ProfileSyncServiceHarness(profile, std::string(), std::string());
145 }
146
147 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, 160 void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
148 const std::string& password) { 161 const std::string& password) {
149 username_ = username; 162 username_ = username;
150 password_ = password; 163 password_ = password;
151 } 164 }
152 165
153 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { 166 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() {
154 return ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( 167 return ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
155 profile_); 168 profile_);
156 } 169 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // classes using the the UI message loop. Defer to their handling. 486 // classes using the the UI message loop. Defer to their handling.
474 break; 487 break;
475 } 488 }
476 return original_wait_state != wait_state_; 489 return original_wait_state != wait_state_;
477 } 490 }
478 491
479 void ProfileSyncServiceHarness::OnStateChanged() { 492 void ProfileSyncServiceHarness::OnStateChanged() {
480 RunStateChangeMachine(); 493 RunStateChangeMachine();
481 } 494 }
482 495
496 void ProfileSyncServiceHarness::OnSyncCycleCompleted() {
497 // Integration tests still use p2p notifications.
498 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
499 bool is_notifiable_commit =
500 (snap.model_neutral_state().num_successful_commits > 0);
501 if (is_notifiable_commit && p2p_invalidation_service_) {
502 const syncer::ObjectIdInvalidationMap& invalidation_map =
503 ModelTypeInvalidationMapToObjectIdInvalidationMap(
504 snap.source().types);
505 p2p_invalidation_service_->SendInvalidation(invalidation_map);
506 }
507
508 OnStateChanged();
509 }
510
483 void ProfileSyncServiceHarness::OnMigrationStateChange() { 511 void ProfileSyncServiceHarness::OnMigrationStateChange() {
484 // Update migration state. 512 // Update migration state.
485 if (HasPendingBackendMigration()) { 513 if (HasPendingBackendMigration()) {
486 // Merge current pending migration types into 514 // Merge current pending migration types into
487 // |pending_migration_types_|. 515 // |pending_migration_types_|.
488 pending_migration_types_.PutAll( 516 pending_migration_types_.PutAll(
489 service()->GetBackendMigratorForTest()-> 517 service()->GetBackendMigratorForTest()->
490 GetPendingMigrationTypesForTest()); 518 GetPendingMigrationTypesForTest());
491 DVLOG(1) << profile_debug_name_ << ": new pending migration types " 519 DVLOG(1) << profile_debug_name_ << ": new pending migration types "
492 << syncer::ModelTypeSetToString(pending_migration_types_); 520 << syncer::ModelTypeSetToString(pending_migration_types_);
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 1155
1128 std::string ProfileSyncServiceHarness::GetServiceStatus() { 1156 std::string ProfileSyncServiceHarness::GetServiceStatus() {
1129 scoped_ptr<DictionaryValue> value( 1157 scoped_ptr<DictionaryValue> value(
1130 sync_ui_util::ConstructAboutInformation(service_)); 1158 sync_ui_util::ConstructAboutInformation(service_));
1131 std::string service_status; 1159 std::string service_status;
1132 base::JSONWriter::WriteWithOptions(value.get(), 1160 base::JSONWriter::WriteWithOptions(value.get(),
1133 base::JSONWriter::OPTIONS_PRETTY_PRINT, 1161 base::JSONWriter::OPTIONS_PRETTY_PRINT,
1134 &service_status); 1162 &service_status);
1135 return service_status; 1163 return service_status;
1136 } 1164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698