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

Side by Side Diff: components/proximity_auth/webui/proximity_auth_webui_handler.cc

Issue 1248533003: Hook up CryptAuthGCMManager to the enrollment and device sync managers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix webui Created 5 years, 4 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/proximity_auth/webui/proximity_auth_webui_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "components/proximity_auth/webui/proximity_auth_webui_handler.h" 5 #include "components/proximity_auth/webui/proximity_auth_webui_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/time_formatting.h" 8 #include "base/i18n/time_formatting.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/time/default_clock.h" 10 #include "base/time/default_clock.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/proximity_auth/cryptauth/base64url.h" 12 #include "components/proximity_auth/cryptauth/base64url.h"
13 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" 13 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h"
14 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.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/logging/logging.h" 16 #include "components/proximity_auth/logging/logging.h"
16 #include "components/proximity_auth/webui/cryptauth_enroller_factory_impl.h" 17 #include "components/proximity_auth/webui/cryptauth_enroller_factory_impl.h"
17 #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h" 18 #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h"
18 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
19 20
20 namespace proximity_auth { 21 namespace proximity_auth {
21 22
22 namespace { 23 namespace {
23 24
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 145
145 web_ui()->RegisterMessageCallback( 146 web_ui()->RegisterMessageCallback(
146 "forceEnrollment", base::Bind(&ProximityAuthWebUIHandler::ForceEnrollment, 147 "forceEnrollment", base::Bind(&ProximityAuthWebUIHandler::ForceEnrollment,
147 base::Unretained(this))); 148 base::Unretained(this)));
148 149
149 web_ui()->RegisterMessageCallback( 150 web_ui()->RegisterMessageCallback(
150 "forceDeviceSync", base::Bind(&ProximityAuthWebUIHandler::ForceDeviceSync, 151 "forceDeviceSync", base::Bind(&ProximityAuthWebUIHandler::ForceDeviceSync,
151 base::Unretained(this))); 152 base::Unretained(this)));
152 153
153 LogBuffer::GetInstance()->AddObserver(this); 154 LogBuffer::GetInstance()->AddObserver(this);
155
156 InitGCMManager();
154 InitEnrollmentManager(); 157 InitEnrollmentManager();
155 InitDeviceManager(); 158 InitDeviceManager();
156 } 159 }
157 160
158 void ProximityAuthWebUIHandler::OnLogMessageAdded( 161 void ProximityAuthWebUIHandler::OnLogMessageAdded(
159 const LogBuffer::LogMessage& log_message) { 162 const LogBuffer::LogMessage& log_message) {
160 scoped_ptr<base::DictionaryValue> dictionary = 163 scoped_ptr<base::DictionaryValue> dictionary =
161 LogMessageToDictionary(log_message); 164 LogMessageToDictionary(log_message);
162 web_ui()->CallJavascriptFunction("LogBufferInterface.onLogMessageAdded", 165 web_ui()->CallJavascriptFunction("LogBufferInterface.onLogMessageAdded",
163 *dictionary); 166 *dictionary);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 enrollment_manager_->ForceEnrollmentNow( 236 enrollment_manager_->ForceEnrollmentNow(
234 cryptauth::INVOCATION_REASON_MANUAL); 237 cryptauth::INVOCATION_REASON_MANUAL);
235 } 238 }
236 } 239 }
237 240
238 void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) { 241 void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) {
239 if (device_manager_) 242 if (device_manager_)
240 device_manager_->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL); 243 device_manager_->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL);
241 } 244 }
242 245
246 void ProximityAuthWebUIHandler::InitGCMManager() {
247 gcm_manager_.reset(new CryptAuthGCMManagerImpl(delegate_->GetGCMDriver(),
248 delegate_->GetPrefService()));
249 }
250
243 void ProximityAuthWebUIHandler::InitEnrollmentManager() { 251 void ProximityAuthWebUIHandler::InitEnrollmentManager() {
244 #if defined(OS_CHROMEOS) 252 #if defined(OS_CHROMEOS)
245 // TODO(tengs): We initialize a CryptAuthEnrollmentManager here for 253 // TODO(tengs): We initialize a CryptAuthEnrollmentManager here for
246 // development and testing purposes until it is ready to be moved into Chrome. 254 // development and testing purposes until it is ready to be moved into Chrome.
247 // The public/private key pair has been generated and serialized in a previous 255 // The public/private key pair has been generated and serialized in a previous
248 // session. 256 // session.
249 std::string user_public_key; 257 std::string user_public_key;
250 Base64UrlDecode( 258 Base64UrlDecode(
251 "CAESRgohAD1lP_wgQ8XqVVwz4aK_89SqdvAQG5L_NZH5zXxwg5UbEiEAZFMlgCZ9h8OlyE4" 259 "CAESRgohAD1lP_wgQ8XqVVwz4aK_89SqdvAQG5L_NZH5zXxwg5UbEiEAZFMlgCZ9h8OlyE4"
252 "QYKY5oiOBu0FmLSKeTAXEq2jnVJI=", 260 "QYKY5oiOBu0FmLSKeTAXEq2jnVJI=",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 "bF9JVWY4YTJDSmJNbXFqaWpYUFYzaVV5dmJXSVRrR3d1bFRaVUs3RGVZczJtT0h5ZkQ1NWR" 295 "bF9JVWY4YTJDSmJNbXFqaWpYUFYzaVV5dmJXSVRrR3d1bFRaVUs3RGVZczJtT0h5ZkQ1NWR"
288 "HRXEtdnJTdVc4VEZ2Z1haa2xhVEZTN0dqM2xCVUktSHd5Z0h6bHZHX2NGLWtzQmw0dXdveG" 296 "HRXEtdnJTdVc4VEZ2Z1haa2xhVEZTN0dqM2xCVUktSHd5Z0h6bHZHX2NGLWtzQmw0dXdveG"
289 "VPWE1hRlJ3WGJHVUU1Tm9sLS1mdkRIcGVZVnJR", 297 "VPWE1hRlJ3WGJHVUU1Tm9sLS1mdkRIcGVZVnJR",
290 &serialized_device_info); 298 &serialized_device_info);
291 cryptauth::GcmDeviceInfo device_info; 299 cryptauth::GcmDeviceInfo device_info;
292 device_info.ParseFromString(serialized_device_info); 300 device_info.ParseFromString(serialized_device_info);
293 301
294 enrollment_manager_.reset(new CryptAuthEnrollmentManager( 302 enrollment_manager_.reset(new CryptAuthEnrollmentManager(
295 make_scoped_ptr(new base::DefaultClock()), 303 make_scoped_ptr(new base::DefaultClock()),
296 make_scoped_ptr(new CryptAuthEnrollerFactoryImpl(delegate_)), 304 make_scoped_ptr(new CryptAuthEnrollerFactoryImpl(delegate_)),
297 user_public_key, user_private_key, device_info, 305 user_public_key, user_private_key, device_info, gcm_manager_.get(),
298 delegate_->GetPrefService())); 306 delegate_->GetPrefService()));
299 enrollment_manager_->AddObserver(this); 307 enrollment_manager_->AddObserver(this);
300 enrollment_manager_->Start(); 308 enrollment_manager_->Start();
301 #endif 309 #endif
302 } 310 }
303 311
304 void ProximityAuthWebUIHandler::InitDeviceManager() { 312 void ProximityAuthWebUIHandler::InitDeviceManager() {
305 // TODO(tengs): We initialize a CryptAuthDeviceManager here for 313 // TODO(tengs): We initialize a CryptAuthDeviceManager here for
306 // development and testing purposes until it is ready to be moved into Chrome. 314 // development and testing purposes until it is ready to be moved into Chrome.
307 device_manager_.reset(new CryptAuthDeviceManager( 315 device_manager_.reset(new CryptAuthDeviceManager(
308 make_scoped_ptr(new base::DefaultClock()), 316 make_scoped_ptr(new base::DefaultClock()),
309 delegate_->CreateCryptAuthClientFactory(), delegate_->GetPrefService())); 317 delegate_->CreateCryptAuthClientFactory(), gcm_manager_.get(),
318 delegate_->GetPrefService()));
310 device_manager_->AddObserver(this); 319 device_manager_->AddObserver(this);
311 device_manager_->Start(); 320 device_manager_->Start();
312 } 321 }
313 322
314 void ProximityAuthWebUIHandler::OnCryptAuthClientError( 323 void ProximityAuthWebUIHandler::OnCryptAuthClientError(
315 const std::string& error_message) { 324 const std::string& error_message) {
316 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message; 325 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message;
317 base::StringValue error_string(error_message); 326 base::StringValue error_string(error_message);
318 web_ui()->CallJavascriptFunction("CryptAuthInterface.onError", error_string); 327 web_ui()->CallJavascriptFunction("CryptAuthInterface.onError", error_string);
319 } 328 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return make_scoped_ptr(new base::DictionaryValue()); 375 return make_scoped_ptr(new base::DictionaryValue());
367 376
368 return CreateSyncStateDictionary( 377 return CreateSyncStateDictionary(
369 device_manager_->GetLastSyncTime().ToJsTime(), 378 device_manager_->GetLastSyncTime().ToJsTime(),
370 device_manager_->GetTimeToNextAttempt().InMillisecondsF(), 379 device_manager_->GetTimeToNextAttempt().InMillisecondsF(),
371 device_manager_->IsRecoveringFromFailure(), 380 device_manager_->IsRecoveringFromFailure(),
372 device_manager_->IsSyncInProgress()); 381 device_manager_->IsSyncInProgress());
373 } 382 }
374 383
375 } // namespace proximity_auth 384 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/webui/proximity_auth_webui_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698