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

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

Issue 12022041: Separate local and remote sync invalidations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" 17 #include "chrome/browser/sync/glue/backend_data_type_configurer.h"
18 #include "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h" 18 #include "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
19 #include "google_apis/gaia/google_service_auth_error.h" 21 #include "google_apis/gaia/google_service_auth_error.h"
20 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
21 #include "sync/internal_api/public/base/model_type.h" 23 #include "sync/internal_api/public/base/model_type.h"
22 #include "sync/internal_api/public/configure_reason.h" 24 #include "sync/internal_api/public/configure_reason.h"
23 #include "sync/internal_api/public/engine/model_safe_worker.h" 25 #include "sync/internal_api/public/engine/model_safe_worker.h"
24 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
25 #include "sync/internal_api/public/sync_encryption_handler.h" 27 #include "sync/internal_api/public/sync_encryption_handler.h"
26 #include "sync/internal_api/public/sync_manager.h" 28 #include "sync/internal_api/public/sync_manager.h"
27 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" 29 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
28 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 30 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
29 #include "sync/internal_api/public/util/weak_handle.h" 31 #include "sync/internal_api/public/util/weak_handle.h"
30 #include "sync/notifier/invalidation_handler.h" 32 #include "sync/notifier/invalidation_handler.h"
31 #include "sync/notifier/invalidator_factory.h" 33 #include "sync/notifier/invalidator_factory.h"
32 #include "sync/protocol/encryption.pb.h" 34 #include "sync/protocol/encryption.pb.h"
33 #include "sync/protocol/sync_protocol_error.h" 35 #include "sync/protocol/sync_protocol_error.h"
34 36
35 class MessageLoop; 37 class MessageLoop;
36 class Profile; 38 class Profile;
37 39
38 namespace syncer { 40 namespace syncer {
39 class SyncManagerFactory; 41 class SyncManagerFactory;
40 } 42 }
41 43
42 namespace browser_sync { 44 namespace browser_sync {
43 45
46 class AndroidInvalidatorBridge;
44 class ChangeProcessor; 47 class ChangeProcessor;
45 class ChromeSyncNotificationBridge;
46 class InvalidatorStorage; 48 class InvalidatorStorage;
47 class SyncBackendRegistrar; 49 class SyncBackendRegistrar;
48 class SyncPrefs; 50 class SyncPrefs;
49 class SyncedDeviceTracker; 51 class SyncedDeviceTracker;
50 struct Experiments; 52 struct Experiments;
51 53
52 // SyncFrontend is the interface used by SyncBackendHost to communicate with 54 // SyncFrontend is the interface used by SyncBackendHost to communicate with
53 // the entity that created it and, presumably, is interested in sync-related 55 // the entity that created it and, presumably, is interested in sync-related
54 // activity. 56 // activity.
55 // NOTE: All methods will be invoked by a SyncBackendHost on the same thread 57 // NOTE: All methods will be invoked by a SyncBackendHost on the same thread
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 virtual ~SyncFrontend() { 138 virtual ~SyncFrontend() {
137 } 139 }
138 private: 140 private:
139 DISALLOW_COPY_AND_ASSIGN(SyncFrontend); 141 DISALLOW_COPY_AND_ASSIGN(SyncFrontend);
140 }; 142 };
141 143
142 // A UI-thread safe API into the sync backend that "hosts" the top-level 144 // A UI-thread safe API into the sync backend that "hosts" the top-level
143 // syncapi element, the SyncManager, on its own thread. This class handles 145 // syncapi element, the SyncManager, on its own thread. This class handles
144 // dispatch of potentially blocking calls to appropriate threads and ensures 146 // dispatch of potentially blocking calls to appropriate threads and ensures
145 // that the SyncFrontend is only accessed on the UI loop. 147 // that the SyncFrontend is only accessed on the UI loop.
146 class SyncBackendHost : public BackendDataTypeConfigurer { 148 class SyncBackendHost
149 : public BackendDataTypeConfigurer,
150 public content::NotificationObserver {
147 public: 151 public:
148 typedef syncer::SyncStatus Status; 152 typedef syncer::SyncStatus Status;
149 153
150 // Create a SyncBackendHost with a reference to the |frontend| that 154 // Create a SyncBackendHost with a reference to the |frontend| that
151 // it serves and communicates to via the SyncFrontend interface (on 155 // it serves and communicates to via the SyncFrontend interface (on
152 // the same thread it used to call the constructor). Must outlive 156 // the same thread it used to call the constructor). Must outlive
153 // |sync_prefs| and |invalidator_storage|. 157 // |sync_prefs| and |invalidator_storage|.
154 SyncBackendHost( 158 SyncBackendHost(
155 const std::string& name, 159 const std::string& name,
156 Profile* profile, 160 Profile* profile,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 DoInitializeOptions( 305 DoInitializeOptions(
302 MessageLoop* sync_loop, 306 MessageLoop* sync_loop,
303 SyncBackendRegistrar* registrar, 307 SyncBackendRegistrar* registrar,
304 const syncer::ModelSafeRoutingInfo& routing_info, 308 const syncer::ModelSafeRoutingInfo& routing_info,
305 const std::vector<syncer::ModelSafeWorker*>& workers, 309 const std::vector<syncer::ModelSafeWorker*>& workers,
306 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 310 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
307 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 311 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
308 const GURL& service_url, 312 const GURL& service_url,
309 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 313 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
310 const syncer::SyncCredentials& credentials, 314 const syncer::SyncCredentials& credentials,
311 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, 315 AndroidInvalidatorBridge* android_invalidator_bridge,
312 syncer::InvalidatorFactory* invalidator_factory, 316 syncer::InvalidatorFactory* invalidator_factory,
313 syncer::SyncManagerFactory* sync_manager_factory, 317 syncer::SyncManagerFactory* sync_manager_factory,
314 bool delete_sync_data_folder, 318 bool delete_sync_data_folder,
315 const std::string& restored_key_for_bootstrapping, 319 const std::string& restored_key_for_bootstrapping,
316 const std::string& restored_keystore_key_for_bootstrapping, 320 const std::string& restored_keystore_key_for_bootstrapping,
317 syncer::InternalComponentsFactory* internal_components_factory, 321 syncer::InternalComponentsFactory* internal_components_factory,
318 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 322 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
319 syncer::ReportUnrecoverableErrorFunction 323 syncer::ReportUnrecoverableErrorFunction
320 report_unrecoverable_error_function); 324 report_unrecoverable_error_function);
321 ~DoInitializeOptions(); 325 ~DoInitializeOptions();
322 326
323 MessageLoop* sync_loop; 327 MessageLoop* sync_loop;
324 SyncBackendRegistrar* registrar; 328 SyncBackendRegistrar* registrar;
325 syncer::ModelSafeRoutingInfo routing_info; 329 syncer::ModelSafeRoutingInfo routing_info;
326 std::vector<syncer::ModelSafeWorker*> workers; 330 std::vector<syncer::ModelSafeWorker*> workers;
327 syncer::ExtensionsActivityMonitor* extensions_activity_monitor; 331 syncer::ExtensionsActivityMonitor* extensions_activity_monitor;
328 syncer::WeakHandle<syncer::JsEventHandler> event_handler; 332 syncer::WeakHandle<syncer::JsEventHandler> event_handler;
329 GURL service_url; 333 GURL service_url;
330 // Overridden by tests. 334 // Overridden by tests.
331 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; 335 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn;
332 syncer::SyncCredentials credentials; 336 syncer::SyncCredentials credentials;
333 ChromeSyncNotificationBridge* const chrome_sync_notification_bridge; 337 AndroidInvalidatorBridge* const android_invalidator_bridge;
334 syncer::InvalidatorFactory* const invalidator_factory; 338 syncer::InvalidatorFactory* const invalidator_factory;
335 syncer::SyncManagerFactory* const sync_manager_factory; 339 syncer::SyncManagerFactory* const sync_manager_factory;
336 std::string lsid; 340 std::string lsid;
337 bool delete_sync_data_folder; 341 bool delete_sync_data_folder;
338 std::string restored_key_for_bootstrapping; 342 std::string restored_key_for_bootstrapping;
339 std::string restored_keystore_key_for_bootstrapping; 343 std::string restored_keystore_key_for_bootstrapping;
340 syncer::InternalComponentsFactory* internal_components_factory; 344 syncer::InternalComponentsFactory* internal_components_factory;
341 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler; 345 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler;
342 syncer::ReportUnrecoverableErrorFunction 346 syncer::ReportUnrecoverableErrorFunction
343 report_unrecoverable_error_function; 347 report_unrecoverable_error_function;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 void HandleConnectionStatusChangeOnFrontendLoop( 480 void HandleConnectionStatusChangeOnFrontendLoop(
477 syncer::ConnectionStatus status); 481 syncer::ConnectionStatus status);
478 482
479 // syncer::InvalidationHandler-like functions. 483 // syncer::InvalidationHandler-like functions.
480 void HandleInvalidatorStateChangeOnFrontendLoop( 484 void HandleInvalidatorStateChangeOnFrontendLoop(
481 syncer::InvalidatorState state); 485 syncer::InvalidatorState state);
482 void HandleIncomingInvalidationOnFrontendLoop( 486 void HandleIncomingInvalidationOnFrontendLoop(
483 const syncer::ObjectIdInvalidationMap& invalidation_map, 487 const syncer::ObjectIdInvalidationMap& invalidation_map,
484 syncer::IncomingInvalidationSource source); 488 syncer::IncomingInvalidationSource source);
485 489
490 // NotificationObserver implementation.
491 virtual void Observe(
492 int type,
493 const content::NotificationSource& source,
494 const content::NotificationDetails& details) OVERRIDE;
495
486 // Handles stopping the core's SyncManager, accounting for whether 496 // Handles stopping the core's SyncManager, accounting for whether
487 // initialization is done yet. 497 // initialization is done yet.
488 void StopSyncManagerForShutdown(const base::Closure& closure); 498 void StopSyncManagerForShutdown(const base::Closure& closure);
489 499
490 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; 500 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_;
491 501
502 content::NotificationRegistrar notification_registrar_;
503
492 // A thread where all the sync operations happen. 504 // A thread where all the sync operations happen.
493 base::Thread sync_thread_; 505 base::Thread sync_thread_;
494 506
495 // A reference to the MessageLoop used to construct |this|, so we know how 507 // A reference to the MessageLoop used to construct |this|, so we know how
496 // to safely talk back to the SyncFrontend. 508 // to safely talk back to the SyncFrontend.
497 MessageLoop* const frontend_loop_; 509 MessageLoop* const frontend_loop_;
498 510
499 Profile* const profile_; 511 Profile* const profile_;
500 512
501 // Name used for debugging (set from profile_->GetDebugName()). 513 // Name used for debugging (set from profile_->GetDebugName()).
502 const std::string name_; 514 const std::string name_;
503 515
504 // Our core, which communicates directly to the syncapi. 516 // Our core, which communicates directly to the syncapi.
505 scoped_refptr<Core> core_; 517 scoped_refptr<Core> core_;
506 518
507 InitializationState initialization_state_; 519 InitializationState initialization_state_;
508 520
509 const base::WeakPtr<SyncPrefs> sync_prefs_; 521 const base::WeakPtr<SyncPrefs> sync_prefs_;
510 522
511 // A bridge that converts Chrome notifications (on the UI thread) 523 scoped_ptr<AndroidInvalidatorBridge> android_invalidator_bridge_;
512 // into invalidations (on the sync thread).
513 scoped_ptr<ChromeSyncNotificationBridge> chrome_sync_notification_bridge_;
514 524
515 syncer::InvalidatorFactory invalidator_factory_; 525 syncer::InvalidatorFactory invalidator_factory_;
516 526
517 ChromeExtensionsActivityMonitor extensions_activity_monitor_; 527 ChromeExtensionsActivityMonitor extensions_activity_monitor_;
518 528
519 scoped_ptr<SyncBackendRegistrar> registrar_; 529 scoped_ptr<SyncBackendRegistrar> registrar_;
520 530
521 // The frontend which we serve (and are owned by). 531 // The frontend which we serve (and are owned by).
522 SyncFrontend* frontend_; 532 SyncFrontend* frontend_;
523 533
(...skipping 26 matching lines...) Expand all
550 // HandleInitializationCompletedOnFrontendLoop. 560 // HandleInitializationCompletedOnFrontendLoop.
551 syncer::WeakHandle<syncer::JsBackend> js_backend_; 561 syncer::WeakHandle<syncer::JsBackend> js_backend_;
552 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; 562 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_;
553 563
554 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); 564 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost);
555 }; 565 };
556 566
557 } // namespace browser_sync 567 } // namespace browser_sync
558 568
559 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 569 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc ('k') | chrome/browser/sync/glue/sync_backend_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698