Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "base/string16.h" | 19 #include "base/string16.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "base/timer.h" | 21 #include "base/timer.h" |
| 22 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 22 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" | 23 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" |
| 23 #include "chrome/browser/sync/engine/model_safe_worker.h" | 24 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 24 #include "chrome/browser/sync/failed_datatypes_handler.h" | 25 #include "chrome/browser/sync/failed_datatypes_handler.h" |
| 25 #include "chrome/browser/sync/glue/data_type_controller.h" | 26 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 26 #include "chrome/browser/sync/glue/sync_backend_host.h" | 27 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 27 #include "chrome/browser/sync/internal_api/includes/unrecoverable_error_handler. h" | 28 #include "chrome/browser/sync/internal_api/includes/unrecoverable_error_handler. h" |
| 28 #include "chrome/browser/sync/internal_api/sync_manager.h" | 29 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_observer.h" | 30 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 30 #include "chrome/browser/sync/syncable/model_type.h" | 31 #include "chrome/browser/sync/syncable/model_type.h" |
| 31 #include "chrome/browser/sync/sync_js_controller.h" | 32 #include "chrome/browser/sync/sync_js_controller.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 // as necessary. | 97 // as necessary. |
| 97 // | 98 // |
| 98 // When a datatype is in the process of becoming active, it may be | 99 // When a datatype is in the process of becoming active, it may be |
| 99 // in some intermediate state. Those finer-grained intermediate states | 100 // in some intermediate state. Those finer-grained intermediate states |
| 100 // are differentiated by the DataTypeController state. | 101 // are differentiated by the DataTypeController state. |
| 101 // | 102 // |
| 102 class ProfileSyncService : public browser_sync::SyncFrontend, | 103 class ProfileSyncService : public browser_sync::SyncFrontend, |
| 103 public browser_sync::SyncPrefObserver, | 104 public browser_sync::SyncPrefObserver, |
| 104 public browser_sync::UnrecoverableErrorHandler, | 105 public browser_sync::UnrecoverableErrorHandler, |
| 105 public content::NotificationObserver, | 106 public content::NotificationObserver, |
| 107 public ProfileKeyedService, | |
| 106 // TODO(lipalani): crbug.com/100829. Instead of | 108 // TODO(lipalani): crbug.com/100829. Instead of |
| 107 // doing this vend weak pointers from a factory. | 109 // doing this vend weak pointers from a factory. |
| 108 public base::SupportsWeakPtr<ProfileSyncService> { | 110 public base::SupportsWeakPtr<ProfileSyncService> { |
| 109 public: | 111 public: |
| 110 typedef ProfileSyncServiceObserver Observer; | 112 typedef ProfileSyncServiceObserver Observer; |
| 111 typedef browser_sync::SyncBackendHost::Status Status; | 113 typedef browser_sync::SyncBackendHost::Status Status; |
| 112 | 114 |
| 113 enum SyncEventCodes { | 115 enum SyncEventCodes { |
| 114 MIN_SYNC_EVENT_CODE = 0, | 116 MIN_SYNC_EVENT_CODE = 0, |
| 115 | 117 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 146 enum StartBehavior { | 148 enum StartBehavior { |
| 147 AUTO_START, | 149 AUTO_START, |
| 148 MANUAL_START, | 150 MANUAL_START, |
| 149 }; | 151 }; |
| 150 | 152 |
| 151 // Default sync server URL. | 153 // Default sync server URL. |
| 152 static const char* kSyncServerUrl; | 154 static const char* kSyncServerUrl; |
| 153 // Sync server URL for dev channel users | 155 // Sync server URL for dev channel users |
| 154 static const char* kDevServerUrl; | 156 static const char* kDevServerUrl; |
| 155 | 157 |
| 156 ProfileSyncService(ProfileSyncComponentsFactory* factory, | 158 ProfileSyncService(ProfileSyncComponentsFactory* factory, |
|
Andrew T Wilson (Slow)
2012/01/17 20:25:41
Since we're taking ownership of factory now, do we
tim (not reviewing)
2012/01/17 23:44:17
Done.
| |
| 157 Profile* profile, | 159 Profile* profile, |
| 158 SigninManager* signin, | 160 SigninManager* signin, |
| 159 StartBehavior start_behavior); | 161 StartBehavior start_behavior); |
| 160 virtual ~ProfileSyncService(); | 162 virtual ~ProfileSyncService(); |
| 161 | 163 |
| 162 // Initializes the object. This should be called every time an object of this | 164 // Initializes the object. This should be called every time an object of this |
| 163 // class is constructed. | 165 // class is constructed. |
| 164 void Initialize(); | 166 void Initialize(); |
| 165 | 167 |
| 166 void RegisterAuthNotifications(); | 168 void RegisterAuthNotifications(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // we have an encrypted data type enabled. | 317 // we have an encrypted data type enabled. |
| 316 virtual bool IsPassphraseRequiredForDecryption() const; | 318 virtual bool IsPassphraseRequiredForDecryption() const; |
| 317 | 319 |
| 318 sync_api::PassphraseRequiredReason passphrase_required_reason() const { | 320 sync_api::PassphraseRequiredReason passphrase_required_reason() const { |
| 319 return passphrase_required_reason_; | 321 return passphrase_required_reason_; |
| 320 } | 322 } |
| 321 | 323 |
| 322 // Returns a user-friendly string form of last synced time (in minutes). | 324 // Returns a user-friendly string form of last synced time (in minutes). |
| 323 virtual string16 GetLastSyncedTimeString() const; | 325 virtual string16 GetLastSyncedTimeString() const; |
| 324 | 326 |
| 327 ProfileSyncComponentsFactory* factory() { return factory_.get(); } | |
| 328 | |
| 325 // The profile we are syncing for. | 329 // The profile we are syncing for. |
| 326 Profile* profile() const { return profile_; } | 330 Profile* profile() const { return profile_; } |
| 327 | 331 |
| 328 // Adds/removes an observer. ProfileSyncService does not take ownership of | 332 // Adds/removes an observer. ProfileSyncService does not take ownership of |
| 329 // the observer. | 333 // the observer. |
| 330 virtual void AddObserver(Observer* observer); | 334 virtual void AddObserver(Observer* observer); |
| 331 virtual void RemoveObserver(Observer* observer); | 335 virtual void RemoveObserver(Observer* observer); |
| 332 | 336 |
| 333 // Returns true if |observer| has already been added as an observer. | 337 // Returns true if |observer| has already been added as an observer. |
| 334 bool HasObserver(Observer* observer) const; | 338 bool HasObserver(Observer* observer) const; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 void UnsuppressAndStart(); | 479 void UnsuppressAndStart(); |
| 476 | 480 |
| 477 // Marks all currently registered types as "acknowledged" so we won't prompt | 481 // Marks all currently registered types as "acknowledged" so we won't prompt |
| 478 // the user about them any more. | 482 // the user about them any more. |
| 479 void AcknowledgeSyncedTypes(); | 483 void AcknowledgeSyncedTypes(); |
| 480 | 484 |
| 481 SyncGlobalError* sync_global_error() { return sync_global_error_.get(); } | 485 SyncGlobalError* sync_global_error() { return sync_global_error_.get(); } |
| 482 | 486 |
| 483 virtual const FailedDatatypesHandler& failed_datatypes_handler(); | 487 virtual const FailedDatatypesHandler& failed_datatypes_handler(); |
| 484 | 488 |
| 489 // ProfileKeyedService implementation. | |
| 490 virtual void Shutdown(); | |
| 491 | |
| 485 protected: | 492 protected: |
| 486 // Used by test classes that derive from ProfileSyncService. | 493 // Used by test classes that derive from ProfileSyncService. |
| 487 virtual browser_sync::SyncBackendHost* GetBackendForTest(); | 494 virtual browser_sync::SyncBackendHost* GetBackendForTest(); |
| 488 | 495 |
| 489 // Helper to install and configure a data type manager. | 496 // Helper to install and configure a data type manager. |
| 490 void ConfigureDataTypeManager(); | 497 void ConfigureDataTypeManager(); |
| 491 | 498 |
| 492 // Starts up the backend sync components. | 499 // Starts up the backend sync components. |
| 493 void StartUp(); | 500 void StartUp(); |
| 494 // Shuts down the backend sync components. | 501 // Shuts down the backend sync components. |
| 495 // |sync_disabled| indicates if syncing is being disabled or not. | 502 // |sync_disabled| indicates if syncing is being disabled or not. |
| 496 void Shutdown(bool sync_disabled); | 503 void ShutdownImpl(bool sync_disabled); |
| 497 | 504 |
| 498 // Return SyncCredentials from the TokenService. | 505 // Return SyncCredentials from the TokenService. |
| 499 sync_api::SyncCredentials GetCredentials(); | 506 sync_api::SyncCredentials GetCredentials(); |
| 500 | 507 |
| 501 // Test need to override this to create backends that allow setting up | 508 // Test need to override this to create backends that allow setting up |
| 502 // initial conditions, such as populating sync nodes. | 509 // initial conditions, such as populating sync nodes. |
| 503 // | 510 // |
| 504 // TODO(akalin): Figure out a better way to do this. Ideally, we'd | 511 // TODO(akalin): Figure out a better way to do this. Ideally, we'd |
| 505 // construct the backend outside this class and pass it in to the | 512 // construct the backend outside this class and pass it in to the |
| 506 // contructor or Initialize(). | 513 // contructor or Initialize(). |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 virtual void ReconfigureDatatypeManager(); | 586 virtual void ReconfigureDatatypeManager(); |
| 580 | 587 |
| 581 | 588 |
| 582 // Time at which we begin an attempt a GAIA authorization. | 589 // Time at which we begin an attempt a GAIA authorization. |
| 583 base::TimeTicks auth_start_time_; | 590 base::TimeTicks auth_start_time_; |
| 584 | 591 |
| 585 // Time at which error UI is presented for the new tab page. | 592 // Time at which error UI is presented for the new tab page. |
| 586 base::TimeTicks auth_error_time_; | 593 base::TimeTicks auth_error_time_; |
| 587 | 594 |
| 588 // Factory used to create various dependent objects. | 595 // Factory used to create various dependent objects. |
| 589 ProfileSyncComponentsFactory* factory_; | 596 scoped_ptr<ProfileSyncComponentsFactory> factory_; |
| 590 | 597 |
| 591 // The profile whose data we are synchronizing. | 598 // The profile whose data we are synchronizing. |
| 592 Profile* profile_; | 599 Profile* profile_; |
| 593 | 600 |
| 594 // The class that handles getting, setting, and persisting sync | 601 // The class that handles getting, setting, and persisting sync |
| 595 // preferences. | 602 // preferences. |
| 596 browser_sync::SyncPrefs sync_prefs_; | 603 browser_sync::SyncPrefs sync_prefs_; |
| 597 | 604 |
| 598 // TODO(ncarter): Put this in a profile, once there is UI for it. | 605 // TODO(ncarter): Put this in a profile, once there is UI for it. |
| 599 // This specifies where to find the sync server. | 606 // This specifies where to find the sync server. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 backend_unrecoverable_error_handler_; | 707 backend_unrecoverable_error_handler_; |
| 701 | 708 |
| 702 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 709 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 703 }; | 710 }; |
| 704 | 711 |
| 705 bool ShouldShowActionOnUI( | 712 bool ShouldShowActionOnUI( |
| 706 const browser_sync::SyncProtocolError& error); | 713 const browser_sync::SyncProtocolError& error); |
| 707 | 714 |
| 708 | 715 |
| 709 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 716 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| OLD | NEW |