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

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: 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 invalidator_->UnregisterInvalidationHandler(this);
545 invalidator_ = NULL;
546
640 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. 547 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice.
641 if (sync_thread_.IsRunning()) { 548 if (sync_thread_.IsRunning()) {
642 sync_thread_.message_loop()->PostTask(FROM_HERE, 549 sync_thread_.message_loop()->PostTask(FROM_HERE,
643 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), 550 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(),
644 sync_disabled)); 551 sync_disabled));
645
646 if (android_invalidator_bridge_)
647 android_invalidator_bridge_->StopForShutdown();
648 } 552 }
649 553
650 // Stop will return once the thread exits, which will be after DoShutdown 554 // 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 555 // runs. DoShutdown needs to run from sync_thread_ because the sync backend
652 // requires any thread that opened sqlite handles to relinquish them 556 // requires any thread that opened sqlite handles to relinquish them
653 // personally. We need to join threads, because otherwise the main Chrome 557 // personally. We need to join threads, because otherwise the main Chrome
654 // thread (ui loop) can exit before DoShutdown finishes, at which point 558 // thread (ui loop) can exit before DoShutdown finishes, at which point
655 // virtually anything the sync backend does (or the post-back to 559 // 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 560 // frontend_loop_ by our Core) will epically fail because the CRT won't be
657 // initialized. 561 // initialized.
658 // Since we are blocking the UI thread here, we need to turn ourselves in 562 // 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 563 // with the ThreadRestriction police. For sentencing and how we plan to fix
660 // this, see bug 19757. 564 // this, see bug 19757.
661 base::Time stop_thread_start_time = base::Time::Now(); 565 base::Time stop_thread_start_time = base::Time::Now();
662 { 566 {
663 base::ThreadRestrictions::ScopedAllowIO allow_io; 567 base::ThreadRestrictions::ScopedAllowIO allow_io;
664 sync_thread_.Stop(); 568 sync_thread_.Stop();
665 } 569 }
666 base::TimeDelta stop_sync_thread_time = base::Time::Now() - 570 base::TimeDelta stop_sync_thread_time = base::Time::Now() -
667 stop_thread_start_time; 571 stop_thread_start_time;
668 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", 572 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime",
669 stop_sync_thread_time); 573 stop_sync_thread_time);
670 574
671 registrar_.reset(); 575 registrar_.reset();
672 js_backend_.Reset(); 576 js_backend_.Reset();
673 android_invalidator_bridge_.reset();
674 core_ = NULL; // Releases reference to core_. 577 core_ = NULL; // Releases reference to core_.
675 } 578 }
676 579
677 void SyncBackendHost::ConfigureDataTypes( 580 void SyncBackendHost::ConfigureDataTypes(
678 syncer::ConfigureReason reason, 581 syncer::ConfigureReason reason,
679 const DataTypeConfigStateMap& config_state_map, 582 const DataTypeConfigStateMap& config_state_map,
680 const base::Callback<void(syncer::ModelTypeSet, 583 const base::Callback<void(syncer::ModelTypeSet,
681 syncer::ModelTypeSet)>& ready_task, 584 syncer::ModelTypeSet)>& ready_task,
682 const base::Callback<void()>& retry_callback) { 585 const base::Callback<void()>& retry_callback) {
683 // Only one configure is allowed at a time. This is guaranteed by our 586 // 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(), 738 core_.get(),
836 reason, 739 reason,
837 types_to_config, 740 types_to_config,
838 failed_types, 741 failed_types,
839 routing_info, 742 routing_info,
840 ready_task, 743 ready_task,
841 retry_callback)); 744 retry_callback));
842 } 745 }
843 746
844 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( 747 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
748 const syncer::ModelTypeSet enabled_types,
845 const syncer::ModelTypeSet succeeded_configuration_types, 749 const syncer::ModelTypeSet succeeded_configuration_types,
846 const syncer::ModelTypeSet failed_configuration_types, 750 const syncer::ModelTypeSet failed_configuration_types,
847 const base::Callback<void(syncer::ModelTypeSet, 751 const base::Callback<void(syncer::ModelTypeSet,
848 syncer::ModelTypeSet)>& ready_task) { 752 syncer::ModelTypeSet)>& ready_task) {
849 if (!frontend_) 753 if (!frontend_)
850 return; 754 return;
851 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 755
756 invalidator_->UpdateRegisteredInvalidationIds(
757 this,
758 ModelTypeSetToObjectIdSet(enabled_types));
759
852 if (!ready_task.is_null()) 760 if (!ready_task.is_null())
853 ready_task.Run(succeeded_configuration_types, failed_configuration_types); 761 ready_task.Run(succeeded_configuration_types, failed_configuration_types);
854 } 762 }
855 763
856 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( 764 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
857 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 765 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
858 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 766 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
859 debug_info_listener, 767 debug_info_listener,
860 syncer::ModelTypeSet restored_types) { 768 syncer::ModelTypeSet restored_types) {
861 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); 769 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER);
(...skipping 10 matching lines...) Expand all
872 780
873 // Start forwarding refresh requests to the SyncManager 781 // Start forwarding refresh requests to the SyncManager
874 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 782 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
875 content::Source<Profile>(profile_)); 783 content::Source<Profile>(profile_));
876 784
877 syncer::ConfigureReason reason = 785 syncer::ConfigureReason reason =
878 (sync_prefs_->HasSyncSetupCompleted() ? 786 (sync_prefs_->HasSyncSetupCompleted() ?
879 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : 787 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE :
880 syncer::CONFIGURE_REASON_NEW_CLIENT); 788 syncer::CONFIGURE_REASON_NEW_CLIENT);
881 789
790 // Fake a state change to initialize the SyncManager's cached invalidator
791 // state.
792 OnInvalidatorStateChange(invalidator_->GetInvalidatorState());
793
882 // Kick off the next step in SyncBackendHost initialization by downloading 794 // Kick off the next step in SyncBackendHost initialization by downloading
883 // any necessary control types. 795 // any necessary control types.
884 sync_thread_.message_loop()->PostTask( 796 sync_thread_.message_loop()->PostTask(
885 FROM_HERE, 797 FROM_HERE,
886 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, 798 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes,
887 core_.get(), 799 core_.get(),
888 reason)); 800 reason));
889 } 801 }
890 802
891 void SyncBackendHost::Observe( 803 void SyncBackendHost::Observe(
(...skipping 16 matching lines...) Expand all
908 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 820 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
909 MessageLoop* sync_loop, 821 MessageLoop* sync_loop,
910 SyncBackendRegistrar* registrar, 822 SyncBackendRegistrar* registrar,
911 const syncer::ModelSafeRoutingInfo& routing_info, 823 const syncer::ModelSafeRoutingInfo& routing_info,
912 const std::vector<syncer::ModelSafeWorker*>& workers, 824 const std::vector<syncer::ModelSafeWorker*>& workers,
913 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 825 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
914 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 826 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
915 const GURL& service_url, 827 const GURL& service_url,
916 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 828 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
917 const syncer::SyncCredentials& credentials, 829 const syncer::SyncCredentials& credentials,
918 AndroidInvalidatorBridge* android_invalidator_bridge, 830 const std::string& invalidator_client_id,
919 syncer::InvalidatorFactory* invalidator_factory,
920 syncer::SyncManagerFactory* sync_manager_factory, 831 syncer::SyncManagerFactory* sync_manager_factory,
921 bool delete_sync_data_folder, 832 bool delete_sync_data_folder,
922 const std::string& restored_key_for_bootstrapping, 833 const std::string& restored_key_for_bootstrapping,
923 const std::string& restored_keystore_key_for_bootstrapping, 834 const std::string& restored_keystore_key_for_bootstrapping,
924 InternalComponentsFactory* internal_components_factory, 835 InternalComponentsFactory* internal_components_factory,
925 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 836 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
926 syncer::ReportUnrecoverableErrorFunction 837 syncer::ReportUnrecoverableErrorFunction
927 report_unrecoverable_error_function) 838 report_unrecoverable_error_function)
928 : sync_loop(sync_loop), 839 : sync_loop(sync_loop),
929 registrar(registrar), 840 registrar(registrar),
930 routing_info(routing_info), 841 routing_info(routing_info),
931 workers(workers), 842 workers(workers),
932 extensions_activity_monitor(extensions_activity_monitor), 843 extensions_activity_monitor(extensions_activity_monitor),
933 event_handler(event_handler), 844 event_handler(event_handler),
934 service_url(service_url), 845 service_url(service_url),
935 make_http_bridge_factory_fn(make_http_bridge_factory_fn), 846 make_http_bridge_factory_fn(make_http_bridge_factory_fn),
936 credentials(credentials), 847 credentials(credentials),
937 android_invalidator_bridge(android_invalidator_bridge), 848 invalidator_client_id(invalidator_client_id),
938 invalidator_factory(invalidator_factory),
939 sync_manager_factory(sync_manager_factory), 849 sync_manager_factory(sync_manager_factory),
940 delete_sync_data_folder(delete_sync_data_folder), 850 delete_sync_data_folder(delete_sync_data_folder),
941 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 851 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
942 restored_keystore_key_for_bootstrapping( 852 restored_keystore_key_for_bootstrapping(
943 restored_keystore_key_for_bootstrapping), 853 restored_keystore_key_for_bootstrapping),
944 internal_components_factory(internal_components_factory), 854 internal_components_factory(internal_components_factory),
945 unrecoverable_error_handler(unrecoverable_error_handler), 855 unrecoverable_error_handler(unrecoverable_error_handler),
946 report_unrecoverable_error_function( 856 report_unrecoverable_error_function(
947 report_unrecoverable_error_function) { 857 report_unrecoverable_error_function) {
948 } 858 }
949 859
950 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} 860 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {}
951 861
952 SyncBackendHost::Core::Core(const std::string& name, 862 SyncBackendHost::Core::Core(const std::string& name,
953 const base::FilePath& sync_data_folder_path, 863 const base::FilePath& sync_data_folder_path,
954 const base::WeakPtr<SyncBackendHost>& backend) 864 const base::WeakPtr<SyncBackendHost>& backend)
955 : name_(name), 865 : name_(name),
956 sync_data_folder_path_(sync_data_folder_path), 866 sync_data_folder_path_(sync_data_folder_path),
957 host_(backend), 867 host_(backend),
958 sync_loop_(NULL), 868 sync_loop_(NULL),
959 registrar_(NULL), 869 registrar_(NULL) {
960 registered_as_invalidation_handler_(false) {
961 DCHECK(backend.get()); 870 DCHECK(backend.get());
962 } 871 }
963 872
964 SyncBackendHost::Core::~Core() { 873 SyncBackendHost::Core::~Core() {
965 DCHECK(!sync_manager_.get()); 874 DCHECK(!sync_manager_.get());
966 DCHECK(!sync_loop_); 875 DCHECK(!sync_loop_);
967 } 876 }
968 877
969 void SyncBackendHost::Core::OnSyncCycleCompleted( 878 void SyncBackendHost::Core::OnSyncCycleCompleted(
970 const SyncSessionSnapshot& snapshot) { 879 const SyncSessionSnapshot& snapshot) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 const syncer::SyncProtocolError& sync_error) { 1052 const syncer::SyncProtocolError& sync_error) {
1144 if (!sync_loop_) 1053 if (!sync_loop_)
1145 return; 1054 return;
1146 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1055 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1147 host_.Call( 1056 host_.Call(
1148 FROM_HERE, 1057 FROM_HERE,
1149 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1058 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1150 sync_error); 1059 sync_error);
1151 } 1060 }
1152 1061
1153 void SyncBackendHost::Core::OnInvalidatorStateChange( 1062 void SyncBackendHost::Core::DoOnInvalidatorStateChange(
1154 syncer::InvalidatorState state) { 1063 syncer::InvalidatorState state) {
1155 if (!sync_loop_)
1156 return;
1157 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1064 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1158 host_.Call(FROM_HERE, 1065 sync_manager_->OnInvalidatorStateChange(state);
1159 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop,
1160 state);
1161 } 1066 }
1162 1067
1163 void SyncBackendHost::Core::OnIncomingInvalidation( 1068 void SyncBackendHost::Core::DoOnIncomingInvalidation(
1164 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1069 syncer::ObjectIdInvalidationMap invalidation_map) {
1165 if (!sync_loop_)
1166 return;
1167 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1070 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1168 host_.Call(FROM_HERE, 1071 sync_manager_->OnIncomingInvalidation(invalidation_map);
1169 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop,
1170 invalidation_map);
1171 } 1072 }
1172 1073
1173 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 1074 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
1174 DCHECK(!sync_loop_); 1075 DCHECK(!sync_loop_);
1175 sync_loop_ = options.sync_loop; 1076 sync_loop_ = options.sync_loop;
1176 DCHECK(sync_loop_); 1077 DCHECK(sync_loop_);
1177 1078
1178 // Blow away the partial or corrupt sync data folder before doing any more 1079 // Blow away the partial or corrupt sync data folder before doing any more
1179 // initialization, if necessary. 1080 // initialization, if necessary.
1180 if (options.delete_sync_data_folder) { 1081 if (options.delete_sync_data_folder) {
(...skipping 16 matching lines...) Expand all
1197 sync_data_folder_path_, 1098 sync_data_folder_path_,
1198 options.event_handler, 1099 options.event_handler,
1199 options.service_url.host() + options.service_url.path(), 1100 options.service_url.host() + options.service_url.path(),
1200 options.service_url.EffectiveIntPort(), 1101 options.service_url.EffectiveIntPort(),
1201 options.service_url.SchemeIsSecure(), 1102 options.service_url.SchemeIsSecure(),
1202 options.make_http_bridge_factory_fn.Run().Pass(), 1103 options.make_http_bridge_factory_fn.Run().Pass(),
1203 options.workers, 1104 options.workers,
1204 options.extensions_activity_monitor, 1105 options.extensions_activity_monitor,
1205 options.registrar /* as SyncManager::ChangeDelegate */, 1106 options.registrar /* as SyncManager::ChangeDelegate */,
1206 options.credentials, 1107 options.credentials,
1207 #if defined(OS_ANDROID) 1108 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, 1109 options.restored_key_for_bootstrapping,
1217 options.restored_keystore_key_for_bootstrapping, 1110 options.restored_keystore_key_for_bootstrapping,
1218 scoped_ptr<InternalComponentsFactory>( 1111 scoped_ptr<InternalComponentsFactory>(
1219 options.internal_components_factory), 1112 options.internal_components_factory),
1220 &encryptor_, 1113 &encryptor_,
1221 options.unrecoverable_error_handler, 1114 options.unrecoverable_error_handler,
1222 options.report_unrecoverable_error_function); 1115 options.report_unrecoverable_error_function);
1223 1116
1224 // |sync_manager_| may end up being NULL here in tests (in 1117 // |sync_manager_| may end up being NULL here in tests (in
1225 // synchronous initialization mode). 1118 // synchronous initialization mode).
1226 // 1119 //
1227 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1120 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1228 if (sync_manager_) { 1121 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 1122 // Now check the command line to see if we need to simulate an
1233 // unrecoverable error for testing purpose. Note the error is thrown 1123 // unrecoverable error for testing purpose. Note the error is thrown
1234 // only if the initialization succeeded. Also it makes sense to use this 1124 // 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 1125 // 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 1126 // you use this before setting up the setup would not succeed as an error
1237 // would be encountered. 1127 // would be encountered.
1238 if (CommandLine::ForCurrentProcess()->HasSwitch( 1128 if (CommandLine::ForCurrentProcess()->HasSwitch(
1239 switches::kSyncThrowUnrecoverableError)) { 1129 switches::kSyncThrowUnrecoverableError)) {
1240 sync_manager_->ThrowUnrecoverableError(); 1130 sync_manager_->ThrowUnrecoverableError();
1241 } 1131 }
1242 } 1132 }
1243 } 1133 }
1244 1134
1245 void SyncBackendHost::Core::DoUpdateCredentials( 1135 void SyncBackendHost::Core::DoUpdateCredentials(
1246 const SyncCredentials& credentials) { 1136 const SyncCredentials& credentials) {
1247 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1137 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1248 // UpdateCredentials can be called during backend initialization, possibly 1138 // UpdateCredentials can be called during backend initialization, possibly
1249 // when backend initialization has failed but hasn't notified the UI thread 1139 // 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 1140 // 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. 1141 // thread before this task was executed, so we do nothing.
1252 if (sync_manager_) { 1142 if (sync_manager_) {
1253 sync_manager_->UpdateCredentials(credentials); 1143 sync_manager_->UpdateCredentials(credentials);
1254 } 1144 }
1255 } 1145 }
1256 1146
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( 1147 void SyncBackendHost::Core::DoStartSyncing(
1283 const syncer::ModelSafeRoutingInfo& routing_info) { 1148 const syncer::ModelSafeRoutingInfo& routing_info) {
1284 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1149 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1285 sync_manager_->StartSyncingNormally(routing_info); 1150 sync_manager_->StartSyncingNormally(routing_info);
1286 } 1151 }
1287 1152
1288 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1153 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1289 const std::string& passphrase, 1154 const std::string& passphrase,
1290 bool is_explicit) { 1155 bool is_explicit) {
1291 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1156 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1246
1382 sync_loop_ = NULL; 1247 sync_loop_ = NULL;
1383 1248
1384 host_.Reset(); 1249 host_.Reset();
1385 } 1250 }
1386 1251
1387 void SyncBackendHost::Core::DoDestroySyncManager() { 1252 void SyncBackendHost::Core::DoDestroySyncManager() {
1388 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1253 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1389 if (sync_manager_) { 1254 if (sync_manager_) {
1390 save_changes_timer_.reset(); 1255 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); 1256 sync_manager_->RemoveObserver(this);
1396 sync_manager_->ShutdownOnSyncThread(); 1257 sync_manager_->ShutdownOnSyncThread();
1397 sync_manager_.reset(); 1258 sync_manager_.reset();
1398 } 1259 }
1399 } 1260 }
1400 1261
1401 void SyncBackendHost::Core::DoConfigureSyncer( 1262 void SyncBackendHost::Core::DoConfigureSyncer(
1402 syncer::ConfigureReason reason, 1263 syncer::ConfigureReason reason,
1403 syncer::ModelTypeSet types_to_config, 1264 syncer::ModelTypeSet types_to_config,
1404 syncer::ModelTypeSet failed_types, 1265 syncer::ModelTypeSet failed_types,
(...skipping 20 matching lines...) Expand all
1425 syncer::ModelTypeSet types_to_config, 1286 syncer::ModelTypeSet types_to_config,
1426 const base::Callback<void(syncer::ModelTypeSet, 1287 const base::Callback<void(syncer::ModelTypeSet,
1427 syncer::ModelTypeSet)>& ready_task) { 1288 syncer::ModelTypeSet)>& ready_task) {
1428 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1289 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1429 1290
1430 // Update the enabled types for the bridge and sync manager. 1291 // Update the enabled types for the bridge and sync manager.
1431 syncer::ModelSafeRoutingInfo routing_info; 1292 syncer::ModelSafeRoutingInfo routing_info;
1432 registrar_->GetModelSafeRoutingInfo(&routing_info); 1293 registrar_->GetModelSafeRoutingInfo(&routing_info);
1433 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 1294 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
1434 enabled_types.RemoveAll(syncer::ProxyTypes()); 1295 enabled_types.RemoveAll(syncer::ProxyTypes());
1435 sync_manager_->UpdateEnabledTypes(enabled_types);
1436 1296
1437 const syncer::ModelTypeSet failed_configuration_types = 1297 const syncer::ModelTypeSet failed_configuration_types =
1438 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); 1298 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes());
1439 const syncer::ModelTypeSet succeeded_configuration_types = 1299 const syncer::ModelTypeSet succeeded_configuration_types =
1440 Difference(types_to_config, failed_configuration_types); 1300 Difference(types_to_config, failed_configuration_types);
1441 host_.Call(FROM_HERE, 1301 host_.Call(FROM_HERE,
1442 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, 1302 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1443 succeeded_configuration_types, failed_configuration_types, 1303 enabled_types,
1304 succeeded_configuration_types,
1305 failed_configuration_types,
1444 ready_task); 1306 ready_task);
1445 } 1307 }
1446 1308
1447 void SyncBackendHost::Core::DoRetryConfiguration( 1309 void SyncBackendHost::Core::DoRetryConfiguration(
1448 const base::Closure& retry_callback) { 1310 const base::Closure& retry_callback) {
1449 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1311 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1450 host_.Call(FROM_HERE, 1312 host_.Call(FROM_HERE,
1451 &SyncBackendHost::RetryConfigurationOnFrontendLoop, 1313 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1452 retry_callback); 1314 retry_callback);
1453 } 1315 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 } 1425 }
1564 1426
1565 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1427 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1566 const syncer::SyncProtocolError& sync_error) { 1428 const syncer::SyncProtocolError& sync_error) {
1567 if (!frontend_) 1429 if (!frontend_)
1568 return; 1430 return;
1569 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1431 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1570 frontend_->OnActionableError(sync_error); 1432 frontend_->OnActionableError(sync_error);
1571 } 1433 }
1572 1434
1573 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( 1435 void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) {
1574 syncer::InvalidatorState state) { 1436 sync_thread_.message_loop()->PostTask(
1575 if (!frontend_) 1437 FROM_HERE,
1576 return; 1438 base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange,
1577 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1439 core_.get(),
1578 frontend_->OnInvalidatorStateChange(state); 1440 state));
1579 } 1441 }
1580 1442
1581 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( 1443 void SyncBackendHost::OnIncomingInvalidation(
1582 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1444 const syncer::ObjectIdInvalidationMap& invalidation_map) {
1583 if (!frontend_) 1445 // TODO(dcheng): Acknowledge immediately for now. Fix this once the
1584 return; 1446 // invalidator doesn't repeatedly ping for unacknowledged invaliations, since
1585 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1447 // it conflicts with the sync scheduler's internal backoff algorithm.
1586 frontend_->OnIncomingInvalidation(invalidation_map); 1448 // See http://crbug.com/124149 for more information.
1449 for (syncer::ObjectIdInvalidationMap::const_iterator it =
1450 invalidation_map.begin(); it != invalidation_map.end(); ++it) {
1451 invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle);
1452 }
1453
1454 sync_thread_.message_loop()->PostTask(
1455 FROM_HERE,
1456 base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation,
1457 core_.get(),
1458 invalidation_map));
1587 } 1459 }
1588 1460
1589 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1461 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1590 const std::string& passphrase) const { 1462 const std::string& passphrase) const {
1591 DCHECK(cached_pending_keys_.has_blob()); 1463 DCHECK(cached_pending_keys_.has_blob());
1592 DCHECK(!passphrase.empty()); 1464 DCHECK(!passphrase.empty());
1593 syncer::Nigori nigori; 1465 syncer::Nigori nigori;
1594 nigori.InitByDerivation("localhost", "dummy", passphrase); 1466 nigori.InitByDerivation("localhost", "dummy", passphrase);
1595 std::string plaintext; 1467 std::string plaintext;
1596 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1468 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: " 1549 DVLOG(1) << "Connection status changed: "
1678 << syncer::ConnectionStatusToString(status); 1550 << syncer::ConnectionStatusToString(status);
1679 frontend_->OnConnectionStatusChange(status); 1551 frontend_->OnConnectionStatusChange(status);
1680 } 1552 }
1681 1553
1682 #undef SDVLOG 1554 #undef SDVLOG
1683 1555
1684 #undef SLOG 1556 #undef SLOG
1685 1557
1686 } // namespace browser_sync 1558 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698