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

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: More unit test fixes. 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 "content/public/browser/notification_observer.h" 33 #include "content/public/browser/notification_observer.h"
33 #include "content/public/browser/notification_registrar.h" 34 #include "content/public/browser/notification_registrar.h"
34 #include "content/public/browser/notification_types.h" 35 #include "content/public/browser/notification_types.h"
35 #include "google_apis/gaia/google_service_auth_error.h" 36 #include "google_apis/gaia/google_service_auth_error.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 virtual void SetSyncSetupCompleted();
226
227 // ProfileSyncServiceBase implementation.
228 virtual bool HasSyncSetupCompleted() const OVERRIDE;
229 virtual bool ShouldPushChanges() OVERRIDE;
230 virtual syncer::ModelTypeSet GetPreferredDataTypes() const OVERRIDE;
231 virtual void AddObserver(Observer* observer) OVERRIDE;
232 virtual void RemoveObserver(Observer* observer) OVERRIDE;
233 virtual bool HasObserver(Observer* observer) const OVERRIDE;
234
224 void RegisterAuthNotifications(); 235 void RegisterAuthNotifications();
225 236
226 // Returns true if sync is enabled/not suppressed and the user is logged in. 237 // 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 238 // (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 239 // be missing because they have not loaded yet, or because they were deleted
229 // due to http://crbug.com/121755). 240 // due to http://crbug.com/121755).
230 // Virtual to enable mocking in tests. 241 // Virtual to enable mocking in tests.
231 virtual bool IsSyncEnabledAndLoggedIn(); 242 virtual bool IsSyncEnabledAndLoggedIn();
232 243
233 // Return whether all sync tokens are loaded and available for the backend to 244 // Return whether all sync tokens are loaded and available for the backend to
(...skipping 13 matching lines...) Expand all
247 browser_sync::SessionModelAssociator* GetSessionModelAssociator(); 258 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
248 259
249 // Fills state_map with a map of current data types that are possible to 260 // Fills state_map with a map of current data types that are possible to
250 // sync, as well as their states. 261 // sync, as well as their states.
251 void GetDataTypeControllerStates( 262 void GetDataTypeControllerStates(
252 browser_sync::DataTypeController::StateMap* state_map) const; 263 browser_sync::DataTypeController::StateMap* state_map) const;
253 264
254 // Disables sync for user. Use ShowLoginDialog to enable. 265 // Disables sync for user. Use ShowLoginDialog to enable.
255 virtual void DisableForUser(); 266 virtual void DisableForUser();
256 267
257 // Whether sync is enabled by user or not.
258 virtual bool HasSyncSetupCompleted() const;
259 virtual void SetSyncSetupCompleted();
260
261 // syncer::InvalidationHandler implementation (via SyncFrontend). 268 // syncer::InvalidationHandler implementation (via SyncFrontend).
262 virtual void OnInvalidatorStateChange( 269 virtual void OnInvalidatorStateChange(
263 syncer::InvalidatorState state) OVERRIDE; 270 syncer::InvalidatorState state) OVERRIDE;
264 virtual void OnIncomingInvalidation( 271 virtual void OnIncomingInvalidation(
265 const syncer::ObjectIdStateMap& id_state_map, 272 const syncer::ObjectIdStateMap& id_state_map,
266 syncer::IncomingInvalidationSource source) OVERRIDE; 273 syncer::IncomingInvalidationSource source) OVERRIDE;
267 274
268 // SyncFrontend implementation. 275 // SyncFrontend implementation.
269 virtual void OnBackendInitialized( 276 virtual void OnBackendInitialized(
270 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 277 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 370 }
364 371
365 // Returns a user-friendly string form of last synced time (in minutes). 372 // Returns a user-friendly string form of last synced time (in minutes).
366 virtual string16 GetLastSyncedTimeString() const; 373 virtual string16 GetLastSyncedTimeString() const;
367 374
368 ProfileSyncComponentsFactory* factory() { return factory_.get(); } 375 ProfileSyncComponentsFactory* factory() { return factory_.get(); }
369 376
370 // The profile we are syncing for. 377 // The profile we are syncing for.
371 Profile* profile() const { return profile_; } 378 Profile* profile() const { return profile_; }
372 379
373 // Adds/removes an observer. ProfileSyncService does not take ownership of
374 // the observer.
375 virtual void AddObserver(Observer* observer);
376 virtual void RemoveObserver(Observer* observer);
377
378 // Returns true if |observer| has already been added as an observer.
379 bool HasObserver(Observer* observer) const;
380
381 // Returns a weak pointer to the service's JsController. 380 // Returns a weak pointer to the service's JsController.
382 // Overrideable for testing purposes. 381 // Overrideable for testing purposes.
383 virtual base::WeakPtr<syncer::JsController> GetJsController(); 382 virtual base::WeakPtr<syncer::JsController> GetJsController();
384 383
385 // Record stats on various events. 384 // Record stats on various events.
386 static void SyncEvent(SyncEventCodes code); 385 static void SyncEvent(SyncEventCodes code);
387 386
388 // Returns whether sync is enabled. Sync can be enabled/disabled both 387 // Returns whether sync is enabled. Sync can be enabled/disabled both
389 // at compile time (e.g., on a per-OS basis) or at run time (e.g., 388 // at compile time (e.g., on a per-OS basis) or at run time (e.g.,
390 // command-line switches). 389 // command-line switches).
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 const content::NotificationSource& source, 460 const content::NotificationSource& source,
462 const content::NotificationDetails& details) OVERRIDE; 461 const content::NotificationDetails& details) OVERRIDE;
463 462
464 // Changes which data types we're going to be syncing to |preferred_types|. 463 // Changes which data types we're going to be syncing to |preferred_types|.
465 // If it is running, the DataTypeManager will be instructed to reconfigure 464 // If it is running, the DataTypeManager will be instructed to reconfigure
466 // the sync backend so that exactly these datatypes are actively synced. See 465 // the sync backend so that exactly these datatypes are actively synced. See
467 // class comment for more on what it means for a datatype to be Preferred. 466 // class comment for more on what it means for a datatype to be Preferred.
468 virtual void ChangePreferredDataTypes( 467 virtual void ChangePreferredDataTypes(
469 syncer::ModelTypeSet preferred_types); 468 syncer::ModelTypeSet preferred_types);
470 469
471 // Get the set of currently enabled data types (as chosen or configured by
472 // the user). See class comment for more on what it means for a datatype
473 // to be Preferred.
474 virtual syncer::ModelTypeSet GetPreferredDataTypes() const;
475
476 // Gets the set of all data types that could be allowed (the set that 470 // Gets the set of all data types that could be allowed (the set that
477 // should be advertised to the user). These will typically only change 471 // should be advertised to the user). These will typically only change
478 // via a command-line option. See class comment for more on what it means 472 // via a command-line option. See class comment for more on what it means
479 // for a datatype to be Registered. 473 // for a datatype to be Registered.
480 virtual syncer::ModelTypeSet GetRegisteredDataTypes() const; 474 virtual syncer::ModelTypeSet GetRegisteredDataTypes() const;
481 475
482 // Checks whether the Cryptographer is ready to encrypt and decrypt updates 476 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
483 // for sensitive data types. Caller must be holding a 477 // for sensitive data types. Caller must be holding a
484 // syncapi::BaseTransaction to ensure thread safety. 478 // syncapi::BaseTransaction to ensure thread safety.
485 virtual bool IsCryptographerReady( 479 virtual bool IsCryptographerReady(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 // encryption_pending() must be checked. 514 // encryption_pending() must be checked.
521 virtual bool EncryptEverythingEnabled() const; 515 virtual bool EncryptEverythingEnabled() const;
522 516
523 // Fills |encrypted_types| with the set of currently encrypted types. Does 517 // Fills |encrypted_types| with the set of currently encrypted types. Does
524 // not account for types pending encryption. 518 // not account for types pending encryption.
525 virtual syncer::ModelTypeSet GetEncryptedDataTypes() const; 519 virtual syncer::ModelTypeSet GetEncryptedDataTypes() const;
526 520
527 // Returns true if the syncer is waiting for new datatypes to be encrypted. 521 // Returns true if the syncer is waiting for new datatypes to be encrypted.
528 virtual bool encryption_pending() const; 522 virtual bool encryption_pending() const;
529 523
530 // Returns whether processing changes is allowed. Check this before doing
531 // any model-modifying operations.
532 bool ShouldPushChanges();
533
534 const GURL& sync_service_url() const { return sync_service_url_; } 524 const GURL& sync_service_url() const { return sync_service_url_; }
535 bool auto_start_enabled() const { return auto_start_enabled_; } 525 bool auto_start_enabled() const { return auto_start_enabled_; }
536 SigninManager* signin() const { return signin_; } 526 SigninManager* signin() const { return signin_; }
537 bool setup_in_progress() const { return setup_in_progress_; } 527 bool setup_in_progress() const { return setup_in_progress_; }
538 528
539 // Stops the sync backend and sets the flag for suppressing sync startup. 529 // Stops the sync backend and sets the flag for suppressing sync startup.
540 void StopAndSuppress(); 530 void StopAndSuppress();
541 531
542 // Resets the flag for suppressing sync startup and starts the sync backend. 532 // Resets the flag for suppressing sync startup and starts the sync backend.
543 void UnsuppressAndStart(); 533 void UnsuppressAndStart();
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 syncer::InvalidatorRegistrar invalidator_registrar_; 845 syncer::InvalidatorRegistrar invalidator_registrar_;
856 846
857 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); 847 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
858 }; 848 };
859 849
860 bool ShouldShowActionOnUI( 850 bool ShouldShowActionOnUI(
861 const syncer::SyncProtocolError& error); 851 const syncer::SyncProtocolError& error);
862 852
863 853
864 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 854 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_tracker.h ('k') | chrome/browser/sync/profile_sync_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698