OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "chrome/browser/defaults.h" | 6 #include "chrome/browser/defaults.h" |
7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
10 #include "chrome/browser/sync/glue/sync_backend_host.h" | 10 #include "chrome/browser/sync/glue/sync_backend_host.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const std::string& username, | 88 const std::string& username, |
89 const std::string& password, | 89 const std::string& password, |
90 int id) | 90 int id) |
91 : wait_state_(INITIAL_WAIT_STATE), | 91 : wait_state_(INITIAL_WAIT_STATE), |
92 profile_(profile), | 92 profile_(profile), |
93 service_(NULL), | 93 service_(NULL), |
94 last_timestamp_(0), | 94 last_timestamp_(0), |
95 min_timestamp_needed_(kMinTimestampNeededNone), | 95 min_timestamp_needed_(kMinTimestampNeededNone), |
96 username_(username), | 96 username_(username), |
97 password_(password), | 97 password_(password), |
98 passphrase_acceptance_counter_(0), | |
99 id_(id) { | 98 id_(id) { |
100 if (IsSyncAlreadySetup()) { | 99 if (IsSyncAlreadySetup()) { |
101 service_ = profile_->GetProfileSyncService(); | 100 service_ = profile_->GetProfileSyncService(); |
102 service_->AddObserver(this); | 101 service_->AddObserver(this); |
103 wait_state_ = FULLY_SYNCED; | 102 wait_state_ = FULLY_SYNCED; |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 // static | 106 // static |
108 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( | 107 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( |
(...skipping 17 matching lines...) Expand all Loading... |
126 | 125 |
127 bool ProfileSyncServiceHarness::SetupSync() { | 126 bool ProfileSyncServiceHarness::SetupSync() { |
128 syncable::ModelTypeSet synced_datatypes; | 127 syncable::ModelTypeSet synced_datatypes; |
129 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 128 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
130 i < syncable::MODEL_TYPE_COUNT; ++i) { | 129 i < syncable::MODEL_TYPE_COUNT; ++i) { |
131 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 130 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
132 } | 131 } |
133 return SetupSync(synced_datatypes); | 132 return SetupSync(synced_datatypes); |
134 } | 133 } |
135 | 134 |
136 void ProfileSyncServiceHarness::StartObservingPassphraseEvents() { | |
137 // Prime the counter to account for the implicit set passphrase due to | |
138 // gaia login. | |
139 passphrase_acceptance_counter_--; | |
140 registrar_.Add(this, NotificationType::SYNC_PASSPHRASE_ACCEPTED, | |
141 Source<browser_sync::SyncBackendHost>(service_->backend())); | |
142 registrar_.Add(this, NotificationType::SYNC_PASSPHRASE_REQUIRED, | |
143 Source<browser_sync::SyncBackendHost>(service_->backend())); | |
144 } | |
145 | |
146 bool ProfileSyncServiceHarness::SetupSync( | 135 bool ProfileSyncServiceHarness::SetupSync( |
147 const syncable::ModelTypeSet& synced_datatypes) { | 136 const syncable::ModelTypeSet& synced_datatypes) { |
148 // Initialize the sync client's profile sync service object. | 137 // Initialize the sync client's profile sync service object. |
149 service_ = profile_->GetProfileSyncService(); | 138 service_ = profile_->GetProfileSyncService(); |
150 if (service_ == NULL) { | 139 if (service_ == NULL) { |
151 LOG(ERROR) << "SetupSync(): service_ is null."; | 140 LOG(ERROR) << "SetupSync(): service_ is null."; |
152 return false; | 141 return false; |
153 } | 142 } |
154 | 143 |
155 // Subscribe sync client to notifications from the profile sync service. | 144 // Subscribe sync client to notifications from the profile sync service. |
(...skipping 22 matching lines...) Expand all Loading... |
178 // Wait for a passphrase to be required. | 167 // Wait for a passphrase to be required. |
179 DCHECK_EQ(wait_state_, WAITING_FOR_PASSPHRASE_REQUIRED); | 168 DCHECK_EQ(wait_state_, WAITING_FOR_PASSPHRASE_REQUIRED); |
180 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 169 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
181 "Waiting for Passphrase required.")) { | 170 "Waiting for Passphrase required.")) { |
182 LOG(ERROR) << "Passphrase required not seen after " | 171 LOG(ERROR) << "Passphrase required not seen after " |
183 << kLiveSyncOperationTimeoutMs / 1000 | 172 << kLiveSyncOperationTimeoutMs / 1000 |
184 << " seconds."; | 173 << " seconds."; |
185 return false; | 174 return false; |
186 } | 175 } |
187 | 176 |
188 DCHECK(service()->observed_passphrase_required()); | |
189 if (id_ == 0) | |
190 DCHECK(!service()->passphrase_required_for_decryption()); | |
191 | |
192 // Wait for initial gaia passphrase to be accepted. | 177 // Wait for initial gaia passphrase to be accepted. |
193 DCHECK_EQ(wait_state_, WAITING_FOR_PASSPHRASE_ACCEPTED); | 178 DCHECK_EQ(wait_state_, WAITING_FOR_PASSPHRASE_ACCEPTED); |
194 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 179 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
195 "Waiting for Passphrase accept.")) { | 180 "Waiting for Passphrase accept.")) { |
196 LOG(ERROR) << "Passphrase accept not seen after " | 181 LOG(ERROR) << "Passphrase accept not seen after " |
197 << kLiveSyncOperationTimeoutMs / 1000 | 182 << kLiveSyncOperationTimeoutMs / 1000 |
198 << " seconds."; | 183 << " seconds."; |
199 return false; | 184 return false; |
200 } | 185 } |
201 | 186 |
(...skipping 22 matching lines...) Expand all Loading... |
224 void ProfileSyncServiceHarness::SignalStateComplete() { | 209 void ProfileSyncServiceHarness::SignalStateComplete() { |
225 MessageLoop::current()->Quit(); | 210 MessageLoop::current()->Quit(); |
226 } | 211 } |
227 | 212 |
228 bool ProfileSyncServiceHarness::RunStateChangeMachine() { | 213 bool ProfileSyncServiceHarness::RunStateChangeMachine() { |
229 WaitState original_wait_state = wait_state_; | 214 WaitState original_wait_state = wait_state_; |
230 switch (wait_state_) { | 215 switch (wait_state_) { |
231 case WAITING_FOR_ON_BACKEND_INITIALIZED: { | 216 case WAITING_FOR_ON_BACKEND_INITIALIZED: { |
232 LogClientInfo("WAITING_FOR_ON_BACKEND_INITIALIZED"); | 217 LogClientInfo("WAITING_FOR_ON_BACKEND_INITIALIZED"); |
233 if (service()->sync_initialized()) { | 218 if (service()->sync_initialized()) { |
234 // The sync backend is initialized. Watch for passphrase events. | 219 // The sync backend is initialized. We now wait for passphrase events. |
235 StartObservingPassphraseEvents(); | |
236 SignalStateCompleteWithNextState(WAITING_FOR_PASSPHRASE_REQUIRED); | 220 SignalStateCompleteWithNextState(WAITING_FOR_PASSPHRASE_REQUIRED); |
237 } | 221 } |
238 break; | 222 break; |
239 } | 223 } |
240 case WAITING_FOR_PASSPHRASE_REQUIRED: { | 224 case WAITING_FOR_PASSPHRASE_REQUIRED: { |
241 LogClientInfo("WAITING_FOR_PASSPHRASE_REQUIRED"); | 225 LogClientInfo("WAITING_FOR_PASSPHRASE_REQUIRED"); |
242 if (service_->observed_passphrase_required()) | 226 if (service()->observed_passphrase_required()) { |
| 227 // Special case when the first client signs in to sync. |
| 228 if (id_ == 0) |
| 229 DCHECK(!service()->passphrase_required_for_decryption()); |
| 230 // The SYNC_PASSPHRASE_REQUIRED notification has been seen. |
243 SignalStateCompleteWithNextState(WAITING_FOR_PASSPHRASE_ACCEPTED); | 231 SignalStateCompleteWithNextState(WAITING_FOR_PASSPHRASE_ACCEPTED); |
| 232 } |
244 break; | 233 break; |
245 } | 234 } |
246 case WAITING_FOR_PASSPHRASE_ACCEPTED: { | 235 case WAITING_FOR_PASSPHRASE_ACCEPTED: { |
247 LogClientInfo("WAITING_FOR_PASSPHRASE_ACCEPTED"); | 236 LogClientInfo("WAITING_FOR_PASSPHRASE_ACCEPTED"); |
248 if (passphrase_acceptance_counter_ >= 0) | 237 if (service()->ShouldPushChanges()) |
| 238 // The SYNC_PASSPHRASE_ACCEPTED notification has been seen. |
249 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 239 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
250 break; | 240 break; |
251 } | 241 } |
252 case WAITING_FOR_INITIAL_SYNC: { | 242 case WAITING_FOR_INITIAL_SYNC: { |
253 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); | 243 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); |
254 if (IsSynced()) { | 244 if (IsSynced()) { |
255 // The first sync cycle is now complete. We can start running tests. | 245 // The first sync cycle is now complete. We can start running tests. |
256 SignalStateCompleteWithNextState(FULLY_SYNCED); | 246 SignalStateCompleteWithNextState(FULLY_SYNCED); |
257 } | 247 } |
258 break; | 248 break; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 void ProfileSyncServiceHarness::OnStateChanged() { | 302 void ProfileSyncServiceHarness::OnStateChanged() { |
313 RunStateChangeMachine(); | 303 RunStateChangeMachine(); |
314 } | 304 } |
315 | 305 |
316 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { | 306 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { |
317 LogClientInfo("AwaitPassphraseAccepted"); | 307 LogClientInfo("AwaitPassphraseAccepted"); |
318 if (wait_state_ == SYNC_DISABLED) { | 308 if (wait_state_ == SYNC_DISABLED) { |
319 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 309 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; |
320 return false; | 310 return false; |
321 } | 311 } |
322 passphrase_acceptance_counter_--; | |
323 if (passphrase_acceptance_counter_ >= 0) | |
324 return true; | |
325 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; | 312 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; |
326 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 313 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
327 "Waiting for passphrase accepted."); | 314 "Waiting for passphrase accepted."); |
328 } | 315 } |
329 | 316 |
330 void ProfileSyncServiceHarness::Observe(NotificationType type, | |
331 const NotificationSource& source, | |
332 const NotificationDetails& details) { | |
333 if (NotificationType::SYNC_PASSPHRASE_ACCEPTED == type.value) { | |
334 passphrase_acceptance_counter_++; | |
335 RunStateChangeMachine(); | |
336 } else if (NotificationType::SYNC_PASSPHRASE_REQUIRED == type.value) { | |
337 RunStateChangeMachine(); | |
338 } | |
339 } | |
340 | |
341 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( | 317 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( |
342 const std::string& reason) { | 318 const std::string& reason) { |
343 LogClientInfo("AwaitSyncCycleCompletion"); | 319 LogClientInfo("AwaitSyncCycleCompletion"); |
344 if (wait_state_ == SYNC_DISABLED) { | 320 if (wait_state_ == SYNC_DISABLED) { |
345 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 321 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; |
346 return false; | 322 return false; |
347 } | 323 } |
348 if (!IsSynced()) { | 324 if (!IsSynced()) { |
349 if (wait_state_ == SERVER_UNREACHABLE) { | 325 if (wait_state_ == SERVER_UNREACHABLE) { |
350 // Client was offline; wait for it to go online, and then wait for sync. | 326 // Client was offline; wait for it to go online, and then wait for sync. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); | 563 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); |
588 } else { | 564 } else { |
589 VLOG(1) << "Client " << id_ << ": " << message | 565 VLOG(1) << "Client " << id_ << ": " << message |
590 << ": Sync session snapshot not available."; | 566 << ": Sync session snapshot not available."; |
591 } | 567 } |
592 } else { | 568 } else { |
593 VLOG(1) << "Client " << id_ << ": " << message | 569 VLOG(1) << "Client " << id_ << ": " << message |
594 << ": Sync service not available."; | 570 << ": Sync service not available."; |
595 } | 571 } |
596 } | 572 } |
OLD | NEW |