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

Side by Side Diff: chrome/browser/sync/profile_sync_service.h

Issue 10910071: Extract abstract base to API directory for ProfileSyncService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge LKGR Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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_PROFILE_SYNC_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/string16.h" 18 #include "base/string16.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "base/timer.h" 20 #include "base/timer.h"
21 #include "chrome/browser/api/sync/profile_sync_service_base.h"
22 #include "chrome/browser/api/sync/profile_sync_service_observer.h"
21 #include "chrome/browser/profiles/profile_keyed_service.h" 23 #include "chrome/browser/profiles/profile_keyed_service.h"
22 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" 24 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h"
23 #include "chrome/browser/sync/failed_datatypes_handler.h" 25 #include "chrome/browser/sync/failed_datatypes_handler.h"
24 #include "chrome/browser/sync/glue/data_type_controller.h" 26 #include "chrome/browser/sync/glue/data_type_controller.h"
25 #include "chrome/browser/sync/glue/data_type_manager.h" 27 #include "chrome/browser/sync/glue/data_type_manager.h"
26 #include "chrome/browser/sync/glue/data_type_manager_observer.h" 28 #include "chrome/browser/sync/glue/data_type_manager_observer.h"
27 #include "chrome/browser/sync/glue/sync_backend_host.h" 29 #include "chrome/browser/sync/glue/sync_backend_host.h"
28 #include "chrome/browser/sync/invalidation_frontend.h" 30 #include "chrome/browser/sync/invalidation_frontend.h"
29 #include "chrome/browser/sync/invalidations/invalidator_storage.h" 31 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
30 #include "chrome/browser/sync/profile_sync_service_observer.h"
31 #include "chrome/browser/sync/sync_prefs.h" 32 #include "chrome/browser/sync/sync_prefs.h"
32 #include "chrome/common/net/gaia/google_service_auth_error.h" 33 #include "chrome/common/net/gaia/google_service_auth_error.h"
33 #include "content/public/browser/notification_observer.h" 34 #include "content/public/browser/notification_observer.h"
34 #include "content/public/browser/notification_registrar.h" 35 #include "content/public/browser/notification_registrar.h"
35 #include "content/public/browser/notification_types.h" 36 #include "content/public/browser/notification_types.h"
36 #include "googleurl/src/gurl.h" 37 #include "googleurl/src/gurl.h"
37 #include "sync/internal_api/public/base/model_type.h" 38 #include "sync/internal_api/public/base/model_type.h"
38 #include "sync/internal_api/public/engine/model_safe_worker.h" 39 #include "sync/internal_api/public/engine/model_safe_worker.h"
39 #include "sync/internal_api/public/sync_manager_factory.h" 40 #include "sync/internal_api/public/sync_manager_factory.h"
40 #include "sync/internal_api/public/util/experiments.h" 41 #include "sync/internal_api/public/util/experiments.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // called while the user is actively configuring their account, and then 143 // called while the user is actively configuring their account, and then
143 // SetSetupInProgress(false) should be called when configuration is complete. 144 // SetSetupInProgress(false) should be called when configuration is complete.
144 // When SetSyncSetupCompleted() == false, but SetSetupInProgress(true) has 145 // When SetSyncSetupCompleted() == false, but SetSetupInProgress(true) has
145 // been called, then the sync engine knows not to download any user data. 146 // been called, then the sync engine knows not to download any user data.
146 // 147 //
147 // When initial sync is complete, the UI code should call 148 // When initial sync is complete, the UI code should call
148 // SetSyncSetupCompleted() followed by SetSetupInProgress(false) - this will 149 // SetSyncSetupCompleted() followed by SetSetupInProgress(false) - this will
149 // tell the sync engine that setup is completed and it can begin downloading 150 // tell the sync engine that setup is completed and it can begin downloading
150 // data from the sync server. 151 // data from the sync server.
151 // 152 //
152 class ProfileSyncService : public browser_sync::SyncFrontend, 153 class ProfileSyncService : public ProfileSyncServiceBase,
154 public browser_sync::SyncFrontend,
153 public browser_sync::SyncPrefObserver, 155 public browser_sync::SyncPrefObserver,
154 public browser_sync::DataTypeManagerObserver, 156 public browser_sync::DataTypeManagerObserver,
155 public syncer::UnrecoverableErrorHandler, 157 public syncer::UnrecoverableErrorHandler,
156 public content::NotificationObserver, 158 public content::NotificationObserver,
157 public ProfileKeyedService, 159 public ProfileKeyedService,
158 public InvalidationFrontend { 160 public InvalidationFrontend {
159 public: 161 public:
160 typedef ProfileSyncServiceObserver Observer;
161 typedef browser_sync::SyncBackendHost::Status Status; 162 typedef browser_sync::SyncBackendHost::Status Status;
162 163
163 enum SyncEventCodes { 164 enum SyncEventCodes {
164 MIN_SYNC_EVENT_CODE = 0, 165 MIN_SYNC_EVENT_CODE = 0,
165 166
166 // Events starting the sync service. 167 // Events starting the sync service.
167 START_FROM_NTP = 1, // Sync was started from the ad in NTP 168 START_FROM_NTP = 1, // Sync was started from the ad in NTP
168 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. 169 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu.
169 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. 170 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options.
170 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager. 171 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 ProfileSyncService(ProfileSyncComponentsFactory* factory, 215 ProfileSyncService(ProfileSyncComponentsFactory* factory,
215 Profile* profile, 216 Profile* profile,
216 SigninManager* signin, 217 SigninManager* signin,
217 StartBehavior start_behavior); 218 StartBehavior start_behavior);
218 virtual ~ProfileSyncService(); 219 virtual ~ProfileSyncService();
219 220
220 // Initializes the object. This should be called every time an object of this 221 // Initializes the object. This should be called every time an object of this
221 // class is constructed. 222 // class is constructed.
222 void Initialize(); 223 void Initialize();
223 224
225 // ProfileSyncServiceBase implementation.
226 virtual bool HasSyncSetupCompleted() const OVERRIDE;
227 virtual bool ShouldPushChanges() OVERRIDE;
228 virtual syncer::ModelTypeSet GetPreferredDataTypes() const OVERRIDE;
229 virtual void AddObserver(Observer* observer) OVERRIDE;
230 virtual void RemoveObserver(Observer* observer) OVERRIDE;
231 virtual bool HasObserver(Observer* observer) const OVERRIDE;
tim (not reviewing) 2012/09/06 17:00:06 If we describe ProfileSyncServiceBase as "what nor
Jói 2012/09/06 20:08:35 OK. I agree it's probably best to evolve it as we
232
224 void RegisterAuthNotifications(); 233 void RegisterAuthNotifications();
225 234
226 // Returns true if sync is enabled/not suppressed and the user is logged in. 235 // Returns true if sync is enabled/not suppressed and the user is logged in.
227 // (being logged in does not mean that tokens are available - tokens may 236 // (being logged in does not mean that tokens are available - tokens may
228 // be missing because they have not loaded yet, or because they were deleted 237 // be missing because they have not loaded yet, or because they were deleted
229 // due to http://crbug.com/121755). 238 // due to http://crbug.com/121755).
230 // Virtual to enable mocking in tests. 239 // Virtual to enable mocking in tests.
231 virtual bool IsSyncEnabledAndLoggedIn(); 240 virtual bool IsSyncEnabledAndLoggedIn();
232 241
233 // Return whether all sync tokens are loaded and available for the backend to 242 // Return whether all sync tokens are loaded and available for the backend to
(...skipping 13 matching lines...) Expand all
247 browser_sync::SessionModelAssociator* GetSessionModelAssociator(); 256 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
248 257
249 // Fills state_map with a map of current data types that are possible to 258 // Fills state_map with a map of current data types that are possible to
250 // sync, as well as their states. 259 // sync, as well as their states.
251 void GetDataTypeControllerStates( 260 void GetDataTypeControllerStates(
252 browser_sync::DataTypeController::StateMap* state_map) const; 261 browser_sync::DataTypeController::StateMap* state_map) const;
253 262
254 // Disables sync for user. Use ShowLoginDialog to enable. 263 // Disables sync for user. Use ShowLoginDialog to enable.
255 virtual void DisableForUser(); 264 virtual void DisableForUser();
256 265
257 // Whether sync is enabled by user or not.
258 virtual bool HasSyncSetupCompleted() const;
259 virtual void SetSyncSetupCompleted(); 266 virtual void SetSyncSetupCompleted();
tim (not reviewing) 2012/09/06 17:00:06 It's weird that this is so asymmetric now. Just do
Jói 2012/09/06 20:08:35 Correct, the APIs are intended for "business logic
260 267
261 // syncer::InvalidationHandler implementation (via SyncFrontend). 268 // syncer::InvalidationHandler implementation (via SyncFrontend).
262 virtual void OnNotificationsEnabled() OVERRIDE; 269 virtual void OnNotificationsEnabled() OVERRIDE;
263 virtual void OnNotificationsDisabled( 270 virtual void OnNotificationsDisabled(
264 syncer::NotificationsDisabledReason reason) OVERRIDE; 271 syncer::NotificationsDisabledReason reason) OVERRIDE;
265 virtual void OnIncomingNotification( 272 virtual void OnIncomingNotification(
266 const syncer::ObjectIdStateMap& id_state_map, 273 const syncer::ObjectIdStateMap& id_state_map,
267 syncer::IncomingNotificationSource source) OVERRIDE; 274 syncer::IncomingNotificationSource source) OVERRIDE;
268 275
269 // SyncFrontend implementation. 276 // SyncFrontend implementation.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 371 }
365 372
366 // Returns a user-friendly string form of last synced time (in minutes). 373 // Returns a user-friendly string form of last synced time (in minutes).
367 virtual string16 GetLastSyncedTimeString() const; 374 virtual string16 GetLastSyncedTimeString() const;
368 375
369 ProfileSyncComponentsFactory* factory() { return factory_.get(); } 376 ProfileSyncComponentsFactory* factory() { return factory_.get(); }
370 377
371 // The profile we are syncing for. 378 // The profile we are syncing for.
372 Profile* profile() const { return profile_; } 379 Profile* profile() const { return profile_; }
373 380
374 // Adds/removes an observer. ProfileSyncService does not take ownership of
375 // the observer.
376 virtual void AddObserver(Observer* observer);
377 virtual void RemoveObserver(Observer* observer);
378
379 // Returns true if |observer| has already been added as an observer.
380 bool HasObserver(Observer* observer) const;
381
382 // Returns a weak pointer to the service's JsController. 381 // Returns a weak pointer to the service's JsController.
383 // Overrideable for testing purposes. 382 // Overrideable for testing purposes.
384 virtual base::WeakPtr<syncer::JsController> GetJsController(); 383 virtual base::WeakPtr<syncer::JsController> GetJsController();
385 384
386 // Record stats on various events. 385 // Record stats on various events.
387 static void SyncEvent(SyncEventCodes code); 386 static void SyncEvent(SyncEventCodes code);
388 387
389 // Returns whether sync is enabled. Sync can be enabled/disabled both 388 // Returns whether sync is enabled. Sync can be enabled/disabled both
390 // at compile time (e.g., on a per-OS basis) or at run time (e.g., 389 // at compile time (e.g., on a per-OS basis) or at run time (e.g.,
391 // command-line switches). 390 // command-line switches).
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 const content::NotificationSource& source, 461 const content::NotificationSource& source,
463 const content::NotificationDetails& details) OVERRIDE; 462 const content::NotificationDetails& details) OVERRIDE;
464 463
465 // Changes which data types we're going to be syncing to |preferred_types|. 464 // Changes which data types we're going to be syncing to |preferred_types|.
466 // If it is running, the DataTypeManager will be instructed to reconfigure 465 // If it is running, the DataTypeManager will be instructed to reconfigure
467 // the sync backend so that exactly these datatypes are actively synced. See 466 // the sync backend so that exactly these datatypes are actively synced. See
468 // class comment for more on what it means for a datatype to be Preferred. 467 // class comment for more on what it means for a datatype to be Preferred.
469 virtual void ChangePreferredDataTypes( 468 virtual void ChangePreferredDataTypes(
470 syncer::ModelTypeSet preferred_types); 469 syncer::ModelTypeSet preferred_types);
471 470
472 // Get the set of currently enabled data types (as chosen or configured by
473 // the user). See class comment for more on what it means for a datatype
474 // to be Preferred.
475 virtual syncer::ModelTypeSet GetPreferredDataTypes() const;
476
477 // Gets the set of all data types that could be allowed (the set that 471 // Gets the set of all data types that could be allowed (the set that
478 // should be advertised to the user). These will typically only change 472 // should be advertised to the user). These will typically only change
479 // via a command-line option. See class comment for more on what it means 473 // via a command-line option. See class comment for more on what it means
480 // for a datatype to be Registered. 474 // for a datatype to be Registered.
481 virtual syncer::ModelTypeSet GetRegisteredDataTypes() const; 475 virtual syncer::ModelTypeSet GetRegisteredDataTypes() const;
482 476
483 // Checks whether the Cryptographer is ready to encrypt and decrypt updates 477 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
484 // for sensitive data types. Caller must be holding a 478 // for sensitive data types. Caller must be holding a
485 // syncapi::BaseTransaction to ensure thread safety. 479 // syncapi::BaseTransaction to ensure thread safety.
486 virtual bool IsCryptographerReady( 480 virtual bool IsCryptographerReady(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // encryption_pending() must be checked. 515 // encryption_pending() must be checked.
522 virtual bool EncryptEverythingEnabled() const; 516 virtual bool EncryptEverythingEnabled() const;
523 517
524 // Fills |encrypted_types| with the set of currently encrypted types. Does 518 // Fills |encrypted_types| with the set of currently encrypted types. Does
525 // not account for types pending encryption. 519 // not account for types pending encryption.
526 virtual syncer::ModelTypeSet GetEncryptedDataTypes() const; 520 virtual syncer::ModelTypeSet GetEncryptedDataTypes() const;
527 521
528 // Returns true if the syncer is waiting for new datatypes to be encrypted. 522 // Returns true if the syncer is waiting for new datatypes to be encrypted.
529 virtual bool encryption_pending() const; 523 virtual bool encryption_pending() const;
530 524
531 // Returns whether processing changes is allowed. Check this before doing
532 // any model-modifying operations.
533 bool ShouldPushChanges();
534
535 const GURL& sync_service_url() const { return sync_service_url_; } 525 const GURL& sync_service_url() const { return sync_service_url_; }
536 bool auto_start_enabled() const { return auto_start_enabled_; } 526 bool auto_start_enabled() const { return auto_start_enabled_; }
537 SigninManager* signin() const { return signin_; } 527 SigninManager* signin() const { return signin_; }
538 bool setup_in_progress() const { return setup_in_progress_; } 528 bool setup_in_progress() const { return setup_in_progress_; }
539 529
540 // Stops the sync backend and sets the flag for suppressing sync startup. 530 // Stops the sync backend and sets the flag for suppressing sync startup.
541 void StopAndSuppress(); 531 void StopAndSuppress();
542 532
543 // Resets the flag for suppressing sync startup and starts the sync backend. 533 // Resets the flag for suppressing sync startup and starts the sync backend.
544 void UnsuppressAndStart(); 534 void UnsuppressAndStart();
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 syncer::InvalidatorRegistrar invalidator_registrar_; 884 syncer::InvalidatorRegistrar invalidator_registrar_;
895 885
896 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); 886 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
897 }; 887 };
898 888
899 bool ShouldShowActionOnUI( 889 bool ShouldShowActionOnUI(
900 const syncer::SyncProtocolError& error); 890 const syncer::SyncProtocolError& error);
901 891
902 892
903 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 893 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698