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

Side by Side Diff: components/sync/driver/sync_service_base.h

Issue 2663783002: [Sync] Split encryption state and logic out of PSS and SBHI. (Closed)
Patch Set: Tweak comment. Created 3 years, 10 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
« no previous file with comments | « components/sync/driver/sync_service.h ('k') | components/sync/driver/sync_service_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ 5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_
6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ 6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
13 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/threading/thread_checker.h"
14 #include "components/sync/base/sync_prefs.h" 17 #include "components/sync/base/sync_prefs.h"
15 #include "components/sync/base/unrecoverable_error_handler.h" 18 #include "components/sync/base/unrecoverable_error_handler.h"
16 #include "components/sync/base/weak_handle.h" 19 #include "components/sync/base/weak_handle.h"
17 #include "components/sync/driver/signin_manager_wrapper.h" 20 #include "components/sync/driver/signin_manager_wrapper.h"
18 #include "components/sync/driver/sync_client.h" 21 #include "components/sync/driver/sync_client.h"
19 #include "components/sync/driver/sync_service.h" 22 #include "components/sync/driver/sync_service.h"
23 #include "components/sync/driver/sync_service_crypto.h"
20 #include "components/sync/engine/sync_engine.h" 24 #include "components/sync/engine/sync_engine.h"
21 #include "components/sync/engine/sync_engine_host.h" 25 #include "components/sync/engine/sync_engine_host.h"
22 #include "components/sync/engine/sync_manager.h" 26 #include "components/sync/engine/sync_manager.h"
23 #include "components/sync/js/sync_js_controller.h" 27 #include "components/sync/js/sync_js_controller.h"
24 #include "components/version_info/version_info.h" 28 #include "components/version_info/version_info.h"
25 29
26 namespace syncer { 30 namespace syncer {
27 31
28 // This is a base class for implementations of SyncService that contains some 32 // This is a base class for implementations of SyncService that contains some
29 // common functionality and member variables. Anything that can live inside the 33 // common functionality and member variables. Anything that can live inside the
30 // sync component should eventually live here instead of a concrete 34 // 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 35 // implementation. This is set up as a base class so things can be transferred
32 // piece by piece as easily as possible. 36 // piece by piece as easily as possible.
33 class SyncServiceBase : public SyncService, public SyncEngineHost { 37 class SyncServiceBase : public SyncService, public SyncEngineHost {
34 public: 38 public:
35 SyncServiceBase(std::unique_ptr<SyncClient> sync_client, 39 SyncServiceBase(std::unique_ptr<SyncClient> sync_client,
36 std::unique_ptr<SigninManagerWrapper> signin, 40 std::unique_ptr<SigninManagerWrapper> signin,
37 const version_info::Channel& channel, 41 const version_info::Channel& channel,
38 const base::FilePath& base_directory, 42 const base::FilePath& base_directory,
39 const std::string& debug_identifier); 43 const std::string& debug_identifier);
40 ~SyncServiceBase() override; 44 ~SyncServiceBase() override;
41 45
46 // SyncService partial implementation.
47 void AddObserver(SyncServiceObserver* observer) override;
48 void RemoveObserver(SyncServiceObserver* observer) override;
49 bool HasObserver(const SyncServiceObserver* observer) const override;
50
42 protected: 51 protected:
52 // Notify all observers that a change has occurred.
53 void NotifyObservers();
54
43 // Kicks off asynchronous initialization of the SyncEngine. 55 // Kicks off asynchronous initialization of the SyncEngine.
44 void InitializeEngine(); 56 void InitializeEngine();
45 57
58 // Destroys the |crypto_| object and creates a new one with fresh state.
59 void ResetCryptoState();
60
46 // Returns SyncCredentials from the OAuth2TokenService. 61 // Returns SyncCredentials from the OAuth2TokenService.
47 virtual SyncCredentials GetCredentials() = 0; 62 virtual SyncCredentials GetCredentials() = 0;
48 63
49 // Returns a weak handle to the JsEventHandler. 64 // Returns a weak handle to the JsEventHandler.
50 virtual WeakHandle<JsEventHandler> GetJsEventHandler() = 0; 65 virtual WeakHandle<JsEventHandler> GetJsEventHandler() = 0;
51 66
52 // Returns a callback that makes an HttpPostProviderFactory. 67 // Returns a callback that makes an HttpPostProviderFactory.
53 virtual SyncEngine::HttpPostProviderFactoryGetter 68 virtual SyncEngine::HttpPostProviderFactoryGetter
54 MakeHttpPostProviderFactoryGetter() = 0; 69 MakeHttpPostProviderFactoryGetter() = 0;
55 70
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|). 71 // Returns a weak handle to an UnrecoverableErrorHandler (may be |this|).
61 virtual WeakHandle<UnrecoverableErrorHandler> 72 virtual WeakHandle<UnrecoverableErrorHandler>
62 GetUnrecoverableErrorHandler() = 0; 73 GetUnrecoverableErrorHandler() = 0;
63 74
64 // This profile's SyncClient, which abstracts away non-Sync dependencies and 75 // This profile's SyncClient, which abstracts away non-Sync dependencies and
65 // the Sync API component factory. 76 // the Sync API component factory.
66 const std::unique_ptr<SyncClient> sync_client_; 77 const std::unique_ptr<SyncClient> sync_client_;
67 78
68 // Encapsulates user signin - used to set/get the user's authenticated 79 // Encapsulates user signin - used to set/get the user's authenticated
69 // email address. 80 // email address.
(...skipping 11 matching lines...) Expand all
81 // Directory files will be selectively targeted instead. 92 // Directory files will be selectively targeted instead.
82 const base::FilePath sync_data_folder_; 93 const base::FilePath sync_data_folder_;
83 94
84 // An identifier representing this instance for debugging purposes. 95 // An identifier representing this instance for debugging purposes.
85 const std::string debug_identifier_; 96 const std::string debug_identifier_;
86 97
87 // The class that handles getting, setting, and persisting sync 98 // The class that handles getting, setting, and persisting sync
88 // preferences. 99 // preferences.
89 SyncPrefs sync_prefs_; 100 SyncPrefs sync_prefs_;
90 101
102 // A utility object containing logic and state relating to encryption. It is
103 // never null.
104 std::unique_ptr<SyncServiceCrypto> crypto_;
105
91 // The thread where all the sync operations happen. This thread is kept alive 106 // The thread where all the sync operations happen. This thread is kept alive
92 // until browser shutdown and reused if sync is turned off and on again. It is 107 // until browser shutdown and reused if sync is turned off and on again. It is
93 // joined during the shutdown process, but there is an abort mechanism in 108 // joined during the shutdown process, but there is an abort mechanism in
94 // place to prevent slow HTTP requests from blocking browser shutdown. 109 // place to prevent slow HTTP requests from blocking browser shutdown.
95 std::unique_ptr<base::Thread> sync_thread_; 110 std::unique_ptr<base::Thread> sync_thread_;
96 111
97 // Our asynchronous engine to communicate with sync components living on 112 // Our asynchronous engine to communicate with sync components living on
98 // other threads. 113 // other threads.
99 std::unique_ptr<SyncEngine> engine_; 114 std::unique_ptr<SyncEngine> engine_;
100 115
116 // The list of observers of the SyncService state.
117 base::ObserverList<SyncServiceObserver> observers_;
118
119 // Used to ensure that certain operations are performed on the thread that
120 // this object was created on.
121 base::ThreadChecker thread_checker_;
122
101 private: 123 private:
102 bool GetLocalSyncConfig(base::FilePath* local_sync_backend_folder) const; 124 bool GetLocalSyncConfig(base::FilePath* local_sync_backend_folder) const;
103 125
104 DISALLOW_COPY_AND_ASSIGN(SyncServiceBase); 126 DISALLOW_COPY_AND_ASSIGN(SyncServiceBase);
105 }; 127 };
106 128
107 } // namespace syncer 129 } // namespace syncer
108 130
109 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_ 131 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_
OLDNEW
« no previous file with comments | « components/sync/driver/sync_service.h ('k') | components/sync/driver/sync_service_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698