Commit 814448e9 authored by Yue Li's avatar Yue Li Committed by Commit Bot

Migrate methods from AssitantOptInUI into Handler

- migrate many methods into the handler
- update loading/error screen specs

Bug: b/78190629
Test: Manual
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I7a590f547cc85309f982c58421f0984721a4f04b
Reviewed-on: https://chromium-review.googlesource.com/1112716Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Yue Li <updowndota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570113}
parent 87de9d51
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
.title { .title {
font-size: 18px; font-size: 18px;
padding-bottom: 10px; padding: 32px 0 18px 0;
} }
.sub-title { .sub-title {
font-size: 12px; font-size: 12px;
padding: 8px 0 8px 0; padding-bottom: 8px;
} }
#loading-message { #loading-message {
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
no-footer-padding no-header android> no-footer-padding no-header android>
<div slot="footer"> <div slot="footer">
<div id="error-container"> <div id="error-container">
<div class="title" <iron-icon src="assistant_logo.png">
i18n-content="assistantOptinLoadErrorTitle"></div> </iron-icon>
<div class="sub-title"> <div class="title" i18n-content="assistantOptinLoadErrorTitle"></div>
<div i18n-content="assistantOptinLoadErrorMessage"></div> <div class="sub-title" i18n-content="assistantOptinLoadErrorMessage">
</div> </div>
</div> </div>
<div id="loading-container"> <div id="loading-container">
......
...@@ -88,7 +88,7 @@ Polymer({ ...@@ -88,7 +88,7 @@ Polymer({
}.bind(this), 500); }.bind(this), 500);
this.loadingTimeout_ = window.setTimeout(function() { this.loadingTimeout_ = window.setTimeout(function() {
this.onErrorOccurred(); this.onErrorOccurred();
}.bind(this), 5000); }.bind(this), 3000);
}, },
/** /**
......
...@@ -95,6 +95,10 @@ cr.define('assistantOptin', function() { ...@@ -95,6 +95,10 @@ cr.define('assistantOptin', function() {
} }
}, },
closeDialog: function() {
chrome.send('dialogClose');
},
/** /**
* Show the given screen. * Show the given screen.
* *
......
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/arc/voice_interaction/voice_interaction_controller_client.h"
#include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h" #include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h"
#include "chromeos/services/assistant/public/mojom/settings.mojom.h"
namespace chromeos { namespace chromeos {
class AssistantOptInHandler : public BaseWebUIHandler { class AssistantOptInHandler
: public BaseWebUIHandler,
public arc::VoiceInteractionControllerClient::Observer {
public: public:
explicit AssistantOptInHandler(JSCallsContainer* js_calls_container); explicit AssistantOptInHandler(JSCallsContainer* js_calls_container);
~AssistantOptInHandler() override; ~AssistantOptInHandler() override;
...@@ -24,15 +28,46 @@ class AssistantOptInHandler : public BaseWebUIHandler { ...@@ -24,15 +28,46 @@ class AssistantOptInHandler : public BaseWebUIHandler {
void RegisterMessages() override; void RegisterMessages() override;
void Initialize() override; void Initialize() override;
// Send messages to the page.
void ShowNextScreen();
// Handle user opt-in result.
void OnActivityControlOptInResult(bool opted_in);
void OnEmailOptInResult(bool opted_in);
private:
// arc::VoiceInteractionControllerClient::Observer overrides
void OnStateChanged(ash::mojom::VoiceInteractionState state) override;
// Connect to assistant settings manager.
void BindAssistantSettingsManager();
// Send GetSettings request for the opt-in UI.
void SendGetSettingsRequest();
// Send message and consent data to the page. // Send message and consent data to the page.
void ReloadContent(const base::DictionaryValue& dict); void ReloadContent(const base::DictionaryValue& dict);
void AddSettingZippy(const std::string& type, const base::ListValue& data); void AddSettingZippy(const std::string& type, const base::ListValue& data);
void ShowNextScreen();
private: // Handle response from the settings manager.
void OnGetSettingsResponse(const std::string& settings);
void OnUpdateSettingsResponse(const std::string& settings);
// Handler for JS WebUI message. // Handler for JS WebUI message.
void HandleInitialized(); void HandleInitialized();
// Consent token used to complete the opt-in.
std::string consent_token_;
// Whether activity control is needed for user.
bool activity_control_needed_ = true;
// Whether email optin is needed for user.
bool email_optin_needed_ = false;
assistant::mojom::AssistantSettingsManagerPtr settings_manager_;
base::WeakPtrFactory<AssistantOptInHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AssistantOptInHandler); DISALLOW_COPY_AND_ASSIGN(AssistantOptInHandler);
}; };
......
...@@ -9,60 +9,30 @@ ...@@ -9,60 +9,30 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/arc/voice_interaction/voice_interaction_controller_client.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_handler.h" #include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_handler.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_screen_exit_code.h" #include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_screen_exit_code.h"
#include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h" #include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h"
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "chromeos/services/assistant/public/mojom/settings.mojom.h"
#include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_controller.h"
#include "ui/web_dialogs/web_dialog_ui.h" #include "ui/web_dialogs/web_dialog_ui.h"
namespace chromeos { namespace chromeos {
// Controller for chrome://assistant-optin/ page. // Controller for chrome://assistant-optin/ page.
class AssistantOptInUI class AssistantOptInUI : public ui::WebDialogUI {
: public ui::WebDialogUI,
public arc::VoiceInteractionControllerClient::Observer {
public: public:
explicit AssistantOptInUI(content::WebUI* web_ui); explicit AssistantOptInUI(content::WebUI* web_ui);
~AssistantOptInUI() override; ~AssistantOptInUI() override;
// arc::VoiceInteractionControllerClient::Observer overrides
void OnStateChanged(ash::mojom::VoiceInteractionState state) override;
private: private:
// Initilize connection to settings manager.
void Initialize();
// Add message handler for optin screens. // Add message handler for optin screens.
void AddScreenHandler(std::unique_ptr<BaseWebUIHandler> handler); void AddScreenHandler(std::unique_ptr<BaseWebUIHandler> handler);
// Called by a screen when user's done with it. // Called by a screen when user's done with it.
void OnExit(AssistantOptInScreenExitCode exit_code); void OnExit(AssistantOptInScreenExitCode exit_code);
void OnActivityControlOptInResult(bool opted_in);
void OnEmailOptInResult(bool opted_in);
// Handle response from the settings manager.
void OnGetSettingsResponse(const std::string& settings);
void OnUpdateSettingsResponse(const std::string& settings);
// Show next screen in the optin flow.
void Next();
// Consent token used to complete the opt-in.
std::string consent_token_;
// Whether activity control is needed for user.
bool activity_control_needed_ = true;
// Whether email optin is needed for user.
bool email_optin_needed_ = false;
AssistantOptInHandler* assistant_handler_ = nullptr; AssistantOptInHandler* assistant_handler_ = nullptr;
std::unique_ptr<JSCallsContainer> js_calls_container_; std::unique_ptr<JSCallsContainer> js_calls_container_;
assistant::mojom::AssistantSettingsManagerPtr settings_manager_;
std::vector<BaseWebUIHandler*> screen_handlers_; std::vector<BaseWebUIHandler*> screen_handlers_;
base::WeakPtrFactory<AssistantOptInUI> weak_factory_; base::WeakPtrFactory<AssistantOptInUI> weak_factory_;
......
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