OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H |
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
12 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" | 15 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" |
15 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | 16 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
16 #include "components/proximity_auth/cryptauth/sync_scheduler.h" | 17 #include "components/proximity_auth/cryptauth/sync_scheduler.h" |
17 | 18 |
18 class PrefService; | 19 class PrefService; |
19 class PrefRegistrySimple; | 20 class PrefRegistrySimple; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 }; | 58 }; |
58 | 59 |
59 // Creates the manager: | 60 // Creates the manager: |
60 // |clock|: Used to determine the time between sync attempts. | 61 // |clock|: Used to determine the time between sync attempts. |
61 // |client_factory|: Creates CryptAuthClient instances to perform each sync. | 62 // |client_factory|: Creates CryptAuthClient instances to perform each sync. |
62 // |gcm_manager|: Notifies when GCM push messages trigger device syncs. | 63 // |gcm_manager|: Notifies when GCM push messages trigger device syncs. |
63 // Not owned and must outlive this instance. | 64 // Not owned and must outlive this instance. |
64 // |pref_service|: Stores syncing metadata and unlock key information to | 65 // |pref_service|: Stores syncing metadata and unlock key information to |
65 // persist across browser restarts. Must already be registered | 66 // persist across browser restarts. Must already be registered |
66 // with RegisterPrefs(). | 67 // with RegisterPrefs(). |
67 CryptAuthDeviceManager(scoped_ptr<base::Clock> clock, | 68 CryptAuthDeviceManager(std::unique_ptr<base::Clock> clock, |
68 scoped_ptr<CryptAuthClientFactory> client_factory, | 69 std::unique_ptr<CryptAuthClientFactory> client_factory, |
69 CryptAuthGCMManager* gcm_manager, | 70 CryptAuthGCMManager* gcm_manager, |
70 PrefService* pref_service); | 71 PrefService* pref_service); |
71 | 72 |
72 ~CryptAuthDeviceManager() override; | 73 ~CryptAuthDeviceManager() override; |
73 | 74 |
74 // Registers the prefs used by this class to the given |registry|. | 75 // Registers the prefs used by this class to the given |registry|. |
75 static void RegisterPrefs(PrefRegistrySimple* registry); | 76 static void RegisterPrefs(PrefRegistrySimple* registry); |
76 | 77 |
77 // Starts device manager to begin syncing devices. | 78 // Starts device manager to begin syncing devices. |
78 void Start(); | 79 void Start(); |
(...skipping 25 matching lines...) Expand all Loading... |
104 // has ever been recorded, then this function will also return true. | 105 // has ever been recorded, then this function will also return true. |
105 bool IsRecoveringFromFailure() const; | 106 bool IsRecoveringFromFailure() const; |
106 | 107 |
107 // Returns a list of remote devices that can unlock the user's other devices. | 108 // Returns a list of remote devices that can unlock the user's other devices. |
108 const std::vector<cryptauth::ExternalDeviceInfo>& unlock_keys() const { | 109 const std::vector<cryptauth::ExternalDeviceInfo>& unlock_keys() const { |
109 return unlock_keys_; | 110 return unlock_keys_; |
110 } | 111 } |
111 | 112 |
112 protected: | 113 protected: |
113 // Creates a new SyncScheduler instance. Exposed for testing. | 114 // Creates a new SyncScheduler instance. Exposed for testing. |
114 virtual scoped_ptr<SyncScheduler> CreateSyncScheduler(); | 115 virtual std::unique_ptr<SyncScheduler> CreateSyncScheduler(); |
115 | 116 |
116 private: | 117 private: |
117 // CryptAuthGCMManager::Observer: | 118 // CryptAuthGCMManager::Observer: |
118 void OnResyncMessage() override; | 119 void OnResyncMessage() override; |
119 | 120 |
120 // Updates |unlock_keys_| by fetching the list stored in |pref_service_|. | 121 // Updates |unlock_keys_| by fetching the list stored in |pref_service_|. |
121 void UpdateUnlockKeysFromPrefs(); | 122 void UpdateUnlockKeysFromPrefs(); |
122 | 123 |
123 // SyncScheduler::Delegate: | 124 // SyncScheduler::Delegate: |
124 void OnSyncRequested( | 125 void OnSyncRequested( |
125 scoped_ptr<SyncScheduler::SyncRequest> sync_request) override; | 126 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override; |
126 | 127 |
127 // Callback when |cryptauth_client_| completes with the response. | 128 // Callback when |cryptauth_client_| completes with the response. |
128 void OnGetMyDevicesSuccess(const cryptauth::GetMyDevicesResponse& response); | 129 void OnGetMyDevicesSuccess(const cryptauth::GetMyDevicesResponse& response); |
129 void OnGetMyDevicesFailure(const std::string& error); | 130 void OnGetMyDevicesFailure(const std::string& error); |
130 | 131 |
131 // Used to determine the time. | 132 // Used to determine the time. |
132 scoped_ptr<base::Clock> clock_; | 133 std::unique_ptr<base::Clock> clock_; |
133 | 134 |
134 // Creates CryptAuthClient instances for each sync attempt. | 135 // Creates CryptAuthClient instances for each sync attempt. |
135 scoped_ptr<CryptAuthClientFactory> client_factory_; | 136 std::unique_ptr<CryptAuthClientFactory> client_factory_; |
136 | 137 |
137 // Notifies when GCM push messages trigger device sync. Not owned and must | 138 // Notifies when GCM push messages trigger device sync. Not owned and must |
138 // outlive this instance. | 139 // outlive this instance. |
139 CryptAuthGCMManager* gcm_manager_; | 140 CryptAuthGCMManager* gcm_manager_; |
140 | 141 |
141 // Contains preferences that outlive the lifetime of this object and across | 142 // Contains preferences that outlive the lifetime of this object and across |
142 // process restarts. |pref_service_| must outlive the lifetime of this | 143 // process restarts. |pref_service_| must outlive the lifetime of this |
143 // instance. | 144 // instance. |
144 PrefService* const pref_service_; | 145 PrefService* const pref_service_; |
145 | 146 |
146 // The unlock keys currently synced from CryptAuth. | 147 // The unlock keys currently synced from CryptAuth. |
147 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys_; | 148 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys_; |
148 | 149 |
149 // Schedules the time between device sync attempts. | 150 // Schedules the time between device sync attempts. |
150 scoped_ptr<SyncScheduler> scheduler_; | 151 std::unique_ptr<SyncScheduler> scheduler_; |
151 | 152 |
152 // Contains the SyncRequest that |scheduler_| requests when a device sync | 153 // Contains the SyncRequest that |scheduler_| requests when a device sync |
153 // attempt is made. | 154 // attempt is made. |
154 scoped_ptr<SyncScheduler::SyncRequest> sync_request_; | 155 std::unique_ptr<SyncScheduler::SyncRequest> sync_request_; |
155 | 156 |
156 // The CryptAuthEnroller instance for the current sync attempt. A new | 157 // The CryptAuthEnroller instance for the current sync attempt. A new |
157 // instance will be created for each individual attempt. | 158 // instance will be created for each individual attempt. |
158 scoped_ptr<CryptAuthClient> cryptauth_client_; | 159 std::unique_ptr<CryptAuthClient> cryptauth_client_; |
159 | 160 |
160 // List of observers. | 161 // List of observers. |
161 base::ObserverList<Observer> observers_; | 162 base::ObserverList<Observer> observers_; |
162 | 163 |
163 base::WeakPtrFactory<CryptAuthDeviceManager> weak_ptr_factory_; | 164 base::WeakPtrFactory<CryptAuthDeviceManager> weak_ptr_factory_; |
164 | 165 |
165 DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceManager); | 166 DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceManager); |
166 }; | 167 }; |
167 | 168 |
168 } // namespace proximity_auth | 169 } // namespace proximity_auth |
169 | 170 |
170 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H | 171 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H |
OLD | NEW |