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

Side by Side Diff: components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h

Issue 1912433002: Convert //components/proximity_auth from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 8 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
OLDNEW
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_ENROLLMENT_MANAGER_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H 6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_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/time.h" 13 #include "base/time/time.h"
13 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" 14 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h"
14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" 15 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
15 #include "components/proximity_auth/cryptauth/sync_scheduler.h" 16 #include "components/proximity_auth/cryptauth/sync_scheduler.h"
16 17
17 class PrefRegistrySimple; 18 class PrefRegistrySimple;
18 class PrefService; 19 class PrefService;
19 20
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // |secure_message_delegate|: Used to generate the user's keypair if it does 55 // |secure_message_delegate|: Used to generate the user's keypair if it does
55 // not exist. 56 // not exist.
56 // |device_info|: Contains information about the local device that will be 57 // |device_info|: Contains information about the local device that will be
57 // uploaded to CryptAuth with each enrollment request. 58 // uploaded to CryptAuth with each enrollment request.
58 // |gcm_manager|: Used to perform GCM registrations and also notifies when GCM 59 // |gcm_manager|: Used to perform GCM registrations and also notifies when GCM
59 // push messages trigger re-enrollments. 60 // push messages trigger re-enrollments.
60 // Not owned and must outlive this instance. 61 // Not owned and must outlive this instance.
61 // |pref_service|: Contains preferences across browser restarts, and should 62 // |pref_service|: Contains preferences across browser restarts, and should
62 // have been registered through RegisterPrefs(). 63 // have been registered through RegisterPrefs().
63 CryptAuthEnrollmentManager( 64 CryptAuthEnrollmentManager(
64 scoped_ptr<base::Clock> clock, 65 std::unique_ptr<base::Clock> clock,
65 scoped_ptr<CryptAuthEnrollerFactory> enroller_factory, 66 std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
66 scoped_ptr<SecureMessageDelegate> secure_message_delegate, 67 std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
67 const cryptauth::GcmDeviceInfo& device_info, 68 const cryptauth::GcmDeviceInfo& device_info,
68 CryptAuthGCMManager* gcm_manager, 69 CryptAuthGCMManager* gcm_manager,
69 PrefService* pref_service); 70 PrefService* pref_service);
70 71
71 ~CryptAuthEnrollmentManager() override; 72 ~CryptAuthEnrollmentManager() override;
72 73
73 // Registers the prefs used by this class to the given |pref_service|. 74 // Registers the prefs used by this class to the given |pref_service|.
74 static void RegisterPrefs(PrefRegistrySimple* registry); 75 static void RegisterPrefs(PrefRegistrySimple* registry);
75 76
76 // Begins scheduling periodic enrollment attempts. 77 // Begins scheduling periodic enrollment attempts.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 110
110 // Returns the keypair used to enroll with CryptAuth. If no enrollment has 111 // Returns the keypair used to enroll with CryptAuth. If no enrollment has
111 // been completed, then an empty string will be returned. 112 // been completed, then an empty string will be returned.
112 // Note: These keys are really serialized protocol buffer messages, and should 113 // Note: These keys are really serialized protocol buffer messages, and should
113 // only be used by passing to SecureMessageDelegate. 114 // only be used by passing to SecureMessageDelegate.
114 std::string GetUserPublicKey(); 115 std::string GetUserPublicKey();
115 std::string GetUserPrivateKey(); 116 std::string GetUserPrivateKey();
116 117
117 protected: 118 protected:
118 // Creates a new SyncScheduler instance. Exposed for testing. 119 // Creates a new SyncScheduler instance. Exposed for testing.
119 virtual scoped_ptr<SyncScheduler> CreateSyncScheduler(); 120 virtual std::unique_ptr<SyncScheduler> CreateSyncScheduler();
120 121
121 private: 122 private:
122 // CryptAuthGCMManager::Observer: 123 // CryptAuthGCMManager::Observer:
123 void OnGCMRegistrationResult(bool success) override; 124 void OnGCMRegistrationResult(bool success) override;
124 void OnReenrollMessage() override; 125 void OnReenrollMessage() override;
125 126
126 // Callback when a new keypair is generated. 127 // Callback when a new keypair is generated.
127 void OnKeyPairGenerated(const std::string& public_key, 128 void OnKeyPairGenerated(const std::string& public_key,
128 const std::string& private_key); 129 const std::string& private_key);
129 130
130 // SyncScheduler::Delegate: 131 // SyncScheduler::Delegate:
131 void OnSyncRequested( 132 void OnSyncRequested(
132 scoped_ptr<SyncScheduler::SyncRequest> sync_request) override; 133 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override;
133 134
134 // Starts a CryptAuth enrollment attempt, generating a new keypair if one is 135 // Starts a CryptAuth enrollment attempt, generating a new keypair if one is
135 // not already stored in the user prefs. 136 // not already stored in the user prefs.
136 void DoCryptAuthEnrollment(); 137 void DoCryptAuthEnrollment();
137 138
138 // Starts a CryptAuth enrollment attempt, after a key-pair is stored in the 139 // Starts a CryptAuth enrollment attempt, after a key-pair is stored in the
139 // user prefs. 140 // user prefs.
140 void DoCryptAuthEnrollmentWithKeys(); 141 void DoCryptAuthEnrollmentWithKeys();
141 142
142 // Callback when |cryptauth_enroller_| completes. 143 // Callback when |cryptauth_enroller_| completes.
143 void OnEnrollmentFinished(bool success); 144 void OnEnrollmentFinished(bool success);
144 145
145 // Used to determine the time. 146 // Used to determine the time.
146 scoped_ptr<base::Clock> clock_; 147 std::unique_ptr<base::Clock> clock_;
147 148
148 // Creates CryptAuthEnroller instances for each enrollment attempt. 149 // Creates CryptAuthEnroller instances for each enrollment attempt.
149 scoped_ptr<CryptAuthEnrollerFactory> enroller_factory_; 150 std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory_;
150 151
151 // The SecureMessageDelegate used to generate the user's keypair if it does 152 // The SecureMessageDelegate used to generate the user's keypair if it does
152 // not already exist. 153 // not already exist.
153 scoped_ptr<SecureMessageDelegate> secure_message_delegate_; 154 std::unique_ptr<SecureMessageDelegate> secure_message_delegate_;
154 155
155 // The local device information to upload to CryptAuth. 156 // The local device information to upload to CryptAuth.
156 const cryptauth::GcmDeviceInfo device_info_; 157 const cryptauth::GcmDeviceInfo device_info_;
157 158
158 // Used to perform GCM registrations and also notifies when GCM push messages 159 // Used to perform GCM registrations and also notifies when GCM push messages
159 // trigger re-enrollments. Not owned and must outlive this instance. 160 // trigger re-enrollments. Not owned and must outlive this instance.
160 CryptAuthGCMManager* gcm_manager_; 161 CryptAuthGCMManager* gcm_manager_;
161 162
162 // Contains perferences that outlive the lifetime of this object and across 163 // Contains perferences that outlive the lifetime of this object and across
163 // process restarts. 164 // process restarts.
164 // Not owned and must outlive this instance. 165 // Not owned and must outlive this instance.
165 PrefService* pref_service_; 166 PrefService* pref_service_;
166 167
167 // Schedules the time between enrollment attempts. 168 // Schedules the time between enrollment attempts.
168 scoped_ptr<SyncScheduler> scheduler_; 169 std::unique_ptr<SyncScheduler> scheduler_;
169 170
170 // Contains the SyncRequest that |scheduler_| requests when an enrollment 171 // Contains the SyncRequest that |scheduler_| requests when an enrollment
171 // attempt is made. 172 // attempt is made.
172 scoped_ptr<SyncScheduler::SyncRequest> sync_request_; 173 std::unique_ptr<SyncScheduler::SyncRequest> sync_request_;
173 174
174 // The CryptAuthEnroller instance for the current enrollment attempt. A new 175 // The CryptAuthEnroller instance for the current enrollment attempt. A new
175 // instance will be created for each individual attempt. 176 // instance will be created for each individual attempt.
176 scoped_ptr<CryptAuthEnroller> cryptauth_enroller_; 177 std::unique_ptr<CryptAuthEnroller> cryptauth_enroller_;
177 178
178 // List of observers. 179 // List of observers.
179 base::ObserverList<Observer> observers_; 180 base::ObserverList<Observer> observers_;
180 181
181 base::WeakPtrFactory<CryptAuthEnrollmentManager> weak_ptr_factory_; 182 base::WeakPtrFactory<CryptAuthEnrollmentManager> weak_ptr_factory_;
182 183
183 DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollmentManager); 184 DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollmentManager);
184 }; 185 };
185 186
186 } // namespace proximity_auth 187 } // namespace proximity_auth
187 188
188 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H 189 #endif // COMPONENTS_PROXIMITY_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698