Commit e30241b2 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[CrOS Multidevice] Migrate ProximityAuthWebUIHandler to conditionally use DeviceSyncClient.

ProximityAuthWebUiHandler now uses either ProximityAuthClient or DeviceSyncClient
to get remote device info or perform Cryptauth calls, depending on whether the
chromeos::features::kMultiDeviceApi is enabled. Once the migration to DeviceSyncClient
has been completed across all of Smart Lock, code that references ProximityAuthClient will
be removed.

This is one of many future CLs which are migrating Smart Lock to use
DeviceSync Mojo API instead of directly using the CryptAuth API.

I have manually verified the correctness of this change by verifying the
output on chrome://proximity-auth.

Bug: 824568, 752273, 848956
Change-Id: Ia6bf1666f631a79c2873df3745232b8a8152bc8e
Reviewed-on: https://chromium-review.googlesource.com/1099050
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567354}
parent 17d2fcdd
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "base/sys_info.h" #include "base/sys_info.h"
#include "chrome/browser/chromeos/device_sync/device_sync_client_factory.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_factory.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_factory.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.h" #include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.h"
...@@ -154,6 +155,7 @@ ...@@ -154,6 +155,7 @@
#include "chrome/browser/ui/webui/chromeos/slow_ui.h" #include "chrome/browser/ui/webui/chromeos/slow_ui.h"
#include "chrome/browser/ui/webui/chromeos/sys_internals/sys_internals_ui.h" #include "chrome/browser/ui/webui/chromeos/sys_internals/sys_internals_ui.h"
#include "chrome/browser/ui/webui/signin/inline_login_ui.h" #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/webui/proximity_auth_ui.h" #include "chromeos/components/proximity_auth/webui/proximity_auth_ui.h"
#include "chromeos/components/proximity_auth/webui/url_constants.h" #include "chromeos/components/proximity_auth/webui/url_constants.h"
#endif #endif
...@@ -259,10 +261,19 @@ WebUIController* NewWebUI<proximity_auth::ProximityAuthUI>(WebUI* web_ui, ...@@ -259,10 +261,19 @@ WebUIController* NewWebUI<proximity_auth::ProximityAuthUI>(WebUI* web_ui,
const GURL& url) { const GURL& url) {
content::BrowserContext* browser_context = content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext(); web_ui->GetWebContents()->GetBrowserContext();
// TODO(crbug.com/848956): Only pass DeviceSyncClient once Smart Lock has
// fully migrated to the DeviceSync API.
return new proximity_auth::ProximityAuthUI( return new proximity_auth::ProximityAuthUI(
web_ui, web_ui,
chromeos::EasyUnlockServiceFactory::GetForBrowserContext(browser_context) base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
->proximity_auth_client()); ? nullptr
: chromeos::EasyUnlockServiceFactory::GetForBrowserContext(
browser_context)
->proximity_auth_client(),
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? chromeos::device_sync::DeviceSyncClientFactory::GetForProfile(
Profile::FromBrowserContext(browser_context))
: nullptr);
} }
#endif #endif
......
...@@ -19,9 +19,12 @@ static_library("webui") { ...@@ -19,9 +19,12 @@ static_library("webui") {
deps = [ deps = [
"//base", "//base",
"//base:i18n", "//base:i18n",
"//chromeos",
"//chromeos/components/proximity_auth", "//chromeos/components/proximity_auth",
"//chromeos/components/proximity_auth/logging", "//chromeos/components/proximity_auth/logging",
"//chromeos/resources", "//chromeos/resources",
"//chromeos/services/device_sync/public/cpp",
"//chromeos/services/device_sync/public/mojom",
"//chromeos/services/multidevice_setup/public/mojom", "//chromeos/services/multidevice_setup/public/mojom",
"//components/cryptauth", "//components/cryptauth",
"//components/prefs", "//components/prefs",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chromeos/components/proximity_auth/webui/proximity_auth_webui_handler.h" #include "chromeos/components/proximity_auth/webui/proximity_auth_webui_handler.h"
#include "chromeos/components/proximity_auth/webui/url_constants.h" #include "chromeos/components/proximity_auth/webui/url_constants.h"
#include "chromeos/grit/chromeos_resources.h" #include "chromeos/grit/chromeos_resources.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h" #include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h"
#include "components/grit/components_resources.h" #include "components/grit/components_resources.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -19,8 +20,10 @@ ...@@ -19,8 +20,10 @@
namespace proximity_auth { namespace proximity_auth {
ProximityAuthUI::ProximityAuthUI(content::WebUI* web_ui, ProximityAuthUI::ProximityAuthUI(
ProximityAuthClient* delegate) content::WebUI* web_ui,
ProximityAuthClient* proximity_auth_client,
chromeos::device_sync::DeviceSyncClient* device_sync_client)
: ui::MojoWebUIController(web_ui, true /* enable_chrome_send */) { : ui::MojoWebUIController(web_ui, true /* enable_chrome_send */) {
content::WebUIDataSource* source = content::WebUIDataSource* source =
content::WebUIDataSource::Create(kChromeUIProximityAuthHost); content::WebUIDataSource::Create(kChromeUIProximityAuthHost);
...@@ -49,8 +52,8 @@ ProximityAuthUI::ProximityAuthUI(content::WebUI* web_ui, ...@@ -49,8 +52,8 @@ ProximityAuthUI::ProximityAuthUI(content::WebUI* web_ui,
content::BrowserContext* browser_context = content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext(); web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, source); content::WebUIDataSource::Add(browser_context, source);
web_ui->AddMessageHandler( web_ui->AddMessageHandler(std::make_unique<ProximityAuthWebUIHandler>(
std::make_unique<ProximityAuthWebUIHandler>(delegate)); proximity_auth_client, device_sync_client));
AddHandlerToRegistry(base::BindRepeating( AddHandlerToRegistry(base::BindRepeating(
&ProximityAuthUI::BindMultiDeviceSetup, base::Unretained(this))); &ProximityAuthUI::BindMultiDeviceSetup, base::Unretained(this)));
} }
......
...@@ -12,6 +12,12 @@ ...@@ -12,6 +12,12 @@
#include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_controller.h"
#include "ui/webui/mojo_web_ui_controller.h" #include "ui/webui/mojo_web_ui_controller.h"
namespace chromeos {
namespace device_sync {
class DeviceSyncClient;
} // namespace device_sync
} // namespace chromeos
namespace proximity_auth { namespace proximity_auth {
class ProximityAuthClient; class ProximityAuthClient;
...@@ -19,9 +25,11 @@ class ProximityAuthClient; ...@@ -19,9 +25,11 @@ class ProximityAuthClient;
// The WebUI controller for chrome://proximity-auth. // The WebUI controller for chrome://proximity-auth.
class ProximityAuthUI : public ui::MojoWebUIController { class ProximityAuthUI : public ui::MojoWebUIController {
public: public:
// Note: |web_ui| and |delegate| are not owned by this instance and must // Note: |web_ui| and |proximity_auth_client| are not owned by this instance
// outlive this instance. // and must outlive this instance.
ProximityAuthUI(content::WebUI* web_ui, ProximityAuthClient* delegate); ProximityAuthUI(content::WebUI* web_ui,
ProximityAuthClient* proximity_auth_client,
chromeos::device_sync::DeviceSyncClient* device_sync_client);
~ProximityAuthUI() override; ~ProximityAuthUI() override;
protected: protected:
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
#include "chromeos/components/proximity_auth/messenger_observer.h" #include "chromeos/components/proximity_auth/messenger_observer.h"
#include "chromeos/components/proximity_auth/proximity_auth_client.h" #include "chromeos/components/proximity_auth/proximity_auth_client.h"
#include "chromeos/components/proximity_auth/remote_device_life_cycle.h" #include "chromeos/components/proximity_auth/remote_device_life_cycle.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "components/cryptauth/connection_observer.h" #include "components/cryptauth/connection_observer.h"
#include "components/cryptauth/cryptauth_client.h" #include "components/cryptauth/cryptauth_client.h"
#include "components/cryptauth/cryptauth_device_manager.h" #include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h" #include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/cryptauth_gcm_manager.h" #include "components/cryptauth/cryptauth_gcm_manager.h"
#include "components/cryptauth/remote_device_ref.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
namespace base { namespace base {
...@@ -31,7 +33,6 @@ class RemoteDeviceLoader; ...@@ -31,7 +33,6 @@ class RemoteDeviceLoader;
namespace proximity_auth { namespace proximity_auth {
class ReachablePhoneFlow;
class RemoteDeviceLifeCycle; class RemoteDeviceLifeCycle;
struct RemoteStatusUpdate; struct RemoteStatusUpdate;
...@@ -41,12 +42,13 @@ class ProximityAuthWebUIHandler ...@@ -41,12 +42,13 @@ class ProximityAuthWebUIHandler
public LogBuffer::Observer, public LogBuffer::Observer,
public cryptauth::CryptAuthEnrollmentManager::Observer, public cryptauth::CryptAuthEnrollmentManager::Observer,
public cryptauth::CryptAuthDeviceManager::Observer, public cryptauth::CryptAuthDeviceManager::Observer,
public chromeos::device_sync::DeviceSyncClient::Observer,
public RemoteDeviceLifeCycle::Observer, public RemoteDeviceLifeCycle::Observer,
public MessengerObserver { public MessengerObserver {
public: public:
// |client_| is not owned and must outlive this instance. ProximityAuthWebUIHandler(
explicit ProximityAuthWebUIHandler( ProximityAuthClient* proximity_auth_client,
ProximityAuthClient* proximity_auth_client); chromeos::device_sync::DeviceSyncClient* device_sync_client);
~ProximityAuthWebUIHandler() override; ~ProximityAuthWebUIHandler() override;
// content::WebUIMessageHandler: // content::WebUIMessageHandler:
...@@ -67,13 +69,16 @@ class ProximityAuthWebUIHandler ...@@ -67,13 +69,16 @@ class ProximityAuthWebUIHandler
cryptauth::CryptAuthDeviceManager::DeviceChangeResult cryptauth::CryptAuthDeviceManager::DeviceChangeResult
device_change_result) override; device_change_result) override;
// chromeos::device_sync::DeviceSyncClient::Observer:
void OnEnrollmentFinished() override;
void OnNewDevicesSynced() override;
// Message handler callbacks. // Message handler callbacks.
void OnWebContentsInitialized(const base::ListValue* args); void OnWebContentsInitialized(const base::ListValue* args);
void GetLogMessages(const base::ListValue* args); void GetLogMessages(const base::ListValue* args);
void ClearLogBuffer(const base::ListValue* args); void ClearLogBuffer(const base::ListValue* args);
void ToggleUnlockKey(const base::ListValue* args); void ToggleUnlockKey(const base::ListValue* args);
void FindEligibleUnlockDevices(const base::ListValue* args); void FindEligibleUnlockDevices(const base::ListValue* args);
void FindReachableDevices(const base::ListValue* args);
void GetLocalState(const base::ListValue* args); void GetLocalState(const base::ListValue* args);
void ForceEnrollment(const base::ListValue* args); void ForceEnrollment(const base::ListValue* args);
void ForceDeviceSync(const base::ListValue* args); void ForceDeviceSync(const base::ListValue* args);
...@@ -84,35 +89,25 @@ class ProximityAuthWebUIHandler ...@@ -84,35 +89,25 @@ class ProximityAuthWebUIHandler
void InitEnrollmentManager(); void InitEnrollmentManager();
void InitDeviceManager(); void InitDeviceManager();
// Called when a CryptAuth request fails.
void OnCryptAuthClientError(const std::string& error_message); void OnCryptAuthClientError(const std::string& error_message);
// Called when the toggleUnlock request succeeds.
void OnEasyUnlockToggled(const cryptauth::ToggleEasyUnlockResponse& response); void OnEasyUnlockToggled(const cryptauth::ToggleEasyUnlockResponse& response);
// Called when the findEligibleUnlockDevices request succeeds.
void OnFoundEligibleUnlockDevices( void OnFoundEligibleUnlockDevices(
const cryptauth::FindEligibleUnlockDevicesResponse& response); const cryptauth::FindEligibleUnlockDevicesResponse& response);
// Callback when |reachable_phone_flow_| completes.
void OnReachablePhonesFound(
const std::vector<cryptauth::ExternalDeviceInfo>& reachable_phones);
// Called when the RemoteDevice is loaded so we can create a connection. // Called when the RemoteDevice is loaded so we can create a connection.
void OnRemoteDevicesLoaded(const cryptauth::RemoteDeviceList& remote_devices); void OnRemoteDevicesLoaded(const cryptauth::RemoteDeviceList& remote_devices);
// Converts an ExternalDeviceInfo proto to a JSON dictionary used in void StartRemoteDeviceLifeCycle(cryptauth::RemoteDeviceRef remote_device);
// JavaScript. void CleanUpRemoteDeviceLifeCycle();
std::unique_ptr<base::DictionaryValue> ExternalDeviceInfoToDictionary( std::unique_ptr<base::DictionaryValue> ExternalDeviceInfoToDictionary(
const cryptauth::ExternalDeviceInfo& device_info); const cryptauth::ExternalDeviceInfo& device_info);
std::unique_ptr<base::DictionaryValue> RemoteDeviceToDictionary(
// Converts an IneligibleDevice proto to a JSON dictionary used in JavaScript. const cryptauth::RemoteDeviceRef& remote_device);
std::unique_ptr<base::DictionaryValue> IneligibleDeviceToDictionary( std::unique_ptr<base::DictionaryValue> IneligibleDeviceToDictionary(
const cryptauth::IneligibleDevice& ineligible_device); const cryptauth::IneligibleDevice& ineligible_device);
// Cleans up the connection to the selected remote device.
void CleanUpRemoteDeviceLifeCycle();
// RemoteDeviceLifeCycle::Observer: // RemoteDeviceLifeCycle::Observer:
void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state, void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state,
RemoteDeviceLifeCycle::State new_state) override; RemoteDeviceLifeCycle::State new_state) override;
...@@ -120,30 +115,46 @@ class ProximityAuthWebUIHandler ...@@ -120,30 +115,46 @@ class ProximityAuthWebUIHandler
// MessengerObserver: // MessengerObserver:
void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override; void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override;
// Returns the truncated device ID of the local device. void OnForceEnrollmentNow(bool success);
void OnForceSyncNow(bool success);
void OnSetSoftwareFeatureState(const std::string public_key,
const base::Optional<std::string>& error_code);
void OnFindEligibleDevices(const base::Optional<std::string>&,
cryptauth::RemoteDeviceRefList eligible_devices,
cryptauth::RemoteDeviceRefList ineligible_devices);
void OnGetDebugInfo(
chromeos::device_sync::mojom::DebugInfoPtr debug_info_ptr);
void NotifyOnEnrollmentFinished(
bool success,
std::unique_ptr<base::DictionaryValue> enrollment_state);
void NotifyOnSyncFinished(
bool was_sync_successful,
bool changed,
std::unique_ptr<base::DictionaryValue> device_sync_state);
void NotifyGotLocalState(
std::unique_ptr<base::Value> truncated_local_device_id,
std::unique_ptr<base::DictionaryValue> enrollment_state,
std::unique_ptr<base::DictionaryValue> device_sync_state,
std::unique_ptr<base::ListValue> synced_devices);
std::unique_ptr<base::Value> GetTruncatedLocalDeviceId(); std::unique_ptr<base::Value> GetTruncatedLocalDeviceId();
// Returns the current enrollment state that can be used as a JSON object. // These two methods cannot be used if the chromeos::features::kMultiDeviceApi
// flag is enabled.
std::unique_ptr<base::DictionaryValue> GetEnrollmentStateDictionary(); std::unique_ptr<base::DictionaryValue> GetEnrollmentStateDictionary();
// Returns the current device sync state that can be used as a JSON object.
std::unique_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary(); std::unique_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary();
// Returns the current remote devices that can be used as a JSON object.
std::unique_ptr<base::ListValue> GetRemoteDevicesList(); std::unique_ptr<base::ListValue> GetRemoteDevicesList();
// The delegate used to fetch dependencies. Must outlive this instance. // The delegate used to fetch dependencies. Must outlive this instance.
ProximityAuthClient* proximity_auth_client_; ProximityAuthClient* proximity_auth_client_;
chromeos::device_sync::DeviceSyncClient* device_sync_client_;
// Creates CryptAuth client instances to make API calls.
std::unique_ptr<cryptauth::CryptAuthClientFactory> cryptauth_client_factory_; std::unique_ptr<cryptauth::CryptAuthClientFactory> cryptauth_client_factory_;
// We only support one concurrent API call. // We only support one concurrent API call.
std::unique_ptr<cryptauth::CryptAuthClient> cryptauth_client_; std::unique_ptr<cryptauth::CryptAuthClient> cryptauth_client_;
// The flow for getting a list of reachable phones.
std::unique_ptr<ReachablePhoneFlow> reachable_phone_flow_;
// True if we get a message from the loaded WebContents to know that it is // True if we get a message from the loaded WebContents to know that it is
// initialized, and we can inject JavaScript. // initialized, and we can inject JavaScript.
bool web_contents_initialized_; bool web_contents_initialized_;
...@@ -155,6 +166,10 @@ class ProximityAuthWebUIHandler ...@@ -155,6 +166,10 @@ class ProximityAuthWebUIHandler
std::unique_ptr<RemoteDeviceLifeCycle> life_cycle_; std::unique_ptr<RemoteDeviceLifeCycle> life_cycle_;
std::unique_ptr<RemoteStatusUpdate> last_remote_status_update_; std::unique_ptr<RemoteStatusUpdate> last_remote_status_update_;
bool enrollment_update_waiting_for_debug_info_ = false;
bool sync_update_waiting_for_debug_info_ = false;
bool get_local_state_update_waiting_for_debug_info_ = false;
base::WeakPtrFactory<ProximityAuthWebUIHandler> weak_ptr_factory_; base::WeakPtrFactory<ProximityAuthWebUIHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler); DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment