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 @@
.title {
font-size: 18px;
padding-bottom: 10px;
padding: 32px 0 18px 0;
}
.sub-title {
font-size: 12px;
padding: 8px 0 8px 0;
padding-bottom: 8px;
}
#loading-message {
......
......@@ -12,10 +12,10 @@
no-footer-padding no-header android>
<div slot="footer">
<div id="error-container">
<div class="title"
i18n-content="assistantOptinLoadErrorTitle"></div>
<div class="sub-title">
<div i18n-content="assistantOptinLoadErrorMessage"></div>
<iron-icon src="assistant_logo.png">
</iron-icon>
<div class="title" i18n-content="assistantOptinLoadErrorTitle"></div>
<div class="sub-title" i18n-content="assistantOptinLoadErrorMessage">
</div>
</div>
<div id="loading-container">
......
......@@ -88,7 +88,7 @@ Polymer({
}.bind(this), 500);
this.loadingTimeout_ = window.setTimeout(function() {
this.onErrorOccurred();
}.bind(this), 5000);
}.bind(this), 3000);
},
/**
......
......@@ -95,6 +95,10 @@ cr.define('assistantOptin', function() {
}
},
closeDialog: function() {
chrome.send('dialogClose');
},
/**
* Show the given screen.
*
......
......@@ -9,11 +9,15 @@
#include <string>
#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 "chromeos/services/assistant/public/mojom/settings.mojom.h"
namespace chromeos {
class AssistantOptInHandler : public BaseWebUIHandler {
class AssistantOptInHandler
: public BaseWebUIHandler,
public arc::VoiceInteractionControllerClient::Observer {
public:
explicit AssistantOptInHandler(JSCallsContainer* js_calls_container);
~AssistantOptInHandler() override;
......@@ -24,15 +28,46 @@ class AssistantOptInHandler : public BaseWebUIHandler {
void RegisterMessages() 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.
void ReloadContent(const base::DictionaryValue& dict);
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.
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);
};
......
......@@ -9,60 +9,30 @@
#include "base/callback.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_screen_exit_code.h"
#include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.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 "ui/web_dialogs/web_dialog_ui.h"
namespace chromeos {
// Controller for chrome://assistant-optin/ page.
class AssistantOptInUI
: public ui::WebDialogUI,
public arc::VoiceInteractionControllerClient::Observer {
class AssistantOptInUI : public ui::WebDialogUI {
public:
explicit AssistantOptInUI(content::WebUI* web_ui);
~AssistantOptInUI() override;
// arc::VoiceInteractionControllerClient::Observer overrides
void OnStateChanged(ash::mojom::VoiceInteractionState state) override;
private:
// Initilize connection to settings manager.
void Initialize();
// Add message handler for optin screens.
void AddScreenHandler(std::unique_ptr<BaseWebUIHandler> handler);
// Called by a screen when user's done with it.
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;
std::unique_ptr<JSCallsContainer> js_calls_container_;
assistant::mojom::AssistantSettingsManagerPtr settings_manager_;
std::vector<BaseWebUIHandler*> screen_handlers_;
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