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

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

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More review fixes Created 7 years, 7 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 "build/build_config.h"
6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 5 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 6
9 #include <algorithm> 7 #include <algorithm>
10 #include <map> 8 #include <map>
11 9
12 #include "base/bind.h" 10 #include "base/bind.h"
13 #include "base/command_line.h" 11 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
15 #include "base/file_util.h" 13 #include "base/file_util.h"
16 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
17 #include "base/location.h" 15 #include "base/location.h"
18 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
19 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
20 #include "base/timer.h" 18 #include "base/timer.h"
21 #include "base/tracked_objects.h" 19 #include "base/tracked_objects.h"
22 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
23 #include "build/build_config.h" 21 #include "build/build_config.h"
24 #include "chrome/browser/invalidation/invalidator_storage.h" 22 #include "chrome/browser/invalidation/invalidation_service.h"
23 #include "chrome/browser/invalidation/invalidation_service_factory.h"
25 #include "chrome/browser/net/network_time_tracker.h" 24 #include "chrome/browser/net/network_time_tracker.h"
26 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/signin/token_service.h" 26 #include "chrome/browser/signin/token_service.h"
28 #include "chrome/browser/signin/token_service_factory.h" 27 #include "chrome/browser/signin/token_service_factory.h"
29 #include "chrome/browser/sync/glue/android_invalidator_bridge.h"
30 #include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h"
31 #include "chrome/browser/sync/glue/change_processor.h" 28 #include "chrome/browser/sync/glue/change_processor.h"
32 #include "chrome/browser/sync/glue/chrome_encryptor.h" 29 #include "chrome/browser/sync/glue/chrome_encryptor.h"
33 #include "chrome/browser/sync/glue/device_info.h" 30 #include "chrome/browser/sync/glue/device_info.h"
34 #include "chrome/browser/sync/glue/sync_backend_registrar.h" 31 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
35 #include "chrome/browser/sync/glue/synced_device_tracker.h" 32 #include "chrome/browser/sync/glue/synced_device_tracker.h"
36 #include "chrome/browser/sync/sync_prefs.h" 33 #include "chrome/browser/sync/sync_prefs.h"
37 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
38 #include "chrome/common/chrome_notification_types.h" 35 #include "chrome/common/chrome_notification_types.h"
39 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/chrome_version_info.h" 37 #include "chrome/common/chrome_version_info.h"
41 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/notification_details.h" 39 #include "content/public/browser/notification_details.h"
43 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/notification_source.h" 41 #include "content/public/browser/notification_source.h"
45 #include "content/public/common/content_client.h" 42 #include "content/public/common/content_client.h"
46 #include "google_apis/gaia/gaia_constants.h" 43 #include "google_apis/gaia/gaia_constants.h"
47 #include "jingle/notifier/base/notification_method.h" 44 #include "jingle/notifier/base/notification_method.h"
48 #include "jingle/notifier/base/notifier_options.h" 45 #include "jingle/notifier/base/notifier_options.h"
49 #include "net/base/host_port_pair.h" 46 #include "net/base/host_port_pair.h"
50 #include "net/url_request/url_request_context_getter.h" 47 #include "net/url_request/url_request_context_getter.h"
51 #include "sync/internal_api/public/base_transaction.h" 48 #include "sync/internal_api/public/base_transaction.h"
52 #include "sync/internal_api/public/engine/model_safe_worker.h" 49 #include "sync/internal_api/public/engine/model_safe_worker.h"
53 #include "sync/internal_api/public/http_bridge.h" 50 #include "sync/internal_api/public/http_bridge.h"
54 #include "sync/internal_api/public/internal_components_factory_impl.h" 51 #include "sync/internal_api/public/internal_components_factory_impl.h"
55 #include "sync/internal_api/public/read_transaction.h" 52 #include "sync/internal_api/public/read_transaction.h"
56 #include "sync/internal_api/public/sync_manager_factory.h" 53 #include "sync/internal_api/public/sync_manager_factory.h"
57 #include "sync/internal_api/public/util/experiments.h" 54 #include "sync/internal_api/public/util/experiments.h"
58 #include "sync/internal_api/public/util/sync_string_conversions.h" 55 #include "sync/internal_api/public/util/sync_string_conversions.h"
59 #include "sync/notifier/invalidator.h"
60 #include "sync/protocol/encryption.pb.h" 56 #include "sync/protocol/encryption.pb.h"
61 #include "sync/protocol/sync.pb.h" 57 #include "sync/protocol/sync.pb.h"
62 #include "sync/util/nigori.h" 58 #include "sync/util/nigori.h"
63 59
64 static const int kSaveChangesIntervalSeconds = 10; 60 static const int kSaveChangesIntervalSeconds = 10;
65 static const base::FilePath::CharType kSyncDataFolderName[] = 61 static const base::FilePath::CharType kSyncDataFolderName[] =
66 FILE_PATH_LITERAL("Sync Data"); 62 FILE_PATH_LITERAL("Sync Data");
67 63
68 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; 64 typedef TokenService::TokenAvailableDetails TokenAvailableDetails;
69 65
(...skipping 10 matching lines...) Expand all
80 // Helper macros to log with the syncer thread name; useful when there 76 // Helper macros to log with the syncer thread name; useful when there
81 // are multiple syncers involved. 77 // are multiple syncers involved.
82 78
83 #define SLOG(severity) LOG(severity) << name_ << ": " 79 #define SLOG(severity) LOG(severity) << name_ << ": "
84 80
85 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 81 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
86 82
87 class SyncBackendHost::Core 83 class SyncBackendHost::Core
88 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, 84 : public base::RefCountedThreadSafe<SyncBackendHost::Core>,
89 public syncer::SyncEncryptionHandler::Observer, 85 public syncer::SyncEncryptionHandler::Observer,
90 public syncer::SyncManager::Observer, 86 public syncer::SyncManager::Observer {
91 public syncer::InvalidationHandler {
92 public: 87 public:
93 Core(const std::string& name, 88 Core(const std::string& name,
94 const base::FilePath& sync_data_folder_path, 89 const base::FilePath& sync_data_folder_path,
95 const base::WeakPtr<SyncBackendHost>& backend); 90 const base::WeakPtr<SyncBackendHost>& backend);
96 91
97 // SyncManager::Observer implementation. The Core just acts like an air 92 // SyncManager::Observer implementation. The Core just acts like an air
98 // traffic controller here, forwarding incoming messages to appropriate 93 // traffic controller here, forwarding incoming messages to appropriate
99 // landing threads. 94 // landing threads.
100 virtual void OnSyncCycleCompleted( 95 virtual void OnSyncCycleCompleted(
101 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; 96 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE;
(...skipping 20 matching lines...) Expand all
122 syncer::BootstrapTokenType type) OVERRIDE; 117 syncer::BootstrapTokenType type) OVERRIDE;
123 virtual void OnEncryptedTypesChanged( 118 virtual void OnEncryptedTypesChanged(
124 syncer::ModelTypeSet encrypted_types, 119 syncer::ModelTypeSet encrypted_types,
125 bool encrypt_everything) OVERRIDE; 120 bool encrypt_everything) OVERRIDE;
126 virtual void OnEncryptionComplete() OVERRIDE; 121 virtual void OnEncryptionComplete() OVERRIDE;
127 virtual void OnCryptographerStateChanged( 122 virtual void OnCryptographerStateChanged(
128 syncer::Cryptographer* cryptographer) OVERRIDE; 123 syncer::Cryptographer* cryptographer) OVERRIDE;
129 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, 124 virtual void OnPassphraseTypeChanged(syncer::PassphraseType type,
130 base::Time passphrase_time) OVERRIDE; 125 base::Time passphrase_time) OVERRIDE;
131 126
132 // syncer::InvalidationHandler implementation. 127 // Forwards an invalidation state change to the sync manager.
133 virtual void OnInvalidatorStateChange( 128 void DoOnInvalidatorStateChange(syncer::InvalidatorState state);
134 syncer::InvalidatorState state) OVERRIDE; 129
135 virtual void OnIncomingInvalidation( 130 // Forwards an invalidation to the sync manager.
136 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; 131 void DoOnIncomingInvalidation(
132 syncer::ObjectIdInvalidationMap invalidation_map);
137 133
138 // Note: 134 // Note:
139 // 135 //
140 // The Do* methods are the various entry points from our 136 // The Do* methods are the various entry points from our
141 // SyncBackendHost. They are all called on the sync thread to 137 // SyncBackendHost. They are all called on the sync thread to
142 // actually perform synchronous (and potentially blocking) syncapi 138 // actually perform synchronous (and potentially blocking) syncapi
143 // operations. 139 // operations.
144 // 140 //
145 // Called to perform initialization of the syncapi on behalf of 141 // Called to perform initialization of the syncapi on behalf of
146 // SyncBackendHost::Initialize. 142 // SyncBackendHost::Initialize.
147 void DoInitialize(const DoInitializeOptions& options); 143 void DoInitialize(const DoInitializeOptions& options);
148 144
149 // Called to perform credential update on behalf of 145 // Called to perform credential update on behalf of
150 // SyncBackendHost::UpdateCredentials. 146 // SyncBackendHost::UpdateCredentials.
151 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); 147 void DoUpdateCredentials(const syncer::SyncCredentials& credentials);
152 148
153 // Called to update the given registered ids on behalf of
154 // SyncBackendHost::UpdateRegisteredInvalidationIds.
155 void DoUpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids);
156
157 // Called to acknowledge an invalidation on behalf of
158 // SyncBackendHost::AcknowledgeInvalidation.
159 void DoAcknowledgeInvalidation(const invalidation::ObjectId& id,
160 const syncer::AckHandle& ack_handle);
161
162 // Called to tell the syncapi to start syncing (generally after 149 // Called to tell the syncapi to start syncing (generally after
163 // initialization and authentication). 150 // initialization and authentication).
164 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); 151 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info);
165 152
166 // Called to set the passphrase for encryption. 153 // Called to set the passphrase for encryption.
167 void DoSetEncryptionPassphrase(const std::string& passphrase, 154 void DoSetEncryptionPassphrase(const std::string& passphrase,
168 bool is_explicit); 155 bool is_explicit);
169 156
170 // Called to decrypt the pending keys. 157 // Called to decrypt the pending keys.
171 void DoSetDecryptionPassphrase(const std::string& passphrase); 158 void DoSetDecryptionPassphrase(const std::string& passphrase);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 270
284 // Our encryptor, which uses Chrome's encryption functions. 271 // Our encryptor, which uses Chrome's encryption functions.
285 ChromeEncryptor encryptor_; 272 ChromeEncryptor encryptor_;
286 273
287 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. 274 // A special ChangeProcessor that tracks the DEVICE_INFO type for us.
288 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; 275 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_;
289 276
290 // The top-level syncapi entry point. Lives on the sync thread. 277 // The top-level syncapi entry point. Lives on the sync thread.
291 scoped_ptr<syncer::SyncManager> sync_manager_; 278 scoped_ptr<syncer::SyncManager> sync_manager_;
292 279
293 // Whether or not we registered with |sync_manager_| as an invalidation
294 // handler. Necessary since we may end up trying to unregister before we
295 // register in tests (in synchronous initialization mode).
296 //
297 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
298 bool registered_as_invalidation_handler_;
299
300 DISALLOW_COPY_AND_ASSIGN(Core); 280 DISALLOW_COPY_AND_ASSIGN(Core);
301 }; 281 };
302 282
303 namespace {
304
305 // Parses the given command line for notifier options.
306 notifier::NotifierOptions ParseNotifierOptions(
307 const CommandLine& command_line,
308 const scoped_refptr<net::URLRequestContextGetter>&
309 request_context_getter) {
310 notifier::NotifierOptions notifier_options;
311 notifier_options.request_context_getter = request_context_getter;
312
313 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) {
314 notifier_options.xmpp_host_port =
315 net::HostPortPair::FromString(
316 command_line.GetSwitchValueASCII(
317 switches::kSyncNotificationHostPort));
318 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString()
319 << " for test sync notification server.";
320 }
321
322 notifier_options.try_ssltcp_first =
323 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp);
324 DVLOG_IF(1, notifier_options.try_ssltcp_first)
325 << "Trying SSL/TCP port before XMPP port for notifications.";
326
327 notifier_options.invalidate_xmpp_login =
328 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin);
329 DVLOG_IF(1, notifier_options.invalidate_xmpp_login)
330 << "Invalidating sync XMPP login.";
331
332 notifier_options.allow_insecure_connection =
333 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection);
334 DVLOG_IF(1, notifier_options.allow_insecure_connection)
335 << "Allowing insecure XMPP connections.";
336
337 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) {
338 const std::string notification_method_str(
339 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod));
340 notifier_options.notification_method =
341 notifier::StringToNotificationMethod(notification_method_str);
342 }
343
344 return notifier_options;
345 }
346
347 } // namespace
348
349 SyncBackendHost::SyncBackendHost( 283 SyncBackendHost::SyncBackendHost(
350 const std::string& name, 284 const std::string& name,
351 Profile* profile, 285 Profile* profile,
352 const base::WeakPtr<SyncPrefs>& sync_prefs, 286 const base::WeakPtr<SyncPrefs>& sync_prefs)
353 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage)
354 : weak_ptr_factory_(this), 287 : weak_ptr_factory_(this),
355 sync_thread_("Chrome_SyncThread"), 288 sync_thread_("Chrome_SyncThread"),
356 frontend_loop_(MessageLoop::current()), 289 frontend_loop_(MessageLoop::current()),
357 profile_(profile), 290 profile_(profile),
358 name_(name), 291 name_(name),
359 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), 292 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName),
360 weak_ptr_factory_.GetWeakPtr())), 293 weak_ptr_factory_.GetWeakPtr())),
361 initialization_state_(NOT_ATTEMPTED), 294 initialization_state_(NOT_ATTEMPTED),
362 sync_prefs_(sync_prefs), 295 sync_prefs_(sync_prefs),
363 invalidator_factory_(
364 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
365 profile_->GetRequestContext()),
366 content::GetUserAgent(GURL()),
367 invalidator_storage),
368 frontend_(NULL), 296 frontend_(NULL),
369 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { 297 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE),
298 invalidator_(
299 invalidation::InvalidationServiceFactory::GetForProfile(profile)) {
370 } 300 }
371 301
372 SyncBackendHost::SyncBackendHost(Profile* profile) 302 SyncBackendHost::SyncBackendHost(Profile* profile)
373 : weak_ptr_factory_(this), 303 : weak_ptr_factory_(this),
374 sync_thread_("Chrome_SyncThread"), 304 sync_thread_("Chrome_SyncThread"),
375 frontend_loop_(MessageLoop::current()), 305 frontend_loop_(MessageLoop::current()),
376 profile_(profile), 306 profile_(profile),
377 name_("Unknown"), 307 name_("Unknown"),
378 initialization_state_(NOT_ATTEMPTED), 308 initialization_state_(NOT_ATTEMPTED),
379 invalidator_factory_(
380 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
381 profile_->GetRequestContext()),
382 content::GetUserAgent(GURL()),
383 base::WeakPtr<syncer::InvalidationStateTracker>()),
384 frontend_(NULL), 309 frontend_(NULL),
385 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { 310 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) {
386 } 311 }
387 312
388 SyncBackendHost::~SyncBackendHost() { 313 SyncBackendHost::~SyncBackendHost() {
389 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 314 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
390 DCHECK(!android_invalidator_bridge_.get());
391 DCHECK(!registrar_.get()); 315 DCHECK(!registrar_.get());
392 } 316 }
393 317
394 namespace { 318 namespace {
395 319
396 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( 320 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory(
397 const scoped_refptr<net::URLRequestContextGetter>& getter, 321 const scoped_refptr<net::URLRequestContextGetter>& getter,
398 const NetworkTimeTracker::UpdateCallback& update_callback) { 322 const NetworkTimeTracker::UpdateCallback& update_callback) {
399 chrome::VersionInfo version_info; 323 chrome::VersionInfo version_info;
400 return scoped_ptr<syncer::HttpPostProviderFactory>( 324 return scoped_ptr<syncer::HttpPostProviderFactory>(
(...skipping 11 matching lines...) Expand all
412 const GURL& sync_service_url, 336 const GURL& sync_service_url,
413 const SyncCredentials& credentials, 337 const SyncCredentials& credentials,
414 bool delete_sync_data_folder, 338 bool delete_sync_data_folder,
415 syncer::SyncManagerFactory* sync_manager_factory, 339 syncer::SyncManagerFactory* sync_manager_factory,
416 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 340 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
417 syncer::ReportUnrecoverableErrorFunction 341 syncer::ReportUnrecoverableErrorFunction
418 report_unrecoverable_error_function) { 342 report_unrecoverable_error_function) {
419 if (!sync_thread_.Start()) 343 if (!sync_thread_.Start())
420 return; 344 return;
421 345
422 android_invalidator_bridge_.reset(
423 new AndroidInvalidatorBridge(
424 profile_, sync_thread_.message_loop_proxy()));
425
426 frontend_ = frontend; 346 frontend_ = frontend;
427 DCHECK(frontend); 347 DCHECK(frontend);
428 348
429 registrar_.reset(new SyncBackendRegistrar(name_, 349 registrar_.reset(new SyncBackendRegistrar(name_,
430 profile_, 350 profile_,
431 sync_thread_.message_loop())); 351 sync_thread_.message_loop()));
432 syncer::ModelSafeRoutingInfo routing_info; 352 syncer::ModelSafeRoutingInfo routing_info;
433 std::vector<syncer::ModelSafeWorker*> workers; 353 std::vector<syncer::ModelSafeWorker*> workers;
434 registrar_->GetModelSafeRoutingInfo(&routing_info); 354 registrar_->GetModelSafeRoutingInfo(&routing_info);
435 registrar_->GetWorkers(&workers); 355 registrar_->GetWorkers(&workers);
436 356
437 InternalComponentsFactory::Switches factory_switches = { 357 InternalComponentsFactory::Switches factory_switches = {
438 InternalComponentsFactory::ENCRYPTION_KEYSTORE, 358 InternalComponentsFactory::ENCRYPTION_KEYSTORE,
439 InternalComponentsFactory::BACKOFF_NORMAL 359 InternalComponentsFactory::BACKOFF_NORMAL
440 }; 360 };
441 361
442 CommandLine* cl = CommandLine::ForCurrentProcess(); 362 CommandLine* cl = CommandLine::ForCurrentProcess();
443 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { 363 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) {
444 factory_switches.backoff_override = 364 factory_switches.backoff_override =
445 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; 365 InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE;
446 } 366 }
447 367
368 invalidator_->RegisterInvalidationHandler(this);
369
448 initialization_state_ = CREATING_SYNC_MANAGER; 370 initialization_state_ = CREATING_SYNC_MANAGER;
449 InitCore(DoInitializeOptions( 371 InitCore(DoInitializeOptions(
450 sync_thread_.message_loop(), 372 sync_thread_.message_loop(),
451 registrar_.get(), 373 registrar_.get(),
452 routing_info, 374 routing_info,
453 workers, 375 workers,
454 &extensions_activity_monitor_, 376 &extensions_activity_monitor_,
455 event_handler, 377 event_handler,
456 sync_service_url, 378 sync_service_url,
457 base::Bind(&MakeHttpBridgeFactory, 379 base::Bind(&MakeHttpBridgeFactory,
458 make_scoped_refptr(profile_->GetRequestContext()), 380 make_scoped_refptr(profile_->GetRequestContext()),
459 NetworkTimeTracker::BuildNotifierUpdateCallback()), 381 NetworkTimeTracker::BuildNotifierUpdateCallback()),
460 credentials, 382 credentials,
461 android_invalidator_bridge_.get(), 383 invalidator_->GetInvalidatorClientId(),
462 &invalidator_factory_,
463 sync_manager_factory, 384 sync_manager_factory,
464 delete_sync_data_folder, 385 delete_sync_data_folder,
465 sync_prefs_->GetEncryptionBootstrapToken(), 386 sync_prefs_->GetEncryptionBootstrapToken(),
466 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), 387 sync_prefs_->GetKeystoreEncryptionBootstrapToken(),
467 new InternalComponentsFactoryImpl(factory_switches), 388 new InternalComponentsFactoryImpl(factory_switches),
468 unrecoverable_error_handler, 389 unrecoverable_error_handler,
469 report_unrecoverable_error_function)); 390 report_unrecoverable_error_function));
470 } 391 }
471 392
472 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 393 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
473 DCHECK(sync_thread_.IsRunning()); 394 DCHECK(sync_thread_.IsRunning());
474 sync_thread_.message_loop()->PostTask(FROM_HERE, 395 sync_thread_.message_loop()->PostTask(FROM_HERE,
475 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), 396 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(),
476 credentials)); 397 credentials));
477 } 398 }
478 399
479 void SyncBackendHost::UpdateRegisteredInvalidationIds(
480 const syncer::ObjectIdSet& ids) {
481 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
482 DCHECK(sync_thread_.IsRunning());
483 sync_thread_.message_loop()->PostTask(FROM_HERE,
484 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds,
485 core_.get(), ids));
486 }
487
488 void SyncBackendHost::AcknowledgeInvalidation(
489 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) {
490 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
491 DCHECK(sync_thread_.IsRunning());
492 sync_thread_.message_loop()->PostTask(FROM_HERE,
493 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation,
494 core_.get(), id, ack_handle));
495 }
496
497 void SyncBackendHost::StartSyncingWithServer() { 400 void SyncBackendHost::StartSyncingWithServer() {
498 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; 401 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
499 402
500 syncer::ModelSafeRoutingInfo routing_info; 403 syncer::ModelSafeRoutingInfo routing_info;
501 registrar_->GetModelSafeRoutingInfo(&routing_info); 404 registrar_->GetModelSafeRoutingInfo(&routing_info);
502 405
503 sync_thread_.message_loop()->PostTask(FROM_HERE, 406 sync_thread_.message_loop()->PostTask(FROM_HERE,
504 base::Bind(&SyncBackendHost::Core::DoStartSyncing, 407 base::Bind(&SyncBackendHost::Core::DoStartSyncing,
505 core_.get(), routing_info)); 408 core_.get(), routing_info));
506 } 409 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // so the registrar won't need stopping either. 533 // so the registrar won't need stopping either.
631 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED); 534 DCHECK_EQ(initialization_state_, NOT_ATTEMPTED);
632 DCHECK(!registrar_.get()); 535 DCHECK(!registrar_.get());
633 } 536 }
634 } 537 }
635 538
636 void SyncBackendHost::Shutdown(bool sync_disabled) { 539 void SyncBackendHost::Shutdown(bool sync_disabled) {
637 // StopSyncingForShutdown() (which nulls out |frontend_|) should be 540 // StopSyncingForShutdown() (which nulls out |frontend_|) should be
638 // called first. 541 // called first.
639 DCHECK(!frontend_); 542 DCHECK(!frontend_);
543
544 if (sync_disabled)
545 invalidator_->UpdateRegisteredInvalidationIds(this, syncer::ObjectIdSet());
546 invalidator_->UnregisterInvalidationHandler(this);
547 invalidator_ = NULL;
548
640 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. 549 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice.
641 if (sync_thread_.IsRunning()) { 550 if (sync_thread_.IsRunning()) {
642 sync_thread_.message_loop()->PostTask(FROM_HERE, 551 sync_thread_.message_loop()->PostTask(FROM_HERE,
643 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), 552 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(),
644 sync_disabled)); 553 sync_disabled));
645
646 if (android_invalidator_bridge_)
647 android_invalidator_bridge_->StopForShutdown();
648 } 554 }
649 555
650 // Stop will return once the thread exits, which will be after DoShutdown 556 // Stop will return once the thread exits, which will be after DoShutdown
651 // runs. DoShutdown needs to run from sync_thread_ because the sync backend 557 // runs. DoShutdown needs to run from sync_thread_ because the sync backend
652 // requires any thread that opened sqlite handles to relinquish them 558 // requires any thread that opened sqlite handles to relinquish them
653 // personally. We need to join threads, because otherwise the main Chrome 559 // personally. We need to join threads, because otherwise the main Chrome
654 // thread (ui loop) can exit before DoShutdown finishes, at which point 560 // thread (ui loop) can exit before DoShutdown finishes, at which point
655 // virtually anything the sync backend does (or the post-back to 561 // virtually anything the sync backend does (or the post-back to
656 // frontend_loop_ by our Core) will epically fail because the CRT won't be 562 // frontend_loop_ by our Core) will epically fail because the CRT won't be
657 // initialized. 563 // initialized.
658 // Since we are blocking the UI thread here, we need to turn ourselves in 564 // Since we are blocking the UI thread here, we need to turn ourselves in
659 // with the ThreadRestriction police. For sentencing and how we plan to fix 565 // with the ThreadRestriction police. For sentencing and how we plan to fix
660 // this, see bug 19757. 566 // this, see bug 19757.
661 base::Time stop_thread_start_time = base::Time::Now(); 567 base::Time stop_thread_start_time = base::Time::Now();
662 { 568 {
663 base::ThreadRestrictions::ScopedAllowIO allow_io; 569 base::ThreadRestrictions::ScopedAllowIO allow_io;
664 sync_thread_.Stop(); 570 sync_thread_.Stop();
665 } 571 }
666 base::TimeDelta stop_sync_thread_time = base::Time::Now() - 572 base::TimeDelta stop_sync_thread_time = base::Time::Now() -
667 stop_thread_start_time; 573 stop_thread_start_time;
668 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", 574 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime",
669 stop_sync_thread_time); 575 stop_sync_thread_time);
670 576
671 registrar_.reset(); 577 registrar_.reset();
672 js_backend_.Reset(); 578 js_backend_.Reset();
673 android_invalidator_bridge_.reset();
674 core_ = NULL; // Releases reference to core_. 579 core_ = NULL; // Releases reference to core_.
675 } 580 }
676 581
677 void SyncBackendHost::ConfigureDataTypes( 582 void SyncBackendHost::ConfigureDataTypes(
678 syncer::ConfigureReason reason, 583 syncer::ConfigureReason reason,
679 const DataTypeConfigStateMap& config_state_map, 584 const DataTypeConfigStateMap& config_state_map,
680 const base::Callback<void(syncer::ModelTypeSet, 585 const base::Callback<void(syncer::ModelTypeSet,
681 syncer::ModelTypeSet)>& ready_task, 586 syncer::ModelTypeSet)>& ready_task,
682 const base::Callback<void()>& retry_callback) { 587 const base::Callback<void()>& retry_callback) {
683 // Only one configure is allowed at a time. This is guaranteed by our 588 // Only one configure is allowed at a time. This is guaranteed by our
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 core_.get(), 740 core_.get(),
836 reason, 741 reason,
837 types_to_config, 742 types_to_config,
838 failed_types, 743 failed_types,
839 routing_info, 744 routing_info,
840 ready_task, 745 ready_task,
841 retry_callback)); 746 retry_callback));
842 } 747 }
843 748
844 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( 749 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
750 const syncer::ModelTypeSet enabled_types,
845 const syncer::ModelTypeSet succeeded_configuration_types, 751 const syncer::ModelTypeSet succeeded_configuration_types,
846 const syncer::ModelTypeSet failed_configuration_types, 752 const syncer::ModelTypeSet failed_configuration_types,
847 const base::Callback<void(syncer::ModelTypeSet, 753 const base::Callback<void(syncer::ModelTypeSet,
848 syncer::ModelTypeSet)>& ready_task) { 754 syncer::ModelTypeSet)>& ready_task) {
849 if (!frontend_) 755 if (!frontend_)
850 return; 756 return;
851 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 757
758 invalidator_->UpdateRegisteredInvalidationIds(
759 this,
760 ModelTypeSetToObjectIdSet(enabled_types));
761
852 if (!ready_task.is_null()) 762 if (!ready_task.is_null())
853 ready_task.Run(succeeded_configuration_types, failed_configuration_types); 763 ready_task.Run(succeeded_configuration_types, failed_configuration_types);
854 } 764 }
855 765
856 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( 766 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
857 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 767 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
858 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 768 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
859 debug_info_listener, 769 debug_info_listener,
860 syncer::ModelTypeSet restored_types) { 770 syncer::ModelTypeSet restored_types) {
861 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); 771 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER);
(...skipping 10 matching lines...) Expand all
872 782
873 // Start forwarding refresh requests to the SyncManager 783 // Start forwarding refresh requests to the SyncManager
874 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 784 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
875 content::Source<Profile>(profile_)); 785 content::Source<Profile>(profile_));
876 786
877 syncer::ConfigureReason reason = 787 syncer::ConfigureReason reason =
878 (sync_prefs_->HasSyncSetupCompleted() ? 788 (sync_prefs_->HasSyncSetupCompleted() ?
879 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : 789 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE :
880 syncer::CONFIGURE_REASON_NEW_CLIENT); 790 syncer::CONFIGURE_REASON_NEW_CLIENT);
881 791
792 // Fake a state change to initialize the SyncManager's cached invalidator
793 // state.
794 OnInvalidatorStateChange(invalidator_->GetInvalidatorState());
795
882 // Kick off the next step in SyncBackendHost initialization by downloading 796 // Kick off the next step in SyncBackendHost initialization by downloading
883 // any necessary control types. 797 // any necessary control types.
884 sync_thread_.message_loop()->PostTask( 798 sync_thread_.message_loop()->PostTask(
885 FROM_HERE, 799 FROM_HERE,
886 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, 800 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes,
887 core_.get(), 801 core_.get(),
888 reason)); 802 reason));
889 } 803 }
890 804
891 void SyncBackendHost::Observe( 805 void SyncBackendHost::Observe(
(...skipping 16 matching lines...) Expand all
908 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 822 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
909 MessageLoop* sync_loop, 823 MessageLoop* sync_loop,
910 SyncBackendRegistrar* registrar, 824 SyncBackendRegistrar* registrar,
911 const syncer::ModelSafeRoutingInfo& routing_info, 825 const syncer::ModelSafeRoutingInfo& routing_info,
912 const std::vector<syncer::ModelSafeWorker*>& workers, 826 const std::vector<syncer::ModelSafeWorker*>& workers,
913 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 827 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
914 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 828 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
915 const GURL& service_url, 829 const GURL& service_url,
916 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 830 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
917 const syncer::SyncCredentials& credentials, 831 const syncer::SyncCredentials& credentials,
918 AndroidInvalidatorBridge* android_invalidator_bridge, 832 const std::string& invalidator_client_id,
919 syncer::InvalidatorFactory* invalidator_factory,
920 syncer::SyncManagerFactory* sync_manager_factory, 833 syncer::SyncManagerFactory* sync_manager_factory,
921 bool delete_sync_data_folder, 834 bool delete_sync_data_folder,
922 const std::string& restored_key_for_bootstrapping, 835 const std::string& restored_key_for_bootstrapping,
923 const std::string& restored_keystore_key_for_bootstrapping, 836 const std::string& restored_keystore_key_for_bootstrapping,
924 InternalComponentsFactory* internal_components_factory, 837 InternalComponentsFactory* internal_components_factory,
925 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 838 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
926 syncer::ReportUnrecoverableErrorFunction 839 syncer::ReportUnrecoverableErrorFunction
927 report_unrecoverable_error_function) 840 report_unrecoverable_error_function)
928 : sync_loop(sync_loop), 841 : sync_loop(sync_loop),
929 registrar(registrar), 842 registrar(registrar),
930 routing_info(routing_info), 843 routing_info(routing_info),
931 workers(workers), 844 workers(workers),
932 extensions_activity_monitor(extensions_activity_monitor), 845 extensions_activity_monitor(extensions_activity_monitor),
933 event_handler(event_handler), 846 event_handler(event_handler),
934 service_url(service_url), 847 service_url(service_url),
935 make_http_bridge_factory_fn(make_http_bridge_factory_fn), 848 make_http_bridge_factory_fn(make_http_bridge_factory_fn),
936 credentials(credentials), 849 credentials(credentials),
937 android_invalidator_bridge(android_invalidator_bridge), 850 invalidator_client_id(invalidator_client_id),
938 invalidator_factory(invalidator_factory),
939 sync_manager_factory(sync_manager_factory), 851 sync_manager_factory(sync_manager_factory),
940 delete_sync_data_folder(delete_sync_data_folder), 852 delete_sync_data_folder(delete_sync_data_folder),
941 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 853 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
942 restored_keystore_key_for_bootstrapping( 854 restored_keystore_key_for_bootstrapping(
943 restored_keystore_key_for_bootstrapping), 855 restored_keystore_key_for_bootstrapping),
944 internal_components_factory(internal_components_factory), 856 internal_components_factory(internal_components_factory),
945 unrecoverable_error_handler(unrecoverable_error_handler), 857 unrecoverable_error_handler(unrecoverable_error_handler),
946 report_unrecoverable_error_function( 858 report_unrecoverable_error_function(
947 report_unrecoverable_error_function) { 859 report_unrecoverable_error_function) {
948 } 860 }
949 861
950 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} 862 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {}
951 863
952 SyncBackendHost::Core::Core(const std::string& name, 864 SyncBackendHost::Core::Core(const std::string& name,
953 const base::FilePath& sync_data_folder_path, 865 const base::FilePath& sync_data_folder_path,
954 const base::WeakPtr<SyncBackendHost>& backend) 866 const base::WeakPtr<SyncBackendHost>& backend)
955 : name_(name), 867 : name_(name),
956 sync_data_folder_path_(sync_data_folder_path), 868 sync_data_folder_path_(sync_data_folder_path),
957 host_(backend), 869 host_(backend),
958 sync_loop_(NULL), 870 sync_loop_(NULL),
959 registrar_(NULL), 871 registrar_(NULL) {
960 registered_as_invalidation_handler_(false) {
961 DCHECK(backend.get()); 872 DCHECK(backend.get());
962 } 873 }
963 874
964 SyncBackendHost::Core::~Core() { 875 SyncBackendHost::Core::~Core() {
965 DCHECK(!sync_manager_.get()); 876 DCHECK(!sync_manager_.get());
966 DCHECK(!sync_loop_); 877 DCHECK(!sync_loop_);
967 } 878 }
968 879
969 void SyncBackendHost::Core::OnSyncCycleCompleted( 880 void SyncBackendHost::Core::OnSyncCycleCompleted(
970 const SyncSessionSnapshot& snapshot) { 881 const SyncSessionSnapshot& snapshot) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 const syncer::SyncProtocolError& sync_error) { 1054 const syncer::SyncProtocolError& sync_error) {
1144 if (!sync_loop_) 1055 if (!sync_loop_)
1145 return; 1056 return;
1146 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1057 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1147 host_.Call( 1058 host_.Call(
1148 FROM_HERE, 1059 FROM_HERE,
1149 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1060 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1150 sync_error); 1061 sync_error);
1151 } 1062 }
1152 1063
1153 void SyncBackendHost::Core::OnInvalidatorStateChange( 1064 void SyncBackendHost::Core::DoOnInvalidatorStateChange(
1154 syncer::InvalidatorState state) { 1065 syncer::InvalidatorState state) {
1155 if (!sync_loop_)
1156 return;
1157 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1066 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1158 host_.Call(FROM_HERE, 1067 sync_manager_->OnInvalidatorStateChange(state);
1159 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop,
1160 state);
1161 } 1068 }
1162 1069
1163 void SyncBackendHost::Core::OnIncomingInvalidation( 1070 void SyncBackendHost::Core::DoOnIncomingInvalidation(
1164 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1071 syncer::ObjectIdInvalidationMap invalidation_map) {
1165 if (!sync_loop_)
1166 return;
1167 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1072 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1168 host_.Call(FROM_HERE, 1073 sync_manager_->OnIncomingInvalidation(invalidation_map);
1169 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop,
1170 invalidation_map);
1171 } 1074 }
1172 1075
1173 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 1076 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
1174 DCHECK(!sync_loop_); 1077 DCHECK(!sync_loop_);
1175 sync_loop_ = options.sync_loop; 1078 sync_loop_ = options.sync_loop;
1176 DCHECK(sync_loop_); 1079 DCHECK(sync_loop_);
1177 1080
1178 // Blow away the partial or corrupt sync data folder before doing any more 1081 // Blow away the partial or corrupt sync data folder before doing any more
1179 // initialization, if necessary. 1082 // initialization, if necessary.
1180 if (options.delete_sync_data_folder) { 1083 if (options.delete_sync_data_folder) {
(...skipping 16 matching lines...) Expand all
1197 sync_data_folder_path_, 1100 sync_data_folder_path_,
1198 options.event_handler, 1101 options.event_handler,
1199 options.service_url.host() + options.service_url.path(), 1102 options.service_url.host() + options.service_url.path(),
1200 options.service_url.EffectiveIntPort(), 1103 options.service_url.EffectiveIntPort(),
1201 options.service_url.SchemeIsSecure(), 1104 options.service_url.SchemeIsSecure(),
1202 options.make_http_bridge_factory_fn.Run().Pass(), 1105 options.make_http_bridge_factory_fn.Run().Pass(),
1203 options.workers, 1106 options.workers,
1204 options.extensions_activity_monitor, 1107 options.extensions_activity_monitor,
1205 options.registrar /* as SyncManager::ChangeDelegate */, 1108 options.registrar /* as SyncManager::ChangeDelegate */,
1206 options.credentials, 1109 options.credentials,
1207 #if defined(OS_ANDROID) 1110 options.invalidator_client_id,
1208 scoped_ptr<syncer::Invalidator>(
1209 new AndroidInvalidatorBridgeProxy(
1210 options.android_invalidator_bridge)),
1211 #else
1212 scoped_ptr<syncer::Invalidator>(
1213 options.invalidator_factory->CreateInvalidator()),
1214 #endif
1215 options.invalidator_factory->GetInvalidatorClientId(),
1216 options.restored_key_for_bootstrapping, 1111 options.restored_key_for_bootstrapping,
1217 options.restored_keystore_key_for_bootstrapping, 1112 options.restored_keystore_key_for_bootstrapping,
1218 scoped_ptr<InternalComponentsFactory>( 1113 scoped_ptr<InternalComponentsFactory>(
1219 options.internal_components_factory), 1114 options.internal_components_factory),
1220 &encryptor_, 1115 &encryptor_,
1221 options.unrecoverable_error_handler, 1116 options.unrecoverable_error_handler,
1222 options.report_unrecoverable_error_function); 1117 options.report_unrecoverable_error_function);
1223 1118
1224 // |sync_manager_| may end up being NULL here in tests (in 1119 // |sync_manager_| may end up being NULL here in tests (in
1225 // synchronous initialization mode). 1120 // synchronous initialization mode).
1226 // 1121 //
1227 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1122 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1228 if (sync_manager_) { 1123 if (sync_manager_) {
1229 sync_manager_->RegisterInvalidationHandler(this);
1230 registered_as_invalidation_handler_ = true;
1231
1232 // Now check the command line to see if we need to simulate an 1124 // Now check the command line to see if we need to simulate an
1233 // unrecoverable error for testing purpose. Note the error is thrown 1125 // unrecoverable error for testing purpose. Note the error is thrown
1234 // only if the initialization succeeded. Also it makes sense to use this 1126 // only if the initialization succeeded. Also it makes sense to use this
1235 // flag only when restarting the browser with an account already setup. If 1127 // flag only when restarting the browser with an account already setup. If
1236 // you use this before setting up the setup would not succeed as an error 1128 // you use this before setting up the setup would not succeed as an error
1237 // would be encountered. 1129 // would be encountered.
1238 if (CommandLine::ForCurrentProcess()->HasSwitch( 1130 if (CommandLine::ForCurrentProcess()->HasSwitch(
1239 switches::kSyncThrowUnrecoverableError)) { 1131 switches::kSyncThrowUnrecoverableError)) {
1240 sync_manager_->ThrowUnrecoverableError(); 1132 sync_manager_->ThrowUnrecoverableError();
1241 } 1133 }
1242 } 1134 }
1243 } 1135 }
1244 1136
1245 void SyncBackendHost::Core::DoUpdateCredentials( 1137 void SyncBackendHost::Core::DoUpdateCredentials(
1246 const SyncCredentials& credentials) { 1138 const SyncCredentials& credentials) {
1247 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1139 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1248 // UpdateCredentials can be called during backend initialization, possibly 1140 // UpdateCredentials can be called during backend initialization, possibly
1249 // when backend initialization has failed but hasn't notified the UI thread 1141 // when backend initialization has failed but hasn't notified the UI thread
1250 // yet. In that case, the sync manager may have been destroyed on the sync 1142 // yet. In that case, the sync manager may have been destroyed on the sync
1251 // thread before this task was executed, so we do nothing. 1143 // thread before this task was executed, so we do nothing.
1252 if (sync_manager_) { 1144 if (sync_manager_) {
1253 sync_manager_->UpdateCredentials(credentials); 1145 sync_manager_->UpdateCredentials(credentials);
1254 } 1146 }
1255 } 1147 }
1256 1148
1257 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds(
1258 const syncer::ObjectIdSet& ids) {
1259 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1260 // |sync_manager_| may end up being NULL here in tests (in
1261 // synchronous initialization mode) since this is called during
1262 // shutdown.
1263 //
1264 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1265 if (sync_manager_) {
1266 sync_manager_->UpdateRegisteredInvalidationIds(this, ids);
1267 }
1268 }
1269
1270 void SyncBackendHost::Core::DoAcknowledgeInvalidation(
1271 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) {
1272 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1273 // |sync_manager_| may end up being NULL here in tests (in
1274 // synchronous initialization mode).
1275 //
1276 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1277 if (sync_manager_) {
1278 sync_manager_->AcknowledgeInvalidation(id, ack_handle);
1279 }
1280 }
1281
1282 void SyncBackendHost::Core::DoStartSyncing( 1149 void SyncBackendHost::Core::DoStartSyncing(
1283 const syncer::ModelSafeRoutingInfo& routing_info) { 1150 const syncer::ModelSafeRoutingInfo& routing_info) {
1284 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1151 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1285 sync_manager_->StartSyncingNormally(routing_info); 1152 sync_manager_->StartSyncingNormally(routing_info);
1286 } 1153 }
1287 1154
1288 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1155 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1289 const std::string& passphrase, 1156 const std::string& passphrase,
1290 bool is_explicit) { 1157 bool is_explicit) {
1291 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1158 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1248
1382 sync_loop_ = NULL; 1249 sync_loop_ = NULL;
1383 1250
1384 host_.Reset(); 1251 host_.Reset();
1385 } 1252 }
1386 1253
1387 void SyncBackendHost::Core::DoDestroySyncManager() { 1254 void SyncBackendHost::Core::DoDestroySyncManager() {
1388 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1255 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1389 if (sync_manager_) { 1256 if (sync_manager_) {
1390 save_changes_timer_.reset(); 1257 save_changes_timer_.reset();
1391 if (registered_as_invalidation_handler_) {
1392 sync_manager_->UnregisterInvalidationHandler(this);
1393 registered_as_invalidation_handler_ = false;
1394 }
1395 sync_manager_->RemoveObserver(this); 1258 sync_manager_->RemoveObserver(this);
1396 sync_manager_->ShutdownOnSyncThread(); 1259 sync_manager_->ShutdownOnSyncThread();
1397 sync_manager_.reset(); 1260 sync_manager_.reset();
1398 } 1261 }
1399 } 1262 }
1400 1263
1401 void SyncBackendHost::Core::DoConfigureSyncer( 1264 void SyncBackendHost::Core::DoConfigureSyncer(
1402 syncer::ConfigureReason reason, 1265 syncer::ConfigureReason reason,
1403 syncer::ModelTypeSet types_to_config, 1266 syncer::ModelTypeSet types_to_config,
1404 syncer::ModelTypeSet failed_types, 1267 syncer::ModelTypeSet failed_types,
(...skipping 20 matching lines...) Expand all
1425 syncer::ModelTypeSet types_to_config, 1288 syncer::ModelTypeSet types_to_config,
1426 const base::Callback<void(syncer::ModelTypeSet, 1289 const base::Callback<void(syncer::ModelTypeSet,
1427 syncer::ModelTypeSet)>& ready_task) { 1290 syncer::ModelTypeSet)>& ready_task) {
1428 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1291 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1429 1292
1430 // Update the enabled types for the bridge and sync manager. 1293 // Update the enabled types for the bridge and sync manager.
1431 syncer::ModelSafeRoutingInfo routing_info; 1294 syncer::ModelSafeRoutingInfo routing_info;
1432 registrar_->GetModelSafeRoutingInfo(&routing_info); 1295 registrar_->GetModelSafeRoutingInfo(&routing_info);
1433 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 1296 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
1434 enabled_types.RemoveAll(syncer::ProxyTypes()); 1297 enabled_types.RemoveAll(syncer::ProxyTypes());
1435 sync_manager_->UpdateEnabledTypes(enabled_types);
1436 1298
1437 const syncer::ModelTypeSet failed_configuration_types = 1299 const syncer::ModelTypeSet failed_configuration_types =
1438 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); 1300 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes());
1439 const syncer::ModelTypeSet succeeded_configuration_types = 1301 const syncer::ModelTypeSet succeeded_configuration_types =
1440 Difference(types_to_config, failed_configuration_types); 1302 Difference(types_to_config, failed_configuration_types);
1441 host_.Call(FROM_HERE, 1303 host_.Call(FROM_HERE,
1442 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, 1304 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1443 succeeded_configuration_types, failed_configuration_types, 1305 enabled_types,
1306 succeeded_configuration_types,
1307 failed_configuration_types,
1444 ready_task); 1308 ready_task);
1445 } 1309 }
1446 1310
1447 void SyncBackendHost::Core::DoRetryConfiguration( 1311 void SyncBackendHost::Core::DoRetryConfiguration(
1448 const base::Closure& retry_callback) { 1312 const base::Closure& retry_callback) {
1449 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1313 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1450 host_.Call(FROM_HERE, 1314 host_.Call(FROM_HERE,
1451 &SyncBackendHost::RetryConfigurationOnFrontendLoop, 1315 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1452 retry_callback); 1316 retry_callback);
1453 } 1317 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 } 1427 }
1564 1428
1565 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1429 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1566 const syncer::SyncProtocolError& sync_error) { 1430 const syncer::SyncProtocolError& sync_error) {
1567 if (!frontend_) 1431 if (!frontend_)
1568 return; 1432 return;
1569 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1433 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1570 frontend_->OnActionableError(sync_error); 1434 frontend_->OnActionableError(sync_error);
1571 } 1435 }
1572 1436
1573 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( 1437 void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) {
1574 syncer::InvalidatorState state) { 1438 sync_thread_.message_loop()->PostTask(
1575 if (!frontend_) 1439 FROM_HERE,
1576 return; 1440 base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange,
1577 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1441 core_.get(),
1578 frontend_->OnInvalidatorStateChange(state); 1442 state));
1579 } 1443 }
1580 1444
1581 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( 1445 void SyncBackendHost::OnIncomingInvalidation(
1582 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1446 const syncer::ObjectIdInvalidationMap& invalidation_map) {
1583 if (!frontend_) 1447 // TODO(dcheng): Acknowledge immediately for now. Fix this once the
akalin 2013/05/24 22:58:46 ah, here it is.
1584 return; 1448 // invalidator doesn't repeatedly ping for unacknowledged invaliations, since
1585 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1449 // it conflicts with the sync scheduler's internal backoff algorithm.
1586 frontend_->OnIncomingInvalidation(invalidation_map); 1450 // See http://crbug.com/124149 for more information.
1451 for (syncer::ObjectIdInvalidationMap::const_iterator it =
1452 invalidation_map.begin(); it != invalidation_map.end(); ++it) {
1453 invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle);
1454 }
1455
1456 sync_thread_.message_loop()->PostTask(
1457 FROM_HERE,
1458 base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation,
1459 core_.get(),
1460 invalidation_map));
1587 } 1461 }
1588 1462
1589 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1463 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1590 const std::string& passphrase) const { 1464 const std::string& passphrase) const {
1591 DCHECK(cached_pending_keys_.has_blob()); 1465 DCHECK(cached_pending_keys_.has_blob());
1592 DCHECK(!passphrase.empty()); 1466 DCHECK(!passphrase.empty());
1593 syncer::Nigori nigori; 1467 syncer::Nigori nigori;
1594 nigori.InitByDerivation("localhost", "dummy", passphrase); 1468 nigori.InitByDerivation("localhost", "dummy", passphrase);
1595 std::string plaintext; 1469 std::string plaintext;
1596 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1470 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 DVLOG(1) << "Connection status changed: " 1551 DVLOG(1) << "Connection status changed: "
1678 << syncer::ConnectionStatusToString(status); 1552 << syncer::ConnectionStatusToString(status);
1679 frontend_->OnConnectionStatusChange(status); 1553 frontend_->OnConnectionStatusChange(status);
1680 } 1554 }
1681 1555
1682 #undef SDVLOG 1556 #undef SDVLOG
1683 1557
1684 #undef SLOG 1558 #undef SLOG
1685 1559
1686 } // namespace browser_sync 1560 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698