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

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

Issue 2716413003: Initial clear server data impl (Closed)
Patch Set: Responding to Pavel's comments. Created 3 years, 9 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 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 <sstream> 10 #include <sstream>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 std::string GetDebugMessage() const override { return "Engine Initialize"; } 70 std::string GetDebugMessage() const override { return "Engine Initialize"; }
71 }; 71 };
72 72
73 class SyncSetupChecker : public SingleClientStatusChangeChecker { 73 class SyncSetupChecker : public SingleClientStatusChangeChecker {
74 public: 74 public:
75 explicit SyncSetupChecker(ProfileSyncService* service) 75 explicit SyncSetupChecker(ProfileSyncService* service)
76 : SingleClientStatusChangeChecker(service) {} 76 : SingleClientStatusChangeChecker(service) {}
77 77
78 bool IsExitConditionSatisfied() override { 78 bool IsExitConditionSatisfied() override {
79 if (!service()->IsSyncActive()) 79 LOG(WARNING) << "ISEXIT";
pavely 2017/03/10 06:14:41 Cleanup.
wylieb 2017/03/10 20:44:01 Done.
80 if (!service()->IsSyncActive()) {
81 LOG(WARNING) << "ISEXIT";
80 return false; 82 return false;
81 if (service()->ConfigurationDone()) 83 }
84 if (service()->ConfigurationDone()) {
85 LOG(WARNING) << "ISEXIT";
82 return true; 86 return true;
87 }
83 // Sync is blocked because a custom passphrase is required. 88 // Sync is blocked because a custom passphrase is required.
84 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) 89 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) {
90 LOG(WARNING) << "ISEXIT";
85 return true; 91 return true;
92 }
86 // Sync is blocked by an auth error. 93 // Sync is blocked by an auth error.
87 if (HasAuthError(service())) 94 if (HasAuthError(service())) {
95 LOG(WARNING) << "ISEXIT";
88 return true; 96 return true;
97 }
98 LOG(WARNING) << "ISEXIT";
89 // Still waiting on sync setup. 99 // Still waiting on sync setup.
90 return false; 100 return false;
91 } 101 }
92 102
93 std::string GetDebugMessage() const override { return "Sync Setup"; } 103 std::string GetDebugMessage() const override { return "Sync Setup"; }
94 }; 104 };
95 105
96 } // namespace 106 } // namespace
97 107
98 // static 108 // static
(...skipping 24 matching lines...) Expand all
123 133
124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } 134 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { }
125 135
126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, 136 void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
127 const std::string& password) { 137 const std::string& password) {
128 username_ = username; 138 username_ = username;
129 password_ = password; 139 password_ = password;
130 } 140 }
131 141
132 bool ProfileSyncServiceHarness::SetupSync() { 142 bool ProfileSyncServiceHarness::SetupSync() {
133 bool result = SetupSync(syncer::UserSelectableTypes()); 143 bool result = SetupSync(syncer::UserSelectableTypes(), false);
pavely 2017/03/10 06:14:42 Yeah... That's the issue with negative parameters.
wylieb 2017/03/10 20:44:01 Done.
134 if (result == false) { 144 if (!result) {
135 std::string status = GetServiceStatus(); 145 LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n"
136 LOG(ERROR) << profile_debug_name_ 146 << GetServiceStatus();
137 << ": SetupSync failed. Syncer status:\n" << status;
138 } else { 147 } else {
139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; 148 DVLOG(1) << profile_debug_name_ << ": SetupSync successful.";
140 } 149 }
141 return result; 150 return result;
142 } 151 }
143 152
144 bool ProfileSyncServiceHarness::SetupSync( 153 bool ProfileSyncServiceHarness::SetupSyncForClear() {
145 syncer::ModelTypeSet synced_datatypes) { 154 bool result = SetupSync(syncer::UserSelectableTypes(), true);
155 if (!result) {
156 LOG(ERROR) << profile_debug_name_
157 << ": SetupSyncForClear failed. Syncer status:\n"
158 << GetServiceStatus();
159 } else {
160 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful.";
161 }
162 return result;
163 }
164
165 bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes,
166 bool skip_passphrase_verification) {
146 DCHECK(!profile_->IsLegacySupervised()) 167 DCHECK(!profile_->IsLegacySupervised())
147 << "SetupSync should not be used for legacy supervised users."; 168 << "SetupSync should not be used for legacy supervised users.";
148 169
149 // Initialize the sync client's profile sync service object. 170 // Initialize the sync client's profile sync service object.
150 if (service() == nullptr) { 171 if (service() == nullptr) {
151 LOG(ERROR) << "SetupSync(): service() is null."; 172 LOG(ERROR) << "SetupSync(): service() is null.";
152 return false; 173 return false;
153 } 174 }
154 175
155 // Tell the sync service that setup is in progress so we don't start syncing 176 // Tell the sync service that setup is in progress so we don't start syncing
(...skipping 16 matching lines...) Expand all
172 service()->GoogleSigninSucceeded(account_id, username_, password_); 193 service()->GoogleSigninSucceeded(account_id, username_, password_);
173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 194 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
174 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); 195 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString());
175 } else { 196 } else {
176 LOG(ERROR) << "Unsupported profile signin type."; 197 LOG(ERROR) << "Unsupported profile signin type.";
177 } 198 }
178 199
179 // Now that auth is completed, request that sync actually start. 200 // Now that auth is completed, request that sync actually start.
180 service()->RequestStart(); 201 service()->RequestStart();
181 202
182 if (!AwaitEngineInitialization()) { 203 if (!AwaitEngineInitialization(!skip_passphrase_verification)) {
pavely 2017/03/10 06:14:41 I think "!skip_..." should be "skip_..."
wylieb 2017/03/10 20:44:01 Done.
183 return false; 204 return false;
184 } 205 }
185
186 // Choose the datatypes to be synced. If all datatypes are to be synced, 206 // Choose the datatypes to be synced. If all datatypes are to be synced,
187 // set sync_everything to true; otherwise, set it to false. 207 // set sync_everything to true; otherwise, set it to false.
188 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); 208 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes());
189 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); 209 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes);
190 210
191 // Notify ProfileSyncService that we are done with configuration. 211 // Notify ProfileSyncService that we are done with configuration.
192 FinishSyncSetup(); 212 FinishSyncSetup();
193 213
194 if ((signin_type_ == SigninType::UI_SIGNIN) && 214 if ((signin_type_ == SigninType::UI_SIGNIN) &&
195 !login_ui_test_utils::DismissSyncConfirmationDialog( 215 !login_ui_test_utils::DismissSyncConfirmationDialog(
196 chrome::FindBrowserWithProfile(profile_), 216 chrome::FindBrowserWithProfile(profile_),
197 base::TimeDelta::FromSeconds(30))) { 217 base::TimeDelta::FromSeconds(30))) {
198 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; 218 LOG(ERROR) << "Failed to dismiss sync confirmation dialog.";
199 return false; 219 return false;
200 } 220 }
201 221
202 // Set an implicit passphrase for encryption if an explicit one hasn't already 222 // Set an implicit passphrase for encryption if an explicit one hasn't already
203 // been set. If an explicit passphrase has been set, immediately return false, 223 // been set. If an explicit passphrase has been set, immediately return false,
204 // since a decryption passphrase is required. 224 // since a decryption passphrase is required.
205 if (!service()->IsUsingSecondaryPassphrase()) { 225 if (!skip_passphrase_verification &&
pavely 2017/03/10 06:14:41 Just wrap this if/else in an outer if(!skip_....).
wylieb 2017/03/10 20:44:01 I actually just passed this block entirely!
226 !service()->IsUsingSecondaryPassphrase()) {
206 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); 227 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
207 } else { 228 } else if (!skip_passphrase_verification) {
208 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 229 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
209 " until SetDecryptionPassphrase is called."; 230 " until SetDecryptionPassphrase is called.";
210 return false; 231 return false;
211 } 232 }
212 233
213 // Wait for initial sync cycle to be completed. 234 // Wait for initial sync cycle to be completed.
214 if (!AwaitSyncSetupCompletion()) { 235 if (!AwaitSyncSetupCompletion()) {
215 LOG(ERROR) << "Initial sync cycle timed out.";
216 return false; 236 return false;
217 } 237 }
218 238
219 return true; 239 return true;
220 } 240 }
221 241
242 bool ProfileSyncServiceHarness::RestartSyncService() {
243 DVLOG(1) << "Requesting stop for service.";
244 service()->RequestStop(ProfileSyncService::CLEAR_DATA);
245
246 std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker =
247 service()->GetSetupInProgressHandle();
248 DVLOG(1) << "Requesting start for service";
249 service()->RequestStart();
250
251 if (!AwaitEngineInitialization()) {
252 LOG(ERROR) << "AwaitEngineInitialization failed.";
253 return false;
254 }
255 DVLOG(1) << "Engine Initialized successfully.";
256
257 // This passphrase should be implicit because ClearServerData should be called
258 // prior.
259 if (!service()->IsUsingSecondaryPassphrase()) {
260 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
261 } else {
262 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
263 " until SetDecryptionPassphrase is called.";
264 return false;
265 }
266 DVLOG(1) << "Passphrase decryption success.";
267
268 blocker.reset();
269 service()->SetFirstSetupComplete();
270
271 return true;
272 }
273
222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 274 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
223 ProfileSyncServiceHarness* partner) { 275 ProfileSyncServiceHarness* partner) {
224 std::vector<ProfileSyncServiceHarness*> harnesses; 276 std::vector<ProfileSyncServiceHarness*> harnesses;
225 harnesses.push_back(this); 277 harnesses.push_back(this);
226 harnesses.push_back(partner); 278 harnesses.push_back(partner);
227 return AwaitQuiescence(harnesses); 279 return AwaitQuiescence(harnesses);
228 } 280 }
229 281
230 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( 282 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
231 const std::vector<ProfileSyncServiceHarness*>& partners) { 283 const std::vector<ProfileSyncServiceHarness*>& partners) {
232 return AwaitQuiescence(partners); 284 return AwaitQuiescence(partners);
233 } 285 }
234 286
235 // static 287 // static
236 bool ProfileSyncServiceHarness::AwaitQuiescence( 288 bool ProfileSyncServiceHarness::AwaitQuiescence(
237 const std::vector<ProfileSyncServiceHarness*>& clients) { 289 const std::vector<ProfileSyncServiceHarness*>& clients) {
238 std::vector<ProfileSyncService*> services; 290 std::vector<ProfileSyncService*> services;
239 if (clients.empty()) { 291 if (clients.empty()) {
240 return true; 292 return true;
241 } 293 }
242 294
243 for (const ProfileSyncServiceHarness* harness : clients) { 295 for (const ProfileSyncServiceHarness* harness : clients) {
244 services.push_back(harness->service()); 296 services.push_back(harness->service());
245 } 297 }
246 return QuiesceStatusChangeChecker(services).Wait(); 298 return QuiesceStatusChangeChecker(services).Wait();
247 } 299 }
248 300
249 bool ProfileSyncServiceHarness::AwaitEngineInitialization() { 301 bool ProfileSyncServiceHarness::AwaitEngineInitialization(
302 bool skip_passphrase_verification) {
250 if (!EngineInitializeChecker(service()).Wait()) { 303 if (!EngineInitializeChecker(service()).Wait()) {
251 LOG(ERROR) << "EngineInitializeChecker timed out."; 304 LOG(ERROR) << "EngineInitializeChecker timed out.";
252 return false; 305 return false;
253 } 306 }
254 307
255 if (!service()->IsEngineInitialized()) { 308 if (!service()->IsEngineInitialized()) {
256 LOG(ERROR) << "Service engine not initialized."; 309 LOG(ERROR) << "Service engine not initialized.";
257 return false; 310 return false;
258 } 311 }
259 312
260 // Make sure that initial sync wasn't blocked by a missing passphrase. 313 // Make sure that initial sync wasn't blocked by a missing passphrase.
261 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { 314 if (!skip_passphrase_verification &&
315 service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) {
262 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 316 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
263 " until SetDecryptionPassphrase is called."; 317 " until SetDecryptionPassphrase is called.";
264 return false; 318 return false;
265 } 319 }
266 320
267 if (HasAuthError(service())) { 321 if (HasAuthError(service())) {
268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; 322 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
269 return false; 323 return false;
270 } 324 }
271 325
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 530
477 std::string ProfileSyncServiceHarness::GetServiceStatus() { 531 std::string ProfileSyncServiceHarness::GetServiceStatus() {
478 std::unique_ptr<base::DictionaryValue> value( 532 std::unique_ptr<base::DictionaryValue> value(
479 syncer::sync_ui_util::ConstructAboutInformation( 533 syncer::sync_ui_util::ConstructAboutInformation(
480 service(), service()->signin(), chrome::GetChannel())); 534 service(), service()->signin(), chrome::GetChannel()));
481 std::string service_status; 535 std::string service_status;
482 base::JSONWriter::WriteWithOptions( 536 base::JSONWriter::WriteWithOptions(
483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); 537 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status);
484 return service_status; 538 return service_status;
485 } 539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698