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 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
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/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/memory/memory_pressure_listener.h" | 17 #include "base/memory/memory_pressure_listener.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "base/threading/thread_checker.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "base/timer/timer.h" | 24 #include "base/timer/timer.h" |
24 #include "chrome/browser/sync/glue/sync_backend_host.h" | 25 #include "chrome/browser/sync/glue/sync_backend_host.h" |
25 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" | 26 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
26 #include "components/keyed_service/core/keyed_service.h" | 27 #include "components/keyed_service/core/keyed_service.h" |
27 #include "components/signin/core/browser/signin_manager_base.h" | 28 #include "components/signin/core/browser/signin_manager_base.h" |
28 #include "components/sync_driver/backup_rollback_controller.h" | 29 #include "components/sync_driver/backup_rollback_controller.h" |
29 #include "components/sync_driver/data_type_controller.h" | 30 #include "components/sync_driver/data_type_controller.h" |
30 #include "components/sync_driver/data_type_manager.h" | 31 #include "components/sync_driver/data_type_manager.h" |
31 #include "components/sync_driver/data_type_manager_observer.h" | 32 #include "components/sync_driver/data_type_manager_observer.h" |
32 #include "components/sync_driver/data_type_status_table.h" | 33 #include "components/sync_driver/data_type_status_table.h" |
33 #include "components/sync_driver/device_info_sync_service.h" | 34 #include "components/sync_driver/device_info_sync_service.h" |
34 #include "components/sync_driver/local_device_info_provider.h" | 35 #include "components/sync_driver/local_device_info_provider.h" |
35 #include "components/sync_driver/protocol_event_observer.h" | 36 #include "components/sync_driver/protocol_event_observer.h" |
36 #include "components/sync_driver/startup_controller.h" | 37 #include "components/sync_driver/startup_controller.h" |
37 #include "components/sync_driver/sync_client.h" | 38 #include "components/sync_driver/sync_client.h" |
38 #include "components/sync_driver/sync_frontend.h" | 39 #include "components/sync_driver/sync_frontend.h" |
39 #include "components/sync_driver/sync_prefs.h" | 40 #include "components/sync_driver/sync_prefs.h" |
40 #include "components/sync_driver/sync_service.h" | 41 #include "components/sync_driver/sync_service.h" |
41 #include "components/sync_driver/sync_stopped_reporter.h" | 42 #include "components/sync_driver/sync_stopped_reporter.h" |
| 43 #include "components/version_info/version_info.h" |
42 #include "content/public/browser/notification_observer.h" | 44 #include "content/public/browser/notification_observer.h" |
43 #include "content/public/browser/notification_registrar.h" | 45 #include "content/public/browser/notification_registrar.h" |
44 #include "google_apis/gaia/google_service_auth_error.h" | 46 #include "google_apis/gaia/google_service_auth_error.h" |
45 #include "google_apis/gaia/oauth2_token_service.h" | 47 #include "google_apis/gaia/oauth2_token_service.h" |
46 #include "net/base/backoff_entry.h" | 48 #include "net/base/backoff_entry.h" |
47 #include "sync/internal_api/public/base/model_type.h" | 49 #include "sync/internal_api/public/base/model_type.h" |
48 #include "sync/internal_api/public/engine/model_safe_worker.h" | 50 #include "sync/internal_api/public/engine/model_safe_worker.h" |
49 #include "sync/internal_api/public/network_time_update_callback.h" | 51 #include "sync/internal_api/public/network_time_update_callback.h" |
50 #include "sync/internal_api/public/shutdown_reason.h" | 52 #include "sync/internal_api/public/shutdown_reason.h" |
51 #include "sync/internal_api/public/sync_manager_factory.h" | 53 #include "sync/internal_api/public/sync_manager_factory.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 ROLLBACK // Backend for rollback. | 232 ROLLBACK // Backend for rollback. |
231 }; | 233 }; |
232 | 234 |
233 // Takes ownership of |factory| and |signin_wrapper|. | 235 // Takes ownership of |factory| and |signin_wrapper|. |
234 ProfileSyncService( | 236 ProfileSyncService( |
235 scoped_ptr<sync_driver::SyncClient> sync_client, | 237 scoped_ptr<sync_driver::SyncClient> sync_client, |
236 Profile* profile, | 238 Profile* profile, |
237 scoped_ptr<SigninManagerWrapper> signin_wrapper, | 239 scoped_ptr<SigninManagerWrapper> signin_wrapper, |
238 ProfileOAuth2TokenService* oauth2_token_service, | 240 ProfileOAuth2TokenService* oauth2_token_service, |
239 browser_sync::ProfileSyncServiceStartBehavior start_behavior, | 241 browser_sync::ProfileSyncServiceStartBehavior start_behavior, |
240 const syncer::NetworkTimeUpdateCallback& network_time_update_callback); | 242 const syncer::NetworkTimeUpdateCallback& network_time_update_callback, |
| 243 base::FilePath base_directory, |
| 244 net::URLRequestContextGetter* url_request_context, |
| 245 std::string debug_identifier, |
| 246 version_info::Channel channel, |
| 247 scoped_refptr<base::SingleThreadTaskRunner> db_thread, |
| 248 scoped_refptr<base::SingleThreadTaskRunner> file_thread, |
| 249 base::SequencedWorkerPool* blocking_pool); |
241 ~ProfileSyncService() override; | 250 ~ProfileSyncService() override; |
242 | 251 |
243 // Initializes the object. This must be called at most once, and | 252 // Initializes the object. This must be called at most once, and |
244 // immediately after an object of this class is constructed. | 253 // immediately after an object of this class is constructed. |
245 void Initialize(); | 254 void Initialize(); |
246 | 255 |
247 // sync_driver::SyncService implementation | 256 // sync_driver::SyncService implementation |
248 bool HasSyncSetupCompleted() const override; | 257 bool HasSyncSetupCompleted() const override; |
249 bool IsSyncAllowed() const override; | 258 bool IsSyncAllowed() const override; |
250 bool IsSyncActive() const override; | 259 bool IsSyncActive() const override; |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 // Calls sync backend to send ClearServerDataMessage to server. | 784 // Calls sync backend to send ClearServerDataMessage to server. |
776 void ClearAndRestartSyncForPassphraseEncryption(); | 785 void ClearAndRestartSyncForPassphraseEncryption(); |
777 | 786 |
778 // Restarts sync clearing directory in the process. | 787 // Restarts sync clearing directory in the process. |
779 void OnClearServerDataDone(); | 788 void OnClearServerDataDone(); |
780 | 789 |
781 // This profile's SyncClient, which abstracts away non-Sync dependencies and | 790 // This profile's SyncClient, which abstracts away non-Sync dependencies and |
782 // the Sync API component factory. | 791 // the Sync API component factory. |
783 scoped_ptr<sync_driver::SyncClient> sync_client_; | 792 scoped_ptr<sync_driver::SyncClient> sync_client_; |
784 | 793 |
785 // The profile whose data we are synchronizing. | |
786 Profile* profile_; | |
787 | |
788 // The class that handles getting, setting, and persisting sync | 794 // The class that handles getting, setting, and persisting sync |
789 // preferences. | 795 // preferences. |
790 sync_driver::SyncPrefs sync_prefs_; | 796 sync_driver::SyncPrefs sync_prefs_; |
791 | 797 |
792 // TODO(ncarter): Put this in a profile, once there is UI for it. | 798 // TODO(ncarter): Put this in a profile, once there is UI for it. |
793 // This specifies where to find the sync server. | 799 // This specifies where to find the sync server. |
794 const GURL sync_service_url_; | 800 const GURL sync_service_url_; |
795 | 801 |
796 // The time that OnConfigureStart is called. This member is zero if | 802 // The time that OnConfigureStart is called. This member is zero if |
797 // OnConfigureStart has not yet been called, and is reset to zero once | 803 // OnConfigureStart has not yet been called, and is reset to zero once |
798 // OnConfigureDone is called. | 804 // OnConfigureDone is called. |
799 base::Time sync_configure_start_time_; | 805 base::Time sync_configure_start_time_; |
800 | 806 |
801 // Callback to update the network time; used for initializing the backend. | 807 // Callback to update the network time; used for initializing the backend. |
802 syncer::NetworkTimeUpdateCallback network_time_update_callback_; | 808 syncer::NetworkTimeUpdateCallback network_time_update_callback_; |
803 | 809 |
| 810 // The path to the base directory under which sync should store its |
| 811 // information. |
| 812 base::FilePath base_directory_; |
| 813 |
| 814 // The request context in which sync should operate. |
| 815 net::URLRequestContextGetter* url_request_context_; |
| 816 |
| 817 // An identifier representing this instance for debugging purposes. |
| 818 std::string debug_identifier_; |
| 819 |
| 820 // The product channel of the embedder. |
| 821 version_info::Channel channel_; |
| 822 |
| 823 // Threading context. |
| 824 scoped_refptr<base::SingleThreadTaskRunner> db_thread_; |
| 825 scoped_refptr<base::SingleThreadTaskRunner> file_thread_; |
| 826 base::SequencedWorkerPool* blocking_pool_; |
| 827 |
804 // Indicates if this is the first time sync is being configured. This value | 828 // Indicates if this is the first time sync is being configured. This value |
805 // is equal to !HasSyncSetupCompleted() at the time of OnBackendInitialized(). | 829 // is equal to !HasSyncSetupCompleted() at the time of OnBackendInitialized(). |
806 bool is_first_time_sync_configure_; | 830 bool is_first_time_sync_configure_; |
807 | 831 |
808 // List of available data type controllers. | 832 // List of available data type controllers. |
809 sync_driver::DataTypeController::TypeMap data_type_controllers_; | 833 sync_driver::DataTypeController::TypeMap data_type_controllers_; |
810 | 834 |
811 // Whether the SyncBackendHost has been initialized. | 835 // Whether the SyncBackendHost has been initialized. |
812 bool backend_initialized_; | 836 bool backend_initialized_; |
813 | 837 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 bool catch_up_configure_in_progress_; | 991 bool catch_up_configure_in_progress_; |
968 | 992 |
969 // Whether the major version has changed since the last time Chrome ran, | 993 // Whether the major version has changed since the last time Chrome ran, |
970 // and therefore a passphrase required state should result in prompting | 994 // and therefore a passphrase required state should result in prompting |
971 // the user. This logic is only enabled on platforms that consume the | 995 // the user. This logic is only enabled on platforms that consume the |
972 // IsPassphrasePrompted sync preference. | 996 // IsPassphrasePrompted sync preference. |
973 bool passphrase_prompt_triggered_by_version_; | 997 bool passphrase_prompt_triggered_by_version_; |
974 | 998 |
975 content::NotificationRegistrar registrar_; | 999 content::NotificationRegistrar registrar_; |
976 | 1000 |
| 1001 // Used to ensure that certain operations are performed on the thread that |
| 1002 // this object was created on. |
| 1003 base::ThreadChecker thread_checker_; |
| 1004 |
977 base::WeakPtrFactory<ProfileSyncService> weak_factory_; | 1005 base::WeakPtrFactory<ProfileSyncService> weak_factory_; |
978 | 1006 |
979 // We don't use |weak_factory_| for the StartupController because the weak | 1007 // We don't use |weak_factory_| for the StartupController because the weak |
980 // ptrs should be bound to the lifetime of ProfileSyncService and not to the | 1008 // ptrs should be bound to the lifetime of ProfileSyncService and not to the |
981 // [Initialize -> sync disabled/shutdown] lifetime. We don't pass | 1009 // [Initialize -> sync disabled/shutdown] lifetime. We don't pass |
982 // StartupController an Unretained reference to future-proof against | 1010 // StartupController an Unretained reference to future-proof against |
983 // the controller impl changing to post tasks. Therefore, we have a separate | 1011 // the controller impl changing to post tasks. Therefore, we have a separate |
984 // factory. | 1012 // factory. |
985 base::WeakPtrFactory<ProfileSyncService> startup_controller_weak_factory_; | 1013 base::WeakPtrFactory<ProfileSyncService> startup_controller_weak_factory_; |
986 | 1014 |
987 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 1015 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
988 }; | 1016 }; |
989 | 1017 |
990 bool ShouldShowActionOnUI( | 1018 bool ShouldShowActionOnUI( |
991 const syncer::SyncProtocolError& error); | 1019 const syncer::SyncProtocolError& error); |
992 | 1020 |
993 | 1021 |
994 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 1022 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
OLD | NEW |