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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 7655055: [Sync] Make BackendMigrator not wait for full sync cycles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac test Created 9 years, 3 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 7 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/tracked.h" 18 #include "base/tracked.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/net/gaia/token_service.h" 20 #include "chrome/browser/net/gaia/token_service.h"
21 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/sync/glue/change_processor.h" 23 #include "chrome/browser/sync/glue/change_processor.h"
24 #include "chrome/browser/sync/glue/http_bridge.h" 24 #include "chrome/browser/sync/glue/http_bridge.h"
25 #include "chrome/browser/sync/internal_api/base_transaction.h" 25 #include "chrome/browser/sync/internal_api/base_transaction.h"
26 #include "chrome/browser/sync/internal_api/read_transaction.h"
26 #include "chrome/browser/sync/internal_api/sync_manager.h" 27 #include "chrome/browser/sync/internal_api/sync_manager.h"
27 #include "chrome/browser/sync/glue/sync_backend_registrar.h" 28 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
28 #include "chrome/browser/sync/notifier/sync_notifier.h" 29 #include "chrome/browser/sync/notifier/sync_notifier.h"
30 #include "chrome/browser/sync/protocol/sync.pb.h"
29 #include "chrome/browser/sync/sessions/session_state.h" 31 #include "chrome/browser/sync/sessions/session_state.h"
30 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. 32 // TODO(tim): Remove this! We should have a syncapi pass-thru instead.
31 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. 33 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer.
32 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/chrome_version_info.h" 35 #include "chrome/common/chrome_version_info.h"
34 #include "chrome/common/net/gaia/gaia_constants.h" 36 #include "chrome/common/net/gaia/gaia_constants.h"
35 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
36 #include "content/browser/browser_thread.h" 38 #include "content/browser/browser_thread.h"
37 #include "content/common/notification_service.h" 39 #include "content/common/notification_service.h"
38 #include "webkit/glue/webkit_glue.h" 40 #include "webkit/glue/webkit_glue.h"
39 41
40 static const int kSaveChangesIntervalSeconds = 10; 42 static const int kSaveChangesIntervalSeconds = 10;
41 static const FilePath::CharType kSyncDataFolderName[] = 43 static const FilePath::CharType kSyncDataFolderName[] =
42 FILE_PATH_LITERAL("Sync Data"); 44 FILE_PATH_LITERAL("Sync Data");
43 45
44 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; 46 typedef TokenService::TokenAvailableDetails TokenAvailableDetails;
45 47
46 typedef GoogleServiceAuthError AuthError; 48 typedef GoogleServiceAuthError AuthError;
47 49
48 namespace browser_sync { 50 namespace browser_sync {
49 51
50 using sessions::SyncSessionSnapshot; 52 using sessions::SyncSessionSnapshot;
51 using sync_api::SyncCredentials; 53 using sync_api::SyncCredentials;
52 54
53 SyncBackendHost::SyncBackendHost(Profile* profile) 55 // Helper macros to log with the syncer thread name; useful when there
54 : core_(new Core(profile, 56 // are multiple syncers involved.
55 ALLOW_THIS_IN_INITIALIZER_LIST(this))), 57
58 #define SLOG(severity) LOG(severity) << name_ << ": "
59
60 #define SVLOG(verbose_level) VLOG(verbose_level) << name_ << ": "
61
62 SyncBackendHost::SyncBackendHost(const std::string& name, Profile* profile)
63 : core_(new Core(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))),
56 initialization_state_(NOT_INITIALIZED), 64 initialization_state_(NOT_INITIALIZED),
57 sync_thread_("Chrome_SyncThread"), 65 sync_thread_("Chrome_SyncThread"),
58 frontend_loop_(MessageLoop::current()), 66 frontend_loop_(MessageLoop::current()),
59 profile_(profile), 67 profile_(profile),
68 name_(name),
60 sync_notifier_factory_(webkit_glue::GetUserAgent(GURL()), 69 sync_notifier_factory_(webkit_glue::GetUserAgent(GURL()),
61 profile_->GetRequestContext(), 70 profile_->GetRequestContext(),
62 *CommandLine::ForCurrentProcess()), 71 *CommandLine::ForCurrentProcess()),
63 frontend_(NULL), 72 frontend_(NULL),
64 sync_data_folder_path_( 73 sync_data_folder_path_(
65 profile_->GetPath().Append(kSyncDataFolderName)), 74 profile_->GetPath().Append(kSyncDataFolderName)),
66 last_auth_error_(AuthError::None()) { 75 last_auth_error_(AuthError::None()) {
67 } 76 }
68 77
69 SyncBackendHost::SyncBackendHost() 78 SyncBackendHost::SyncBackendHost()
70 : initialization_state_(NOT_INITIALIZED), 79 : initialization_state_(NOT_INITIALIZED),
71 sync_thread_("Chrome_SyncThread"), 80 sync_thread_("Chrome_SyncThread"),
72 frontend_loop_(MessageLoop::current()), 81 frontend_loop_(MessageLoop::current()),
73 profile_(NULL), 82 profile_(NULL),
83 name_("Unknown"),
74 sync_notifier_factory_(webkit_glue::GetUserAgent(GURL()), 84 sync_notifier_factory_(webkit_glue::GetUserAgent(GURL()),
75 NULL, 85 NULL,
76 *CommandLine::ForCurrentProcess()), 86 *CommandLine::ForCurrentProcess()),
77 frontend_(NULL), 87 frontend_(NULL),
78 last_auth_error_(AuthError::None()) { 88 last_auth_error_(AuthError::None()) {
79 } 89 }
80 90
81 SyncBackendHost::~SyncBackendHost() { 91 SyncBackendHost::~SyncBackendHost() {
82 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 92 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
83 DCHECK(!registrar_.get()); 93 DCHECK(!registrar_.get());
(...skipping 10 matching lines...) Expand all
94 return; 104 return;
95 105
96 frontend_ = frontend; 106 frontend_ = frontend;
97 DCHECK(frontend); 107 DCHECK(frontend);
98 108
99 syncable::ModelTypeSet initial_types_with_nigori(initial_types); 109 syncable::ModelTypeSet initial_types_with_nigori(initial_types);
100 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) 110 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted))
101 initial_types_with_nigori.insert(syncable::NIGORI); 111 initial_types_with_nigori.insert(syncable::NIGORI);
102 112
103 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori, 113 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori,
114 name_,
104 profile_, 115 profile_,
105 sync_thread_.message_loop())); 116 sync_thread_.message_loop()));
106 117
107 InitCore(Core::DoInitializeOptions( 118 InitCore(Core::DoInitializeOptions(
108 registrar_.get(), 119 registrar_.get(),
109 event_handler, 120 event_handler,
110 sync_service_url, 121 sync_service_url,
111 profile_->GetRequestContext(), 122 profile_->GetRequestContext(),
112 credentials, 123 credentials,
113 delete_sync_data_folder, 124 delete_sync_data_folder,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 177 }
167 178
168 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 179 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
169 sync_thread_.message_loop()->PostTask(FROM_HERE, 180 sync_thread_.message_loop()->PostTask(FROM_HERE,
170 NewRunnableMethod(core_.get(), 181 NewRunnableMethod(core_.get(),
171 &SyncBackendHost::Core::DoUpdateCredentials, 182 &SyncBackendHost::Core::DoUpdateCredentials,
172 credentials)); 183 credentials));
173 } 184 }
174 185
175 void SyncBackendHost::StartSyncingWithServer() { 186 void SyncBackendHost::StartSyncingWithServer() {
176 VLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; 187 SVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
177 sync_thread_.message_loop()->PostTask(FROM_HERE, 188 sync_thread_.message_loop()->PostTask(FROM_HERE,
178 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoStartSyncing)); 189 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoStartSyncing));
179 } 190 }
180 191
181 void SyncBackendHost::SetPassphrase(const std::string& passphrase, 192 void SyncBackendHost::SetPassphrase(const std::string& passphrase,
182 bool is_explicit) { 193 bool is_explicit) {
183 if (!IsNigoriEnabled()) { 194 if (!IsNigoriEnabled()) {
184 LOG(WARNING) << "Silently dropping SetPassphrase request."; 195 SLOG(WARNING) << "Silently dropping SetPassphrase request.";
185 return; 196 return;
186 } 197 }
187 198
188 // This should only be called by the frontend. 199 // This should only be called by the frontend.
189 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 200 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
190 if (core_->processing_passphrase()) { 201 if (core_->processing_passphrase()) {
191 VLOG(1) << "Attempted to call SetPassphrase while already waiting for " 202 SVLOG(1) << "Attempted to call SetPassphrase while already waiting for "
192 << " result from previous SetPassphrase call. Silently dropping."; 203 << " result from previous SetPassphrase call. Silently dropping.";
193 return; 204 return;
194 } 205 }
195 core_->set_processing_passphrase(); 206 core_->set_processing_passphrase();
196 207
197 // If encryption is enabled and we've got a SetPassphrase 208 // If encryption is enabled and we've got a SetPassphrase
198 sync_thread_.message_loop()->PostTask(FROM_HERE, 209 sync_thread_.message_loop()->PostTask(FROM_HERE,
199 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoSetPassphrase, 210 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoSetPassphrase,
200 passphrase, is_explicit)); 211 passphrase, is_explicit));
201 } 212 }
202 213
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 pending_config_mode_state_->ready_task = ready_task; 286 pending_config_mode_state_->ready_task = ready_task;
276 pending_config_mode_state_->types_to_add = types_to_add_with_nigori; 287 pending_config_mode_state_->types_to_add = types_to_add_with_nigori;
277 pending_config_mode_state_->added_types = 288 pending_config_mode_state_->added_types =
278 registrar_->ConfigureDataTypes(types_to_add_with_nigori, 289 registrar_->ConfigureDataTypes(types_to_add_with_nigori,
279 types_to_remove_with_nigori); 290 types_to_remove_with_nigori);
280 pending_config_mode_state_->reason = reason; 291 pending_config_mode_state_->reason = reason;
281 292
282 // Cleanup disabled types before starting configuration so that 293 // Cleanup disabled types before starting configuration so that
283 // callers can assume that the data types are cleaned up once 294 // callers can assume that the data types are cleaned up once
284 // configuration is done. 295 // configuration is done.
285 if (!types_to_remove.empty()) { 296 if (!types_to_remove_with_nigori.empty()) {
286 sync_thread_.message_loop()->PostTask( 297 sync_thread_.message_loop()->PostTask(
287 FROM_HERE, 298 FROM_HERE,
288 NewRunnableMethod( 299 NewRunnableMethod(
289 core_.get(), 300 core_.get(),
290 &SyncBackendHost::Core::DoRequestCleanupDisabledTypes)); 301 &SyncBackendHost::Core::DoRequestCleanupDisabledTypes));
291 } 302 }
292 303
293 StartConfiguration(NewCallback(core_.get(), 304 StartConfiguration(NewCallback(core_.get(),
294 &SyncBackendHost::Core::FinishConfigureDataTypes)); 305 &SyncBackendHost::Core::FinishConfigureDataTypes));
295 } 306 }
(...skipping 12 matching lines...) Expand all
308 // 319 //
309 // Deletions need a nudge in order to ensure the deletion occurs in a timely 320 // Deletions need a nudge in order to ensure the deletion occurs in a timely
310 // manner (see issue 56416). 321 // manner (see issue 56416).
311 // 322 //
312 // In the case of additions, on the next sync cycle, the syncer should 323 // In the case of additions, on the next sync cycle, the syncer should
313 // notice that the routing info has changed and start the process of 324 // notice that the routing info has changed and start the process of
314 // downloading updates for newly added data types. Once this is 325 // downloading updates for newly added data types. Once this is
315 // complete, the configure_state_.ready_task_ is run via an 326 // complete, the configure_state_.ready_task_ is run via an
316 // OnInitializationComplete notification. 327 // OnInitializationComplete notification.
317 328
318 VLOG(1) << "Syncer in config mode. SBH executing" 329 SVLOG(1) << "Syncer in config mode. SBH executing "
319 << "FinishConfigureDataTypesOnFrontendLoop"; 330 << "FinishConfigureDataTypesOnFrontendLoop";
320 331
321 if (pending_config_mode_state_->added_types.empty() && 332 if (pending_config_mode_state_->added_types.empty() &&
322 !core_->sync_manager()->InitialSyncEndedForAllEnabledTypes()) { 333 !core_->sync_manager()->InitialSyncEndedForAllEnabledTypes()) {
323 LOG(WARNING) << "No new types, but initial sync not finished." 334 SLOG(WARNING) << "No new types, but initial sync not finished."
324 << "Possible sync db corruption / removal."; 335 << "Possible sync db corruption / removal.";
325 // TODO(tim): Log / UMA / count this somehow? 336 // TODO(tim): Log / UMA / count this somehow?
326 // TODO(tim): If no added types, we could (should?) config only for 337 // TODO(tim): If no added types, we could (should?) config only for
327 // types that are needed... but this is a rare corruption edge case or 338 // types that are needed... but this is a rare corruption edge case or
328 // implies the user mucked around with their syncdb, so for now do all. 339 // implies the user mucked around with their syncdb, so for now do all.
329 pending_config_mode_state_->added_types = 340 pending_config_mode_state_->added_types =
330 pending_config_mode_state_->types_to_add; 341 pending_config_mode_state_->types_to_add;
331 } 342 }
332 343
333 // If we've added types, we always want to request a nudge/config (even if 344 // If we've added types, we always want to request a nudge/config (even if
334 // the initial sync is ended), in case we could not decrypt the data. 345 // the initial sync is ended), in case we could not decrypt the data.
335 if (pending_config_mode_state_->added_types.empty()) { 346 if (pending_config_mode_state_->added_types.empty()) {
336 VLOG(1) << "SyncBackendHost(" << this << "): No new types added. " 347 SVLOG(1) << "No new types added; calling ready_task directly";
337 << "Calling ready_task directly";
338 // No new types - just notify the caller that the types are available. 348 // No new types - just notify the caller that the types are available.
339 pending_config_mode_state_->ready_task.Run(true); 349 pending_config_mode_state_->ready_task.Run(true);
340 } else { 350 } else {
341 pending_download_state_.reset(pending_config_mode_state_.release()); 351 pending_download_state_.reset(pending_config_mode_state_.release());
342 352
343 // Always configure nigori if it's enabled. 353 // Always configure nigori if it's enabled.
344 syncable::ModelTypeSet types_to_config = 354 syncable::ModelTypeSet types_to_config =
345 pending_download_state_->added_types; 355 pending_download_state_->added_types;
346 if (IsNigoriEnabled()) { 356 if (IsNigoriEnabled()) {
347 types_to_config.insert(syncable::NIGORI); 357 types_to_config.insert(syncable::NIGORI);
348 } 358 }
349 VLOG(1) << "SyncBackendHost(" << this << "):New Types added. " 359 SVLOG(1) << "Types " << ModelTypeSetToString(types_to_config)
350 << "Calling DoRequestConfig"; 360 << " added; calling DoRequestConfig";
351 sync_thread_.message_loop()->PostTask(FROM_HERE, 361 sync_thread_.message_loop()->PostTask(FROM_HERE,
352 NewRunnableMethod(core_.get(), 362 NewRunnableMethod(core_.get(),
353 &SyncBackendHost::Core::DoRequestConfig, 363 &SyncBackendHost::Core::DoRequestConfig,
354 syncable::ModelTypeBitSetFromSet(types_to_config), 364 syncable::ModelTypeBitSetFromSet(types_to_config),
355 pending_download_state_->reason)); 365 pending_download_state_->reason));
356 } 366 }
357 367
358 pending_config_mode_state_.reset(); 368 pending_config_mode_state_.reset();
359 369
360 // Notify the SyncManager about the new types. 370 // Notify the SyncManager about the new types.
361 sync_thread_.message_loop()->PostTask(FROM_HERE, 371 sync_thread_.message_loop()->PostTask(FROM_HERE,
362 NewRunnableMethod(core_.get(), 372 NewRunnableMethod(core_.get(),
363 &SyncBackendHost::Core::DoUpdateEnabledTypes)); 373 &SyncBackendHost::Core::DoUpdateEnabledTypes));
364 } 374 }
365 375
366 void SyncBackendHost::EncryptDataTypes( 376 void SyncBackendHost::EncryptDataTypes(
367 const syncable::ModelTypeSet& encrypted_types) { 377 const syncable::ModelTypeSet& encrypted_types) {
368 sync_thread_.message_loop()->PostTask(FROM_HERE, 378 sync_thread_.message_loop()->PostTask(FROM_HERE,
369 NewRunnableMethod(core_.get(), 379 NewRunnableMethod(core_.get(),
370 &SyncBackendHost::Core::DoEncryptDataTypes, 380 &SyncBackendHost::Core::DoEncryptDataTypes,
371 encrypted_types)); 381 encrypted_types));
372 } 382 }
373 383
374 syncable::ModelTypeSet SyncBackendHost::GetEncryptedDataTypes() const { 384 syncable::ModelTypeSet SyncBackendHost::GetEncryptedDataTypes() const {
375 DCHECK_GT(initialization_state_, NOT_INITIALIZED); 385 DCHECK_GT(initialization_state_, NOT_INITIALIZED);
376 return core_->sync_manager()->GetEncryptedDataTypes(); 386 return core_->sync_manager()->GetEncryptedDataTypes();
377 } 387 }
378 388
389 syncable::ModelTypeSet SyncBackendHost::GetUnsyncedDataTypes() const {
390 DCHECK_GT(initialization_state_, NOT_INITIALIZED);
391 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare());
392 syncable::ModelTypeSet purged_data_types;
393 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
394 i < syncable::MODEL_TYPE_COUNT; ++i) {
395 syncable::ModelType type = syncable::ModelTypeFromInt(i);
396 sync_pb::DataTypeProgressMarker progress_marker;
397 trans.GetLookup()->GetDownloadProgress(type, &progress_marker);
398 if (progress_marker.token().empty()) {
399 purged_data_types.insert(type);
400 }
401 }
402 return purged_data_types;
403 }
404
379 void SyncBackendHost::ActivateDataType( 405 void SyncBackendHost::ActivateDataType(
380 syncable::ModelType type, ModelSafeGroup group, 406 syncable::ModelType type, ModelSafeGroup group,
381 ChangeProcessor* change_processor) { 407 ChangeProcessor* change_processor) {
382 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); 408 registrar_->ActivateDataType(type, group, change_processor, GetUserShare());
383 } 409 }
384 410
385 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) { 411 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) {
386 registrar_->DeactivateDataType(type); 412 registrar_->DeactivateDataType(type);
387 } 413 }
388 414
(...skipping 13 matching lines...) Expand all
402 if (!host_ || !host_->frontend_) 428 if (!host_ || !host_->frontend_)
403 return; 429 return;
404 430
405 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 431 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
406 432
407 // When setting a passphrase fails, unset our waiting flag. 433 // When setting a passphrase fails, unset our waiting flag.
408 if (reason == sync_api::REASON_SET_PASSPHRASE_FAILED) 434 if (reason == sync_api::REASON_SET_PASSPHRASE_FAILED)
409 processing_passphrase_ = false; 435 processing_passphrase_ = false;
410 436
411 if (processing_passphrase_) { 437 if (processing_passphrase_) {
412 VLOG(1) << "Core received OnPassphraseRequired while processing a " 438 SVLOG(1) << "Core received OnPassphraseRequired while processing a "
413 << "passphrase. Silently dropping."; 439 << "passphrase. Silently dropping.";
414 return; 440 return;
415 } 441 }
416 442
417 host_->frontend_->OnPassphraseRequired(reason); 443 host_->frontend_->OnPassphraseRequired(reason);
418 } 444 }
419 445
420 void SyncBackendHost::Core::NotifyPassphraseAccepted( 446 void SyncBackendHost::Core::NotifyPassphraseAccepted(
421 const std::string& bootstrap_token) { 447 const std::string& bootstrap_token) {
422 if (!host_ || !host_->frontend_) 448 if (!host_ || !host_->frontend_)
423 return; 449 return;
424 450
425 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 451 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
426 452
427 processing_passphrase_ = false; 453 processing_passphrase_ = false;
428 host_->PersistEncryptionBootstrapToken(bootstrap_token); 454 host_->PersistEncryptionBootstrapToken(bootstrap_token);
429 host_->frontend_->OnPassphraseAccepted(); 455 host_->frontend_->OnPassphraseAccepted();
430 } 456 }
431 457
432 void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) { 458 void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) {
433 if (!host_) 459 if (!host_)
434 return; 460 return;
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
436 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 462 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
437 NotificationService::current()->Notify( 463 NotificationService::current()->Notify(
438 chrome::NOTIFICATION_TOKEN_UPDATED, 464 chrome::NOTIFICATION_TOKEN_UPDATED,
439 Source<Profile>(profile_), 465 Source<Profile>(host_->profile_),
440 Details<const TokenAvailableDetails>(&details)); 466 Details<const TokenAvailableDetails>(&details));
441 } 467 }
442 468
443 void SyncBackendHost::Core::NotifyEncryptionComplete( 469 void SyncBackendHost::Core::NotifyEncryptionComplete(
444 const syncable::ModelTypeSet& encrypted_types) { 470 const syncable::ModelTypeSet& encrypted_types) {
445 if (!host_) 471 if (!host_)
446 return; 472 return;
447 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 473 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
448 host_->frontend_->OnEncryptionComplete(encrypted_types); 474 host_->frontend_->OnEncryptionComplete(encrypted_types);
449 } 475 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 bool SyncBackendHost::HasUnsyncedItems() const { 537 bool SyncBackendHost::HasUnsyncedItems() const {
512 DCHECK(initialized()); 538 DCHECK(initialized());
513 return core_->sync_manager()->HasUnsyncedItems(); 539 return core_->sync_manager()->HasUnsyncedItems();
514 } 540 }
515 541
516 void SyncBackendHost::LogUnsyncedItems(int level) const { 542 void SyncBackendHost::LogUnsyncedItems(int level) const {
517 DCHECK(initialized()); 543 DCHECK(initialized());
518 return core_->sync_manager()->LogUnsyncedItems(level); 544 return core_->sync_manager()->LogUnsyncedItems(level);
519 } 545 }
520 546
521 SyncBackendHost::Core::Core(Profile* profile, SyncBackendHost* backend) 547 SyncBackendHost::Core::Core(const std::string& name,
522 : profile_(profile), 548 SyncBackendHost* backend)
549 : name_(name),
523 host_(backend), 550 host_(backend),
524 registrar_(NULL), 551 registrar_(NULL),
525 processing_passphrase_(false) { 552 processing_passphrase_(false) {
526 DCHECK(host_); 553 DCHECK(host_);
527 } 554 }
528 555
529 // Helper to construct a user agent string (ASCII) suitable for use by 556 // Helper to construct a user agent string (ASCII) suitable for use by
530 // the syncapi for any HTTP communication. This string is used by the sync 557 // the syncapi for any HTTP communication. This string is used by the sync
531 // backend for classifying client types when calculating statistics. 558 // backend for classifying client types when calculating statistics.
532 std::string MakeUserAgentForSyncApi() { 559 std::string MakeUserAgentForSyncApi() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 595
569 // Make sure that the directory exists before initializing the backend. 596 // Make sure that the directory exists before initializing the backend.
570 // If it already exists, this will do no harm. 597 // If it already exists, this will do no harm.
571 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); 598 bool success = file_util::CreateDirectory(host_->sync_data_folder_path());
572 DCHECK(success); 599 DCHECK(success);
573 600
574 DCHECK(!registrar_); 601 DCHECK(!registrar_);
575 registrar_ = options.registrar; 602 registrar_ = options.registrar;
576 DCHECK(registrar_); 603 DCHECK(registrar_);
577 604
578 sync_manager_.reset(new sync_api::SyncManager(profile_->GetDebugName())), 605 sync_manager_.reset(new sync_api::SyncManager(name_));
579 sync_manager_->AddObserver(this); 606 sync_manager_->AddObserver(this);
580 const FilePath& path_str = host_->sync_data_folder_path(); 607 const FilePath& path_str = host_->sync_data_folder_path();
581 success = sync_manager_->Init( 608 success = sync_manager_->Init(
582 path_str, 609 path_str,
583 options.event_handler, 610 options.event_handler,
584 options.service_url.host() + options.service_url.path(), 611 options.service_url.host() + options.service_url.path(),
585 options.service_url.EffectiveIntPort(), 612 options.service_url.EffectiveIntPort(),
586 options.service_url.SchemeIsSecure(), 613 options.service_url.SchemeIsSecure(),
587 host_->MakeHttpBridgeFactory(options.request_context_getter), 614 host_->MakeHttpBridgeFactory(options.request_context_getter),
588 options.registrar, 615 options.registrar,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } 725 }
699 726
700 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop( 727 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop(
701 SyncSessionSnapshot* snapshot) { 728 SyncSessionSnapshot* snapshot) {
702 if (!host_ || !host_->frontend_) 729 if (!host_ || !host_->frontend_)
703 return; 730 return;
704 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 731 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
705 732
706 host_->last_snapshot_.reset(snapshot); 733 host_->last_snapshot_.reset(snapshot);
707 734
735 SVLOG(1) << "Got snapshot " << snapshot->ToString();
736
708 const syncable::ModelTypeSet& to_migrate = 737 const syncable::ModelTypeSet& to_migrate =
709 snapshot->syncer_status.types_needing_local_migration; 738 snapshot->syncer_status.types_needing_local_migration;
710 if (!to_migrate.empty()) 739 if (!to_migrate.empty())
711 host_->frontend_->OnMigrationNeededForTypes(to_migrate); 740 host_->frontend_->OnMigrationNeededForTypes(to_migrate);
712 741
713 // Process any changes to the datatypes we're syncing. 742 // Process any changes to the datatypes we're syncing.
714 // TODO(sync): add support for removing types. 743 // TODO(sync): add support for removing types.
715 syncable::ModelTypeSet to_add; 744 syncable::ModelTypeSet to_add;
716 if (host_->initialized() && 745 if (host_->initialized() &&
717 sync_manager()->ReceivedExperimentalTypes(&to_add)) { 746 sync_manager()->ReceivedExperimentalTypes(&to_add)) {
718 host_->frontend_->OnDataTypesChanged(to_add); 747 host_->frontend_->OnDataTypesChanged(to_add);
719 } 748 }
720 749
721 // If we are waiting for a configuration change, check here to see 750 // If we are waiting for a configuration change, check here to see
722 // if this sync cycle has initialized all of the types we've been 751 // if this sync cycle has initialized all of the types we've been
723 // waiting for. 752 // waiting for.
724 if (host_->pending_download_state_.get()) { 753 if (host_->pending_download_state_.get()) {
725 scoped_ptr<PendingConfigureDataTypesState> state( 754 scoped_ptr<PendingConfigureDataTypesState> state(
726 host_->pending_download_state_.release()); 755 host_->pending_download_state_.release());
727 DCHECK( 756 DCHECK(
728 std::includes(state->types_to_add.begin(), state->types_to_add.end(), 757 std::includes(state->types_to_add.begin(), state->types_to_add.end(),
729 state->added_types.begin(), state->added_types.end())); 758 state->added_types.begin(), state->added_types.end()));
759 SVLOG(1)
760 << "Added types: "
761 << syncable::ModelTypeSetToString(state->added_types)
762 << ", configured types: "
763 << syncable::ModelTypeBitSetToString(snapshot->initial_sync_ended);
730 syncable::ModelTypeBitSet added_types = 764 syncable::ModelTypeBitSet added_types =
731 syncable::ModelTypeBitSetFromSet(state->added_types); 765 syncable::ModelTypeBitSetFromSet(state->added_types);
732 bool found_all_added = 766 bool found_all_added =
733 (added_types & snapshot->initial_sync_ended) == added_types; 767 (added_types & snapshot->initial_sync_ended) == added_types;
734 state->ready_task.Run(found_all_added); 768 state->ready_task.Run(found_all_added);
735 if (!found_all_added) 769 if (!found_all_added)
736 return; 770 return;
737 } 771 }
738 772
739 if (host_->initialized()) 773 if (host_->initialized())
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 sync_manager_->RequestCleanupDisabledTypes(); 925 sync_manager_->RequestCleanupDisabledTypes();
892 } 926 }
893 927
894 void SyncBackendHost::Core::SaveChanges() { 928 void SyncBackendHost::Core::SaveChanges() {
895 sync_manager_->SaveChanges(); 929 sync_manager_->SaveChanges();
896 } 930 }
897 931
898 void SyncBackendHost::Core::DeleteSyncDataFolder() { 932 void SyncBackendHost::Core::DeleteSyncDataFolder() {
899 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { 933 if (file_util::DirectoryExists(host_->sync_data_folder_path())) {
900 if (!file_util::Delete(host_->sync_data_folder_path(), true)) 934 if (!file_util::Delete(host_->sync_data_folder_path(), true))
901 LOG(DFATAL) << "Could not delete the Sync Data folder."; 935 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
902 } 936 }
903 } 937 }
904 938
939 #undef SVLOG
940
941 #undef SLOG
942
905 } // namespace browser_sync 943 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698