| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread.h" |
| 14 #include "components/sync/base/sync_prefs.h" |
| 15 #include "components/sync/base/unrecoverable_error_handler.h" |
| 16 #include "components/sync/base/weak_handle.h" |
| 17 #include "components/sync/driver/signin_manager_wrapper.h" |
| 18 #include "components/sync/driver/sync_client.h" |
| 19 #include "components/sync/driver/sync_service.h" |
| 20 #include "components/sync/engine/sync_engine.h" |
| 21 #include "components/sync/engine/sync_engine_host.h" |
| 22 #include "components/sync/engine/sync_manager.h" |
| 23 #include "components/sync/js/sync_js_controller.h" |
| 24 #include "components/version_info/version_info.h" |
| 25 |
| 26 namespace syncer { |
| 27 |
| 28 // This is a base class for implementations of SyncService that contains some |
| 29 // common functionality and member variables. Anything that can live inside the |
| 30 // sync component should eventually live here instead of a concrete |
| 31 // implementation. This is set up as a base class so things can be transferred |
| 32 // piece by piece as easily as possible. |
| 33 class SyncServiceBase : public SyncService, public SyncEngineHost { |
| 34 public: |
| 35 SyncServiceBase(std::unique_ptr<SyncClient> sync_client, |
| 36 std::unique_ptr<SigninManagerWrapper> signin, |
| 37 const version_info::Channel& channel, |
| 38 const base::FilePath& base_directory, |
| 39 const std::string& debug_identifier); |
| 40 ~SyncServiceBase() override; |
| 41 |
| 42 protected: |
| 43 // Kicks off asynchronous initialization of the SyncEngine. |
| 44 void InitializeEngine(); |
| 45 |
| 46 // Returns SyncCredentials from the OAuth2TokenService. |
| 47 virtual SyncCredentials GetCredentials() = 0; |
| 48 |
| 49 // Returns a weak handle to the JsEventHandler. |
| 50 virtual WeakHandle<JsEventHandler> GetJsEventHandler() = 0; |
| 51 |
| 52 // Returns a callback that makes an HttpPostProviderFactory. |
| 53 virtual SyncEngine::HttpPostProviderFactoryGetter |
| 54 MakeHttpPostProviderFactoryGetter() = 0; |
| 55 |
| 56 // Takes the previously saved nigori state; null if there isn't any. |
| 57 virtual std::unique_ptr<SyncEncryptionHandler::NigoriState> |
| 58 MoveSavedNigoriState() = 0; |
| 59 |
| 60 // Returns a weak handle to an UnrecoverableErrorHandler (may be |this|). |
| 61 virtual WeakHandle<UnrecoverableErrorHandler> |
| 62 GetUnrecoverableErrorHandler() = 0; |
| 63 |
| 64 // This profile's SyncClient, which abstracts away non-Sync dependencies and |
| 65 // the Sync API component factory. |
| 66 const std::unique_ptr<SyncClient> sync_client_; |
| 67 |
| 68 // Encapsulates user signin - used to set/get the user's authenticated |
| 69 // email address. |
| 70 const std::unique_ptr<SigninManagerWrapper> signin_; |
| 71 |
| 72 // The product channel of the embedder. |
| 73 const version_info::Channel channel_; |
| 74 |
| 75 // The path to the base directory under which sync should store its |
| 76 // information. |
| 77 const base::FilePath base_directory_; |
| 78 |
| 79 // The full path to the sync data directory. |
| 80 const base::FilePath directory_path_; |
| 81 |
| 82 // An identifier representing this instance for debugging purposes. |
| 83 const std::string debug_identifier_; |
| 84 |
| 85 // The class that handles getting, setting, and persisting sync |
| 86 // preferences. |
| 87 SyncPrefs sync_prefs_; |
| 88 |
| 89 // The thread where all the sync operations happen. This thread is kept alive |
| 90 // until browser shutdown and reused if sync is turned off and on again. It is |
| 91 // joined during the shutdown process, but there is an abort mechanism in |
| 92 // place to prevent slow HTTP requests from blocking browser shutdown. |
| 93 std::unique_ptr<base::Thread> sync_thread_; |
| 94 |
| 95 // Our asynchronous engine to communicate with sync components living on |
| 96 // other threads. |
| 97 std::unique_ptr<SyncEngine> engine_; |
| 98 |
| 99 private: |
| 100 bool GetLocalSyncConfig(base::FilePath* local_sync_backend_folder) const; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(SyncServiceBase); |
| 103 }; |
| 104 |
| 105 } // namespace syncer |
| 106 |
| 107 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ |
| OLD | NEW |