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

Unified Diff: chrome/browser/chromeos/arc/arc_support_host.cc

Issue 2472223002: WIP (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/arc_support_host.cc
diff --git a/chrome/browser/chromeos/arc/arc_support_host.cc b/chrome/browser/chromeos/arc/arc_support_host.cc
index 794a0c51bdbe9c5cbfabe1f281b7d9c3b215ff6f..65c0643b7dd407beabda50b838046df6c5146a79 100644
--- a/chrome/browser/chromeos/arc/arc_support_host.cc
+++ b/chrome/browser/chromeos/arc/arc_support_host.cc
@@ -13,13 +13,17 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
-#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/extensions/app_launch_params.h"
+#include "chrome/browser/ui/extensions/application_launch.h"
+#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
+#include "components/prefs/pref_service.h"
#include "components/user_manager/known_user.h"
+#include "extensions/browser/extension_registry.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/display/screen.h"
@@ -29,17 +33,30 @@ constexpr char kAction[] = "action";
constexpr char kArcManaged[] = "arcManaged";
constexpr char kData[] = "data";
constexpr char kDeviceId[] = "deviceId";
-constexpr char kPage[] = "page";
constexpr char kStatus[] = "status";
constexpr char kActionInitialize[] = "initialize";
-constexpr char kActionSetMetricsMode[] = "setMetricsMode";
-constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
-constexpr char kActionLocationServiceMode[] = "setLocationServiceMode";
constexpr char kActionSetWindowBounds[] = "setWindowBounds";
constexpr char kActionCloseWindow[] = "closeWindow";
+
+
+// Action to show a specified page. "page" attribute should point an ID
+// in the arc_support div.
constexpr char kActionShowPage[] = "showPage";
+constexpr char kPage[] = "page";
+
+// Action to show an error page. "errorMessage" should be localized error
+// text. "showFeedbackButon" is the boolean to specify whether "Feedback"
+// button should be shown.
+constexpr char kActionShowErrorPage[] = "showErrorPage";
+constexpr char kErrorMessage[] = "errorMessage";
+constexpr char kShowFeedbackButton[] = "showFeedbackButton";
-// The preference update should have those two fields.
+// Actions to update a Preference checkbox.
+constexpr char kActionSetMetricsMode[] = "setMetricsMode";
+constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
+constexpr char kActionLocationServiceMode[] = "setLocationServiceMode";
+
+// The preference checkbox should have those two fields.
constexpr char kEnabled[] = "enabled";
constexpr char kManaged[] = "managed";
@@ -79,13 +96,7 @@ const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei";
// static
const char ArcSupportHost::kStorageId[] = "arc_support";
-ArcSupportHost::ArcSupportHost() {
- // TODO(hidehiko): Get rid of dependency to ArcAuthService.
- arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
- DCHECK(arc_auth_service);
-
- if (!arc_auth_service->IsAllowed())
- return;
+ArcSupportHost::ArcSupportHost(Profile* profile) : profile_(profile) {
}
ArcSupportHost::~ArcSupportHost() {
@@ -94,6 +105,7 @@ ArcSupportHost::~ArcSupportHost() {
}
void ArcSupportHost::Close() {
+ ui_page_ = UIPage::NO_PAGE;
if (!message_host_) {
VLOG(2) << "ArcSupportHost::Close() is called "
<< "but message_host_ is not available.";
@@ -109,18 +121,130 @@ void ArcSupportHost::Close() {
DisconnectMessageHost();
}
-void ArcSupportHost::ShowPage(arc::ArcAuthService::UIPage page,
- const base::string16& status) {
+void ArcSupportHost::ShowTermsOfServicePage() {
+ ShowPageInternal(UIPage::TERMS);
+}
+
+void ArcSupportHost::ShowLsoPage() {
+ ShowPageInternal(UIPage::LSO);
+}
+
+void ArcSupportHost::ShowLoadingPage() {
+ ShowPageInternal(UIPage::LOADING);
+}
+
+void ArcSupportHost::ShowPageInternal(UIPage ui_page) {
+ ui_page_ = ui_page;
if (!message_host_) {
- VLOG(2) << "ArcSupportHost::ShowPage() is called "
- << "but message_host_ is not available.";
+ if (window_open_requested_) {
+ VLOG(2) << "ArcSupportHost::ShowPageInternal() is called "
+ << "but message_host_ is not available.";
+ return;
+ }
+
+ RequestWindowOpen();
return;
}
base::DictionaryValue message;
message.SetString(kAction, kActionShowPage);
- message.SetInteger(kPage, static_cast<int>(page));
- message.SetString(kStatus, status);
+ switch (ui_page) {
+ case UIPage::TERMS:
+ message.SetString(kPage, "terms");
+ break;
+ case UIPage::LSO:
+ // TODO(hidehiko): Unify the LSO loading page into LSO page.
+ message.SetString(kPage, "lso-loading");
+ break;
+ case UIPage::LOADING:
+ message.SetString(kPage, "arc-loading");
+ break;
+ default:
+ NOTREACHED();
+ return;
+ }
+ message_host_->SendMessage(message);
+}
+
+void ArcSupportHost::ShowErrorPage(
+ ErrorType error_type, bool show_feedback_button) {
+ ui_page_ = UIPage::ERROR;
+ error_type_ = error_type;
+ show_feedback_button_ = show_feedback_button;
+ if (!message_host_) {
+ if (window_open_requested_) {
+ VLOG(2) << "ArcSupportHost::ShowErrorPage() is called "
+ << "but message_host_ is not available.";
+ return;
+ }
+
+ RequestWindowOpen();
+ return;
+ }
+
+ base::DictionaryValue message;
+ message.SetString(kAction, kActionShowErrorPage);
+ int message_id;
+ switch (error_type) {
+ case ErrorType::SIGN_IN_NETWORK_ERROR:
+ message_id = IDS_ARC_SIGN_IN_NETWORK_ERROR;
+ break;
+ case ErrorType::SIGN_IN_SERVICE_UNAVAILABLE_ERROR:
+ message_id = IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR;
+ break;
+ case ErrorType::SIGN_IN_BAD_AUTHENTICATION_ERROR:
+ message_id = IDS_ARC_SIGN_IN_BAD_AUTHENTICATION_ERROR;
+ break;
+ case ErrorType::SIGN_IN_GMS_NOT_AVAILABLE_ERROR:
+ message_id = IDS_ARC_SIGN_IN_GMS_NOT_AVAILABLE_ERROR;
+ break;
+ case ErrorType::SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR:
+ message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
+ break;
+ case ErrorType::SIGN_IN_UNKNOWN_ERROR:
+ message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR;
+ break;
+ case ErrorType::SERVER_COMMUNICATION_ERROR:
+ message_id = IDS_ARC_SERVER_COMMUNICATION_ERROR;
+ break;
+ case ErrorType::ANDROID_MANAGEMENT_REQUIRED_ERROR:
+ message_id = IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR;
+ break;
+ }
+ message.SetString(kErrorMessage, l10n_util::GetStringUTF16(message_id));
+ message.SetBoolean(kShowFeedbackButton, show_feedback_button);
+ message_host_->SendMessage(message);
+}
+
+void ArcSupportHost::SetMetricsCheckbox(bool is_enabled, bool is_managed) {
+ metrics_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
+ SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_);
+}
+
+void ArcSupportHost::SetBackupAndRestoreCheckbox(
+ bool is_enabled, bool is_managed) {
+ backup_and_restore_checkbox_ =
+ PreferenceCheckboxData(is_enabled, is_managed);
+ SendPreferenceCheckboxUpdate(kActionBackupAndRestoreMode,
+ backup_and_restore_checkbox_);
+}
+
+void ArcSupportHost::SetLocationServiceCheckbox(
+ bool is_enabled, bool is_managed) {
+ location_service_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
+ SendPreferenceCheckboxUpdate(kActionLocationServiceMode,
+ location_service_checkbox_);
+}
+
+void ArcSupportHost::SendPreferenceCheckboxUpdate(
+ const std::string& action_name, const PreferenceCheckboxData& data) {
+ if (!message_host_)
+ return;
+
+ base::DictionaryValue message;
+ message.SetString(kAction, action_name);
+ message.SetBoolean(kEnabled, data.is_enabled);
+ message.SetBoolean(kManaged, data.is_managed);
message_host_->SendMessage(message);
}
@@ -128,6 +252,7 @@ void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) {
if (message_host_ == message_host)
return;
+ window_open_requested_ = false;
if (message_host_)
DisconnectMessageHost();
message_host_ = message_host;
@@ -139,15 +264,22 @@ void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) {
return;
}
- arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
- DCHECK(arc_auth_service);
-
- preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>(
- this, arc_auth_service->profile()->GetPrefs());
- // This automatically updates all preferences.
- preference_handler_->Start();
+ // Send cached PreferenceCheckbox data.
+ SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_);
+ SendPreferenceCheckboxUpdate(
+ kActionBackupAndRestoreMode, backup_and_restore_checkbox_);
+ SendPreferenceCheckboxUpdate(
+ kActionLocationServiceMode, location_service_checkbox_);
- ShowPage(arc_auth_service->ui_page(), arc_auth_service->ui_page_status());
+ // Update UI page.
+ if (ui_page_ == UIPage::NO_PAGE) {
+ // Close() is called before opening the window.
+ Close();
+ } else if (ui_page_ == UIPage::ERROR) {
+ ShowErrorPage(error_type_, show_feedback_button_);
+ } else {
+ ShowPageInternal(ui_page_);
+ }
}
void ArcSupportHost::UnsetMessageHost(
@@ -159,18 +291,28 @@ void ArcSupportHost::UnsetMessageHost(
void ArcSupportHost::DisconnectMessageHost() {
DCHECK(message_host_);
- preference_handler_.reset();
display::Screen::GetScreen()->RemoveObserver(this);
message_host_->SetObserver(nullptr);
message_host_ = nullptr;
}
+void ArcSupportHost::RequestWindowOpen() {
+ DCHECK(!message_host_);
+ DCHECK(!window_open_requested_);
+
+ const extensions::Extension* extension =
+ extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
+ kHostAppId);
+ CHECK(extension);
+ CHECK(extensions::util::IsAppLaunchable(kHostAppId, profile_));
+ OpenApplication(CreateAppLaunchParamsUserContainer(
+ profile_, extension, WindowOpenDisposition::NEW_WINDOW,
+ extensions::SOURCE_CHROME_INTERNAL));
+ window_open_requested_ = true;
+}
+
bool ArcSupportHost::Initialize() {
DCHECK(message_host_);
- arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
- if (!arc_auth_service->IsAllowed())
- return false;
-
std::unique_ptr<base::DictionaryValue> loadtime_data(
new base::DictionaryValue());
base::string16 device_name = ash::GetChromeOSDeviceName();
@@ -247,16 +389,17 @@ bool ArcSupportHost::Initialize() {
const std::string& app_locale = g_browser_process->GetApplicationLocale();
const std::string& country_code = base::CountryCodeForCurrentTimezone();
loadtime_data->SetString("countryCode", country_code);
- loadtime_data->SetBoolean(kArcManaged, arc_auth_service->IsArcManaged());
-
+ // TODO(hidehiko): Temporarily duplicate the code for the refactoring.
+ // Merge IsArcManaged function well.
+ loadtime_data->SetBoolean(
+ kArcManaged,
+ profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled));
webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get());
- DCHECK(arc_auth_service);
const std::string device_id = user_manager::known_user::GetDeviceId(
- multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile()));
+ multi_user_util::GetAccountIdFromProfile(profile_));
DCHECK(!device_id.empty());
loadtime_data->SetBoolean(
- "isOwnerProfile",
- chromeos::ProfileHelper::IsOwnerProfile(arc_auth_service->profile()));
+ "isOwnerProfile", chromeos::ProfileHelper::IsOwnerProfile(profile_));
base::DictionaryValue message;
message.SetString(kAction, kActionInitialize);
@@ -280,31 +423,6 @@ void ArcSupportHost::OnDisplayMetricsChanged(const display::Display& display,
message_host_->SendMessage(message);
}
-void ArcSupportHost::OnMetricsModeChanged(bool enabled, bool managed) {
- SendPreferenceUpdate(kActionSetMetricsMode, enabled, managed);
-}
-
-void ArcSupportHost::OnBackupAndRestoreModeChanged(bool enabled, bool managed) {
- SendPreferenceUpdate(kActionBackupAndRestoreMode, enabled, managed);
-}
-
-void ArcSupportHost::OnLocationServicesModeChanged(bool enabled, bool managed) {
- SendPreferenceUpdate(kActionLocationServiceMode, enabled, managed);
-}
-
-void ArcSupportHost::SendPreferenceUpdate(const std::string& action_name,
- bool is_enabled,
- bool is_managed) {
- if (!message_host_)
- return;
-
- base::DictionaryValue message;
- message.SetString(kAction, action_name);
- message.SetBoolean(kEnabled, is_enabled);
- message.SetBoolean(kManaged, is_managed);
- message_host_->SendMessage(message);
-}
-
void ArcSupportHost::OnMessage(const base::DictionaryValue& message) {
std::string event;
if (!message.GetString(kEvent, &event)) {
@@ -312,18 +430,15 @@ void ArcSupportHost::OnMessage(const base::DictionaryValue& message) {
return;
}
- // TODO(hidehiko): Replace by Observer.
- arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
- DCHECK(arc_auth_service);
-
- DCHECK(preference_handler_);
+ if (!observer_)
+ return;
if (event == kEventOnWindowClosed) {
- arc_auth_service->CancelAuthCode();
+ observer_->OnWindowClosed();
} else if (event == kEventOnAuthSuccedded) {
std::string code;
if (message.GetString(kCode, &code)) {
- arc_auth_service->SetAuthCodeAndStartArc(code);
+ observer_->OnAuthSucceeded(code);
} else {
NOTREACHED();
}
@@ -336,15 +451,13 @@ void ArcSupportHost::OnMessage(const base::DictionaryValue& message) {
&is_backup_restore_enabled) &&
message.GetBoolean(kIsLocationServiceEnabled,
&is_location_service_enabled)) {
- preference_handler_->EnableMetrics(is_metrics_enabled);
- preference_handler_->EnableBackupRestore(is_backup_restore_enabled);
- preference_handler_->EnableLocationService(is_location_service_enabled);
- arc_auth_service->StartLso();
+ observer_->OnTermsAgreed(is_metrics_enabled, is_backup_restore_enabled,
+ is_location_service_enabled);
} else {
NOTREACHED();
}
} else if (event == kEventOnSendFeedbackClicked) {
- chrome::OpenFeedbackDialog(nullptr);
+ observer_->OnSendFeedbackClicked();
} else {
LOG(ERROR) << "Unknown message: " << event;
NOTREACHED();

Powered by Google App Engine
This is Rietveld 408576698