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

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: Address more comments 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.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (!host_ || !host_->frontend_) 412 if (!host_ || !host_->frontend_)
403 return; 413 return;
404 414
405 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 415 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
406 416
407 // When setting a passphrase fails, unset our waiting flag. 417 // When setting a passphrase fails, unset our waiting flag.
408 if (reason == sync_api::REASON_SET_PASSPHRASE_FAILED) 418 if (reason == sync_api::REASON_SET_PASSPHRASE_FAILED)
409 processing_passphrase_ = false; 419 processing_passphrase_ = false;
410 420
411 if (processing_passphrase_) { 421 if (processing_passphrase_) {
412 VLOG(1) << "Core received OnPassphraseRequired while processing a " 422 SVLOG(1) << "Core received OnPassphraseRequired while processing a "
413 << "passphrase. Silently dropping."; 423 << "passphrase. Silently dropping.";
414 return; 424 return;
415 } 425 }
416 426
417 host_->frontend_->OnPassphraseRequired(reason); 427 host_->frontend_->OnPassphraseRequired(reason);
418 } 428 }
419 429
420 void SyncBackendHost::Core::NotifyPassphraseAccepted( 430 void SyncBackendHost::Core::NotifyPassphraseAccepted(
421 const std::string& bootstrap_token) { 431 const std::string& bootstrap_token) {
422 if (!host_ || !host_->frontend_) 432 if (!host_ || !host_->frontend_)
423 return; 433 return;
424 434
425 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 435 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
426 436
427 processing_passphrase_ = false; 437 processing_passphrase_ = false;
428 host_->PersistEncryptionBootstrapToken(bootstrap_token); 438 host_->PersistEncryptionBootstrapToken(bootstrap_token);
429 host_->frontend_->OnPassphraseAccepted(); 439 host_->frontend_->OnPassphraseAccepted();
430 } 440 }
431 441
432 void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) { 442 void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) {
433 if (!host_) 443 if (!host_)
434 return; 444 return;
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
436 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 446 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
437 NotificationService::current()->Notify( 447 NotificationService::current()->Notify(
438 chrome::NOTIFICATION_TOKEN_UPDATED, 448 chrome::NOTIFICATION_TOKEN_UPDATED,
439 Source<Profile>(profile_), 449 Source<Profile>(host_->profile_),
440 Details<const TokenAvailableDetails>(&details)); 450 Details<const TokenAvailableDetails>(&details));
441 } 451 }
442 452
443 void SyncBackendHost::Core::NotifyEncryptionComplete( 453 void SyncBackendHost::Core::NotifyEncryptionComplete(
444 const syncable::ModelTypeSet& encrypted_types) { 454 const syncable::ModelTypeSet& encrypted_types) {
445 if (!host_) 455 if (!host_)
446 return; 456 return;
447 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 457 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
448 host_->frontend_->OnEncryptionComplete(encrypted_types); 458 host_->frontend_->OnEncryptionComplete(encrypted_types);
449 } 459 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 bool SyncBackendHost::HasUnsyncedItems() const { 521 bool SyncBackendHost::HasUnsyncedItems() const {
512 DCHECK(initialized()); 522 DCHECK(initialized());
513 return core_->sync_manager()->HasUnsyncedItems(); 523 return core_->sync_manager()->HasUnsyncedItems();
514 } 524 }
515 525
516 void SyncBackendHost::LogUnsyncedItems(int level) const { 526 void SyncBackendHost::LogUnsyncedItems(int level) const {
517 DCHECK(initialized()); 527 DCHECK(initialized());
518 return core_->sync_manager()->LogUnsyncedItems(level); 528 return core_->sync_manager()->LogUnsyncedItems(level);
519 } 529 }
520 530
521 SyncBackendHost::Core::Core(Profile* profile, SyncBackendHost* backend) 531 SyncBackendHost::Core::Core(const std::string& name,
522 : profile_(profile), 532 SyncBackendHost* backend)
533 : name_(name),
523 host_(backend), 534 host_(backend),
524 registrar_(NULL), 535 registrar_(NULL),
525 processing_passphrase_(false) { 536 processing_passphrase_(false) {
526 DCHECK(host_); 537 DCHECK(host_);
527 } 538 }
528 539
529 // Helper to construct a user agent string (ASCII) suitable for use by 540 // 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 541 // the syncapi for any HTTP communication. This string is used by the sync
531 // backend for classifying client types when calculating statistics. 542 // backend for classifying client types when calculating statistics.
532 std::string MakeUserAgentForSyncApi() { 543 std::string MakeUserAgentForSyncApi() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 579
569 // Make sure that the directory exists before initializing the backend. 580 // Make sure that the directory exists before initializing the backend.
570 // If it already exists, this will do no harm. 581 // If it already exists, this will do no harm.
571 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); 582 bool success = file_util::CreateDirectory(host_->sync_data_folder_path());
572 DCHECK(success); 583 DCHECK(success);
573 584
574 DCHECK(!registrar_); 585 DCHECK(!registrar_);
575 registrar_ = options.registrar; 586 registrar_ = options.registrar;
576 DCHECK(registrar_); 587 DCHECK(registrar_);
577 588
578 sync_manager_.reset(new sync_api::SyncManager(profile_->GetDebugName())), 589 sync_manager_.reset(new sync_api::SyncManager(name_));
579 sync_manager_->AddObserver(this); 590 sync_manager_->AddObserver(this);
580 const FilePath& path_str = host_->sync_data_folder_path(); 591 const FilePath& path_str = host_->sync_data_folder_path();
581 success = sync_manager_->Init( 592 success = sync_manager_->Init(
582 path_str, 593 path_str,
583 options.event_handler, 594 options.event_handler,
584 options.service_url.host() + options.service_url.path(), 595 options.service_url.host() + options.service_url.path(),
585 options.service_url.EffectiveIntPort(), 596 options.service_url.EffectiveIntPort(),
586 options.service_url.SchemeIsSecure(), 597 options.service_url.SchemeIsSecure(),
587 host_->MakeHttpBridgeFactory(options.request_context_getter), 598 host_->MakeHttpBridgeFactory(options.request_context_getter),
588 options.registrar, 599 options.registrar,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } 709 }
699 710
700 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop( 711 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop(
701 SyncSessionSnapshot* snapshot) { 712 SyncSessionSnapshot* snapshot) {
702 if (!host_ || !host_->frontend_) 713 if (!host_ || !host_->frontend_)
703 return; 714 return;
704 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 715 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
705 716
706 host_->last_snapshot_.reset(snapshot); 717 host_->last_snapshot_.reset(snapshot);
707 718
719 SVLOG(1) << "Got snapshot " << snapshot->ToString();
720
708 const syncable::ModelTypeSet& to_migrate = 721 const syncable::ModelTypeSet& to_migrate =
709 snapshot->syncer_status.types_needing_local_migration; 722 snapshot->syncer_status.types_needing_local_migration;
710 if (!to_migrate.empty()) 723 if (!to_migrate.empty())
711 host_->frontend_->OnMigrationNeededForTypes(to_migrate); 724 host_->frontend_->OnMigrationNeededForTypes(to_migrate);
712 725
713 // Process any changes to the datatypes we're syncing. 726 // Process any changes to the datatypes we're syncing.
714 // TODO(sync): add support for removing types. 727 // TODO(sync): add support for removing types.
715 syncable::ModelTypeSet to_add; 728 syncable::ModelTypeSet to_add;
716 if (host_->initialized() && 729 if (host_->initialized() &&
717 sync_manager()->ReceivedExperimentalTypes(&to_add)) { 730 sync_manager()->ReceivedExperimentalTypes(&to_add)) {
718 host_->frontend_->OnDataTypesChanged(to_add); 731 host_->frontend_->OnDataTypesChanged(to_add);
719 } 732 }
720 733
721 // If we are waiting for a configuration change, check here to see 734 // 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 735 // if this sync cycle has initialized all of the types we've been
723 // waiting for. 736 // waiting for.
724 if (host_->pending_download_state_.get()) { 737 if (host_->pending_download_state_.get()) {
725 scoped_ptr<PendingConfigureDataTypesState> state( 738 scoped_ptr<PendingConfigureDataTypesState> state(
726 host_->pending_download_state_.release()); 739 host_->pending_download_state_.release());
727 DCHECK( 740 DCHECK(
728 std::includes(state->types_to_add.begin(), state->types_to_add.end(), 741 std::includes(state->types_to_add.begin(), state->types_to_add.end(),
729 state->added_types.begin(), state->added_types.end())); 742 state->added_types.begin(), state->added_types.end()));
743 SVLOG(1)
744 << "Added types: "
745 << syncable::ModelTypeSetToString(state->added_types)
746 << ", configured types: "
747 << syncable::ModelTypeBitSetToString(snapshot->initial_sync_ended);
730 syncable::ModelTypeBitSet added_types = 748 syncable::ModelTypeBitSet added_types =
731 syncable::ModelTypeBitSetFromSet(state->added_types); 749 syncable::ModelTypeBitSetFromSet(state->added_types);
732 bool found_all_added = 750 bool found_all_added =
733 (added_types & snapshot->initial_sync_ended) == added_types; 751 (added_types & snapshot->initial_sync_ended) == added_types;
734 state->ready_task.Run(found_all_added); 752 state->ready_task.Run(found_all_added);
735 if (!found_all_added) 753 if (!found_all_added)
736 return; 754 return;
737 } 755 }
738 756
739 if (host_->initialized()) 757 if (host_->initialized())
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 sync_manager_->RequestCleanupDisabledTypes(); 909 sync_manager_->RequestCleanupDisabledTypes();
892 } 910 }
893 911
894 void SyncBackendHost::Core::SaveChanges() { 912 void SyncBackendHost::Core::SaveChanges() {
895 sync_manager_->SaveChanges(); 913 sync_manager_->SaveChanges();
896 } 914 }
897 915
898 void SyncBackendHost::Core::DeleteSyncDataFolder() { 916 void SyncBackendHost::Core::DeleteSyncDataFolder() {
899 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { 917 if (file_util::DirectoryExists(host_->sync_data_folder_path())) {
900 if (!file_util::Delete(host_->sync_data_folder_path(), true)) 918 if (!file_util::Delete(host_->sync_data_folder_path(), true))
901 LOG(DFATAL) << "Could not delete the Sync Data folder."; 919 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
902 } 920 }
903 } 921 }
904 922
923 #undef SVLOG
924
925 #undef SLOG
926
905 } // namespace browser_sync 927 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698