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

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

Issue 2502343003: Moved //components/proximity_auth/cryptauth to //components/cryptauth. (Closed)
Patch Set: Fixed proto #includes. Created 4 years, 1 month 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 #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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64url.h" 10 #include "base/base64url.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/time/default_clock.h" 15 #include "base/time/default_clock.h"
16 #include "base/time/default_tick_clock.h" 16 #include "base/time/default_tick_clock.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/cryptauth/cryptauth_enrollment_manager.h"
19 #include "components/cryptauth/proto/cryptauth_api.pb.h"
20 #include "components/cryptauth/secure_message_delegate.h"
18 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
19 #include "components/proximity_auth/ble/pref_names.h" 22 #include "components/proximity_auth/ble/pref_names.h"
20 #include "components/proximity_auth/bluetooth_connection_finder.h" 23 #include "components/proximity_auth/bluetooth_connection_finder.h"
21 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h"
22 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
23 #include "components/proximity_auth/cryptauth/secure_message_delegate.h"
24 #include "components/proximity_auth/logging/logging.h" 24 #include "components/proximity_auth/logging/logging.h"
25 #include "components/proximity_auth/messenger.h" 25 #include "components/proximity_auth/messenger.h"
26 #include "components/proximity_auth/remote_device_life_cycle_impl.h" 26 #include "components/proximity_auth/remote_device_life_cycle_impl.h"
27 #include "components/proximity_auth/remote_device_loader.h" 27 #include "components/proximity_auth/remote_device_loader.h"
28 #include "components/proximity_auth/remote_status_update.h" 28 #include "components/proximity_auth/remote_status_update.h"
29 #include "components/proximity_auth/secure_context.h" 29 #include "components/proximity_auth/secure_context.h"
30 #include "components/proximity_auth/webui/reachable_phone_flow.h" 30 #include "components/proximity_auth/webui/reachable_phone_flow.h"
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/web_ui.h" 32 #include "content/public/browser/web_ui.h"
33 #include "device/bluetooth/bluetooth_uuid.h" 33 #include "device/bluetooth/bluetooth_uuid.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 "LocalStateInterface.onEnrollmentStateChanged", *enrollment_state); 189 "LocalStateInterface.onEnrollmentStateChanged", *enrollment_state);
190 } 190 }
191 191
192 void ProximityAuthWebUIHandler::OnSyncStarted() { 192 void ProximityAuthWebUIHandler::OnSyncStarted() {
193 web_ui()->CallJavascriptFunctionUnsafe( 193 web_ui()->CallJavascriptFunctionUnsafe(
194 "LocalStateInterface.onDeviceSyncStateChanged", 194 "LocalStateInterface.onDeviceSyncStateChanged",
195 *GetDeviceSyncStateDictionary()); 195 *GetDeviceSyncStateDictionary());
196 } 196 }
197 197
198 void ProximityAuthWebUIHandler::OnSyncFinished( 198 void ProximityAuthWebUIHandler::OnSyncFinished(
199 CryptAuthDeviceManager::SyncResult sync_result, 199 cryptauth::CryptAuthDeviceManager::SyncResult sync_result,
200 CryptAuthDeviceManager::DeviceChangeResult device_change_result) { 200 cryptauth::CryptAuthDeviceManager::DeviceChangeResult
201 device_change_result) {
201 std::unique_ptr<base::DictionaryValue> device_sync_state = 202 std::unique_ptr<base::DictionaryValue> device_sync_state =
202 GetDeviceSyncStateDictionary(); 203 GetDeviceSyncStateDictionary();
203 PA_LOG(INFO) << "Device sync completed with result=" 204 PA_LOG(INFO) << "Device sync completed with result="
204 << static_cast<int>(sync_result) << ":\n" << *device_sync_state; 205 << static_cast<int>(sync_result) << ":\n" << *device_sync_state;
205 web_ui()->CallJavascriptFunctionUnsafe( 206 web_ui()->CallJavascriptFunctionUnsafe(
206 "LocalStateInterface.onDeviceSyncStateChanged", *device_sync_state); 207 "LocalStateInterface.onDeviceSyncStateChanged", *device_sync_state);
207 208
208 if (device_change_result == 209 if (device_change_result ==
209 CryptAuthDeviceManager::DeviceChangeResult::CHANGED) { 210 cryptauth::CryptAuthDeviceManager::DeviceChangeResult::CHANGED) {
210 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 211 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
211 PA_LOG(INFO) << "New unlock keys obtained after device sync:\n" 212 PA_LOG(INFO) << "New unlock keys obtained after device sync:\n"
212 << *unlock_keys; 213 << *unlock_keys;
213 web_ui()->CallJavascriptFunctionUnsafe( 214 web_ui()->CallJavascriptFunctionUnsafe(
214 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys); 215 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys);
215 } 216 }
216 } 217 }
217 218
218 void ProximityAuthWebUIHandler::OnWebContentsInitialized( 219 void ProximityAuthWebUIHandler::OnWebContentsInitialized(
219 const base::ListValue* args) { 220 const base::ListValue* args) {
220 if (!web_contents_initialized_) { 221 if (!web_contents_initialized_) {
221 CryptAuthEnrollmentManager* enrollment_manager = 222 cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
222 proximity_auth_client_->GetCryptAuthEnrollmentManager(); 223 proximity_auth_client_->GetCryptAuthEnrollmentManager();
223 if (enrollment_manager) 224 if (enrollment_manager)
224 enrollment_manager->AddObserver(this); 225 enrollment_manager->AddObserver(this);
225 226
226 CryptAuthDeviceManager* device_manager = 227 cryptauth::CryptAuthDeviceManager* device_manager =
227 proximity_auth_client_->GetCryptAuthDeviceManager(); 228 proximity_auth_client_->GetCryptAuthDeviceManager();
228 if (device_manager) 229 if (device_manager)
229 device_manager->AddObserver(this); 230 device_manager->AddObserver(this);
230 231
231 LogBuffer::GetInstance()->AddObserver(this); 232 LogBuffer::GetInstance()->AddObserver(this);
232 233
233 web_contents_initialized_ = true; 234 web_contents_initialized_ = true;
234 } 235 }
235 } 236 }
236 237
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 302 }
302 303
303 reachable_phone_flow_.reset( 304 reachable_phone_flow_.reset(
304 new ReachablePhoneFlow(cryptauth_client_factory_.get())); 305 new ReachablePhoneFlow(cryptauth_client_factory_.get()));
305 reachable_phone_flow_->Run( 306 reachable_phone_flow_->Run(
306 base::Bind(&ProximityAuthWebUIHandler::OnReachablePhonesFound, 307 base::Bind(&ProximityAuthWebUIHandler::OnReachablePhonesFound,
307 weak_ptr_factory_.GetWeakPtr())); 308 weak_ptr_factory_.GetWeakPtr()));
308 } 309 }
309 310
310 void ProximityAuthWebUIHandler::ForceEnrollment(const base::ListValue* args) { 311 void ProximityAuthWebUIHandler::ForceEnrollment(const base::ListValue* args) {
311 CryptAuthEnrollmentManager* enrollment_manager = 312 cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
312 proximity_auth_client_->GetCryptAuthEnrollmentManager(); 313 proximity_auth_client_->GetCryptAuthEnrollmentManager();
313 if (enrollment_manager) { 314 if (enrollment_manager) {
314 enrollment_manager->ForceEnrollmentNow(cryptauth::INVOCATION_REASON_MANUAL); 315 enrollment_manager->ForceEnrollmentNow(cryptauth::INVOCATION_REASON_MANUAL);
315 } 316 }
316 } 317 }
317 318
318 void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) { 319 void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) {
319 CryptAuthDeviceManager* device_manager = 320 cryptauth::CryptAuthDeviceManager* device_manager =
320 proximity_auth_client_->GetCryptAuthDeviceManager(); 321 proximity_auth_client_->GetCryptAuthDeviceManager();
321 if (device_manager) 322 if (device_manager)
322 device_manager->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL); 323 device_manager->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL);
323 } 324 }
324 325
325 void ProximityAuthWebUIHandler::ToggleConnection(const base::ListValue* args) { 326 void ProximityAuthWebUIHandler::ToggleConnection(const base::ListValue* args) {
326 CryptAuthEnrollmentManager* enrollment_manager = 327 cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
327 proximity_auth_client_->GetCryptAuthEnrollmentManager(); 328 proximity_auth_client_->GetCryptAuthEnrollmentManager();
328 CryptAuthDeviceManager* device_manager = 329 cryptauth::CryptAuthDeviceManager* device_manager =
329 proximity_auth_client_->GetCryptAuthDeviceManager(); 330 proximity_auth_client_->GetCryptAuthDeviceManager();
330 if (!enrollment_manager || !device_manager) 331 if (!enrollment_manager || !device_manager)
331 return; 332 return;
332 333
333 std::string b64_public_key; 334 std::string b64_public_key;
334 std::string public_key; 335 std::string public_key;
335 if (!enrollment_manager || !device_manager || !args->GetSize() || 336 if (!enrollment_manager || !device_manager || !args->GetSize() ||
336 !args->GetString(0, &b64_public_key) || 337 !args->GetString(0, &b64_public_key) ||
337 !base::Base64UrlDecode(b64_public_key, 338 !base::Base64UrlDecode(b64_public_key,
338 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 339 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 << "Enrollment State: \n" << *enrollment_state 422 << "Enrollment State: \n" << *enrollment_state
422 << "Device Sync State: \n" << *device_sync_state 423 << "Device Sync State: \n" << *device_sync_state
423 << "Unlock Keys: \n" << *unlock_keys; 424 << "Unlock Keys: \n" << *unlock_keys;
424 web_ui()->CallJavascriptFunctionUnsafe("LocalStateInterface.onGotLocalState", 425 web_ui()->CallJavascriptFunctionUnsafe("LocalStateInterface.onGotLocalState",
425 *enrollment_state, *device_sync_state, 426 *enrollment_state, *device_sync_state,
426 *unlock_keys); 427 *unlock_keys);
427 } 428 }
428 429
429 std::unique_ptr<base::DictionaryValue> 430 std::unique_ptr<base::DictionaryValue>
430 ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() { 431 ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() {
431 CryptAuthEnrollmentManager* enrollment_manager = 432 cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
432 proximity_auth_client_->GetCryptAuthEnrollmentManager(); 433 proximity_auth_client_->GetCryptAuthEnrollmentManager();
433 if (!enrollment_manager) 434 if (!enrollment_manager)
434 return base::MakeUnique<base::DictionaryValue>(); 435 return base::MakeUnique<base::DictionaryValue>();
435 436
436 return CreateSyncStateDictionary( 437 return CreateSyncStateDictionary(
437 enrollment_manager->GetLastEnrollmentTime().ToJsTime(), 438 enrollment_manager->GetLastEnrollmentTime().ToJsTime(),
438 enrollment_manager->GetTimeToNextAttempt().InMillisecondsF(), 439 enrollment_manager->GetTimeToNextAttempt().InMillisecondsF(),
439 enrollment_manager->IsRecoveringFromFailure(), 440 enrollment_manager->IsRecoveringFromFailure(),
440 enrollment_manager->IsEnrollmentInProgress()); 441 enrollment_manager->IsEnrollmentInProgress());
441 } 442 }
442 443
443 std::unique_ptr<base::DictionaryValue> 444 std::unique_ptr<base::DictionaryValue>
444 ProximityAuthWebUIHandler::GetDeviceSyncStateDictionary() { 445 ProximityAuthWebUIHandler::GetDeviceSyncStateDictionary() {
445 CryptAuthDeviceManager* device_manager = 446 cryptauth::CryptAuthDeviceManager* device_manager =
446 proximity_auth_client_->GetCryptAuthDeviceManager(); 447 proximity_auth_client_->GetCryptAuthDeviceManager();
447 if (!device_manager) 448 if (!device_manager)
448 return base::MakeUnique<base::DictionaryValue>(); 449 return base::MakeUnique<base::DictionaryValue>();
449 450
450 return CreateSyncStateDictionary( 451 return CreateSyncStateDictionary(
451 device_manager->GetLastSyncTime().ToJsTime(), 452 device_manager->GetLastSyncTime().ToJsTime(),
452 device_manager->GetTimeToNextAttempt().InMillisecondsF(), 453 device_manager->GetTimeToNextAttempt().InMillisecondsF(),
453 device_manager->IsRecoveringFromFailure(), 454 device_manager->IsRecoveringFromFailure(),
454 device_manager->IsSyncInProgress()); 455 device_manager->IsSyncInProgress());
455 } 456 }
456 457
457 std::unique_ptr<base::ListValue> 458 std::unique_ptr<base::ListValue>
458 ProximityAuthWebUIHandler::GetUnlockKeysList() { 459 ProximityAuthWebUIHandler::GetUnlockKeysList() {
459 std::unique_ptr<base::ListValue> unlock_keys(new base::ListValue()); 460 std::unique_ptr<base::ListValue> unlock_keys(new base::ListValue());
460 CryptAuthDeviceManager* device_manager = 461 cryptauth::CryptAuthDeviceManager* device_manager =
461 proximity_auth_client_->GetCryptAuthDeviceManager(); 462 proximity_auth_client_->GetCryptAuthDeviceManager();
462 if (!device_manager) 463 if (!device_manager)
463 return unlock_keys; 464 return unlock_keys;
464 465
465 for (const auto& unlock_key : device_manager->unlock_keys()) { 466 for (const auto& unlock_key : device_manager->unlock_keys()) {
466 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key)); 467 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key));
467 } 468 }
468 469
469 return unlock_keys; 470 return unlock_keys;
470 } 471 }
(...skipping 25 matching lines...) Expand all
496 new base::DictionaryValue()); 497 new base::DictionaryValue());
497 dictionary->SetString(kExternalDevicePublicKey, base64_public_key); 498 dictionary->SetString(kExternalDevicePublicKey, base64_public_key);
498 dictionary->SetString(kExternalDeviceFriendlyName, 499 dictionary->SetString(kExternalDeviceFriendlyName,
499 device_info.friendly_device_name()); 500 device_info.friendly_device_name());
500 dictionary->SetString(kExternalDeviceBluetoothAddress, 501 dictionary->SetString(kExternalDeviceBluetoothAddress,
501 device_info.bluetooth_address()); 502 device_info.bluetooth_address());
502 dictionary->SetBoolean(kExternalDeviceUnlockKey, device_info.unlock_key()); 503 dictionary->SetBoolean(kExternalDeviceUnlockKey, device_info.unlock_key());
503 dictionary->SetString(kExternalDeviceConnectionStatus, 504 dictionary->SetString(kExternalDeviceConnectionStatus,
504 kExternalDeviceDisconnected); 505 kExternalDeviceDisconnected);
505 506
506 CryptAuthDeviceManager* device_manager = 507 cryptauth::CryptAuthDeviceManager* device_manager =
507 proximity_auth_client_->GetCryptAuthDeviceManager(); 508 proximity_auth_client_->GetCryptAuthDeviceManager();
508 if (!device_manager) 509 if (!device_manager)
509 return dictionary; 510 return dictionary;
510 511
511 // If |device_info| is a known unlock key, then combine the proto data with 512 // If |device_info| is a known unlock key, then combine the proto data with
512 // the corresponding local device data (e.g. connection status and remote 513 // the corresponding local device data (e.g. connection status and remote
513 // status updates). 514 // status updates).
514 std::string public_key = device_info.public_key(); 515 std::string public_key = device_info.public_key();
515 auto iterator = std::find_if( 516 auto iterator = std::find_if(
516 device_manager->unlock_keys().begin(), 517 device_manager->unlock_keys().begin(),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 << "\n trust_agent_state: " 610 << "\n trust_agent_state: "
610 << static_cast<int>(status_update.trust_agent_state); 611 << static_cast<int>(status_update.trust_agent_state);
611 612
612 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); 613 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update));
613 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 614 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
614 web_ui()->CallJavascriptFunctionUnsafe( 615 web_ui()->CallJavascriptFunctionUnsafe(
615 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys); 616 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys);
616 } 617 }
617 618
618 } // namespace proximity_auth 619 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/webui/proximity_auth_webui_handler.h ('k') | components/proximity_auth/webui/reachable_phone_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698