| 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 #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 | 9 |
| 9 #include "base/base64url.h" | 10 #include "base/base64url.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/time/default_clock.h" | 15 #include "base/time/default_clock.h" |
| 15 #include "base/time/default_tick_clock.h" | 16 #include "base/time/default_tick_clock.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "components/proximity_auth/ble/pref_names.h" | 18 #include "components/proximity_auth/ble/pref_names.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const LogBuffer::LogMessage& log_message) { | 55 const LogBuffer::LogMessage& log_message) { |
| 55 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); | 56 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); |
| 56 dictionary->SetString(kLogMessageTextKey, log_message.text); | 57 dictionary->SetString(kLogMessageTextKey, log_message.text); |
| 57 dictionary->SetString( | 58 dictionary->SetString( |
| 58 kLogMessageTimeKey, | 59 kLogMessageTimeKey, |
| 59 base::TimeFormatTimeOfDayWithMilliseconds(log_message.time)); | 60 base::TimeFormatTimeOfDayWithMilliseconds(log_message.time)); |
| 60 dictionary->SetString(kLogMessageFileKey, log_message.file); | 61 dictionary->SetString(kLogMessageFileKey, log_message.file); |
| 61 dictionary->SetInteger(kLogMessageLineKey, log_message.line); | 62 dictionary->SetInteger(kLogMessageLineKey, log_message.line); |
| 62 dictionary->SetInteger(kLogMessageSeverityKey, | 63 dictionary->SetInteger(kLogMessageSeverityKey, |
| 63 static_cast<int>(log_message.severity)); | 64 static_cast<int>(log_message.severity)); |
| 64 return dictionary.Pass(); | 65 return dictionary; |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Keys in the JSON representation of an ExternalDeviceInfo proto. | 68 // Keys in the JSON representation of an ExternalDeviceInfo proto. |
| 68 const char kExternalDevicePublicKey[] = "publicKey"; | 69 const char kExternalDevicePublicKey[] = "publicKey"; |
| 69 const char kExternalDeviceFriendlyName[] = "friendlyDeviceName"; | 70 const char kExternalDeviceFriendlyName[] = "friendlyDeviceName"; |
| 70 const char kExternalDeviceBluetoothAddress[] = "bluetoothAddress"; | 71 const char kExternalDeviceBluetoothAddress[] = "bluetoothAddress"; |
| 71 const char kExternalDeviceUnlockKey[] = "unlockKey"; | 72 const char kExternalDeviceUnlockKey[] = "unlockKey"; |
| 72 const char kExternalDeviceConnectionStatus[] = "connectionStatus"; | 73 const char kExternalDeviceConnectionStatus[] = "connectionStatus"; |
| 73 const char kExternalDeviceRemoteState[] = "remoteState"; | 74 const char kExternalDeviceRemoteState[] = "remoteState"; |
| 74 | 75 |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 if (last_remote_status_update_) { | 529 if (last_remote_status_update_) { |
| 529 scoped_ptr<base::DictionaryValue> status_dictionary( | 530 scoped_ptr<base::DictionaryValue> status_dictionary( |
| 530 new base::DictionaryValue()); | 531 new base::DictionaryValue()); |
| 531 status_dictionary->SetInteger("userPresent", | 532 status_dictionary->SetInteger("userPresent", |
| 532 last_remote_status_update_->user_presence); | 533 last_remote_status_update_->user_presence); |
| 533 status_dictionary->SetInteger( | 534 status_dictionary->SetInteger( |
| 534 "secureScreenLock", | 535 "secureScreenLock", |
| 535 last_remote_status_update_->secure_screen_lock_state); | 536 last_remote_status_update_->secure_screen_lock_state); |
| 536 status_dictionary->SetInteger( | 537 status_dictionary->SetInteger( |
| 537 "trustAgent", last_remote_status_update_->trust_agent_state); | 538 "trustAgent", last_remote_status_update_->trust_agent_state); |
| 538 dictionary->Set(kExternalDeviceRemoteState, status_dictionary.Pass()); | 539 dictionary->Set(kExternalDeviceRemoteState, std::move(status_dictionary)); |
| 539 } | 540 } |
| 540 | 541 |
| 541 return dictionary; | 542 return dictionary; |
| 542 } | 543 } |
| 543 | 544 |
| 544 scoped_ptr<base::DictionaryValue> | 545 scoped_ptr<base::DictionaryValue> |
| 545 ProximityAuthWebUIHandler::IneligibleDeviceToDictionary( | 546 ProximityAuthWebUIHandler::IneligibleDeviceToDictionary( |
| 546 const cryptauth::IneligibleDevice& ineligible_device) { | 547 const cryptauth::IneligibleDevice& ineligible_device) { |
| 547 scoped_ptr<base::ListValue> ineligibility_reasons(new base::ListValue()); | 548 scoped_ptr<base::ListValue> ineligibility_reasons(new base::ListValue()); |
| 548 for (const std::string& reason : ineligible_device.reasons()) { | 549 for (const std::string& reason : ineligible_device.reasons()) { |
| 549 ineligibility_reasons->AppendString(reason); | 550 ineligibility_reasons->AppendString(reason); |
| 550 } | 551 } |
| 551 | 552 |
| 552 scoped_ptr<base::DictionaryValue> device_dictionary = | 553 scoped_ptr<base::DictionaryValue> device_dictionary = |
| 553 ExternalDeviceInfoToDictionary(ineligible_device.device()); | 554 ExternalDeviceInfoToDictionary(ineligible_device.device()); |
| 554 device_dictionary->Set(kIneligibleDeviceReasons, | 555 device_dictionary->Set(kIneligibleDeviceReasons, |
| 555 ineligibility_reasons.Pass()); | 556 std::move(ineligibility_reasons)); |
| 556 return device_dictionary; | 557 return device_dictionary; |
| 557 } | 558 } |
| 558 | 559 |
| 559 void ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle() { | 560 void ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle() { |
| 560 PA_LOG(INFO) << "Cleaning up connection to " << selected_remote_device_.name | 561 PA_LOG(INFO) << "Cleaning up connection to " << selected_remote_device_.name |
| 561 << " [" << selected_remote_device_.bluetooth_address << "]"; | 562 << " [" << selected_remote_device_.bluetooth_address << "]"; |
| 562 life_cycle_.reset(); | 563 life_cycle_.reset(); |
| 563 selected_remote_device_ = RemoteDevice(); | 564 selected_remote_device_ = RemoteDevice(); |
| 564 last_remote_status_update_.reset(); | 565 last_remote_status_update_.reset(); |
| 565 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", | 566 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 << "\n trust_agent_state: " | 600 << "\n trust_agent_state: " |
| 600 << static_cast<int>(status_update.trust_agent_state); | 601 << static_cast<int>(status_update.trust_agent_state); |
| 601 | 602 |
| 602 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); | 603 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); |
| 603 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); | 604 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); |
| 604 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", | 605 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", |
| 605 *unlock_keys); | 606 *unlock_keys); |
| 606 } | 607 } |
| 607 | 608 |
| 608 } // namespace proximity_auth | 609 } // namespace proximity_auth |
| OLD | NEW |