Chromium Code Reviews| 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. | |
|
skym
2016/12/14 19:02:35
Common functionality? Between who? Me, myself, and
maxbogue
2016/12/14 19:38:09
I updated the comment. Anything that can be inside
| |
| 30 class SyncServiceBase : public SyncService, public SyncEngineHost { | |
| 31 public: | |
| 32 SyncServiceBase(std::unique_ptr<SyncClient> sync_client, | |
| 33 std::unique_ptr<SigninManagerWrapper> signin, | |
| 34 const version_info::Channel& channel, | |
| 35 const base::FilePath& base_directory, | |
| 36 const std::string& debug_identifier); | |
| 37 ~SyncServiceBase() override; | |
| 38 | |
| 39 protected: | |
| 40 // Kicks off asynchronous initialization of the SyncEngine. | |
| 41 void InitializeEngine(); | |
| 42 | |
| 43 // Returns SyncCredentials from the OAuth2TokenService. | |
| 44 virtual SyncCredentials GetCredentials() = 0; | |
| 45 | |
| 46 // Returns a weak handle to the JsEventHandler. | |
| 47 virtual WeakHandle<JsEventHandler> GetJsEventHandler() = 0; | |
| 48 | |
| 49 // Returns a callback that makes an HttpPostProviderFactory. | |
| 50 virtual SyncEngine::HttpPostProviderFactoryGetter | |
| 51 MakeHttpPostProviderFactoryGetter() = 0; | |
| 52 | |
| 53 // Takes the previously saved nigori state; null if there isn't any. | |
| 54 virtual std::unique_ptr<SyncEncryptionHandler::NigoriState> | |
| 55 MoveSavedNigoriState() = 0; | |
| 56 | |
| 57 // Returns a weak handle to an UnrecoverableErrorHandler (may be |this|). | |
| 58 virtual WeakHandle<UnrecoverableErrorHandler> | |
| 59 GetUnrecoverableErrorHandler() = 0; | |
| 60 | |
| 61 // This profile's SyncClient, which abstracts away non-Sync dependencies and | |
| 62 // the Sync API component factory. | |
| 63 const std::unique_ptr<SyncClient> sync_client_; | |
| 64 | |
| 65 // Encapsulates user signin - used to set/get the user's authenticated | |
| 66 // email address. | |
| 67 const std::unique_ptr<SigninManagerWrapper> signin_; | |
| 68 | |
| 69 // The product channel of the embedder. | |
| 70 const version_info::Channel channel_; | |
| 71 | |
| 72 // The path to the base directory under which sync should store its | |
| 73 // information. | |
| 74 const base::FilePath base_directory_; | |
| 75 | |
| 76 // The full path to the sync data directory. | |
| 77 const base::FilePath directory_path_; | |
| 78 | |
| 79 // An identifier representing this instance for debugging purposes. | |
| 80 const std::string debug_identifier_; | |
| 81 | |
| 82 // The class that handles getting, setting, and persisting sync | |
| 83 // preferences. | |
| 84 SyncPrefs sync_prefs_; | |
| 85 | |
| 86 // The thread where all the sync operations happen. This thread is kept alive | |
| 87 // until browser shutdown and reused if sync is turned off and on again. It is | |
| 88 // joined during the shutdown process, but there is an abort mechanism in | |
| 89 // place to prevent slow HTTP requests from blocking browser shutdown. | |
| 90 std::unique_ptr<base::Thread> sync_thread_; | |
| 91 | |
| 92 // Our asynchronous engine to communicate with sync components living on | |
| 93 // other threads. | |
| 94 std::unique_ptr<SyncEngine> engine_; | |
| 95 | |
| 96 private: | |
| 97 bool GetLocalSyncConfig(base::FilePath* local_sync_backend_folder) const; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(SyncServiceBase); | |
| 100 }; | |
| 101 | |
| 102 } // namespace syncer | |
| 103 | |
| 104 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ | |
| OLD | NEW |