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

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

Issue 2475073003: Refactor ArcSupportHost and ArcAuthService part 1. (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..42bf0cef2416ac35d35a184fc163227ba486ee8a 100644
--- a/chrome/browser/chromeos/arc/arc_support_host.cc
+++ b/chrome/browser/chromeos/arc/arc_support_host.cc
@@ -13,11 +13,10 @@
#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/arc/arc_auth_service.h"
#include "chrome/browser/chromeos/profiles/profile_helper.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/grit/generated_resources.h"
#include "components/user_manager/known_user.h"
#include "ui/base/l10n/l10n_util.h"
@@ -55,7 +54,7 @@ constexpr char kEventOnWindowClosed[] = "onWindowClosed";
// "onAuthSucceeded" is fired when successfully done to LSO authorization in
// extension.
// The auth token is passed via "code" field.
-constexpr char kEventOnAuthSuccedded[] = "onAuthSucceeded";
+constexpr char kEventOnAuthSucceeded[] = "onAuthSucceeded";
constexpr char kCode[] = "code";
// "onAgree" is fired when a user clicks "Agree" button.
@@ -79,14 +78,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() = default;
ArcSupportHost::~ArcSupportHost() {
if (message_host_)
@@ -109,8 +101,7 @@ void ArcSupportHost::Close() {
DisconnectMessageHost();
}
-void ArcSupportHost::ShowPage(arc::ArcAuthService::UIPage page,
- const base::string16& status) {
+void ArcSupportHost::ShowPage(UIPage page, const base::string16& status) {
if (!message_host_) {
VLOG(2) << "ArcSupportHost::ShowPage() is called "
<< "but message_host_ is not available.";
@@ -124,6 +115,39 @@ void ArcSupportHost::ShowPage(arc::ArcAuthService::UIPage page,
message_host_->SendMessage(message);
}
+void ArcSupportHost::SetMetricsPreferenceCheckbox(bool is_enabled,
+ bool is_managed) {
+ metrics_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
+ SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_);
+}
+
+void ArcSupportHost::SetBackupAndRestorePreferenceCheckbox(bool is_enabled,
+ bool is_managed) {
+ backup_and_restore_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
+ SendPreferenceCheckboxUpdate(kActionBackupAndRestoreMode,
+ backup_and_restore_checkbox_);
+}
+
+void ArcSupportHost::SetLocationServicesPreferenceCheckbox(bool is_enabled,
+ bool is_managed) {
+ location_services_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
+ SendPreferenceCheckboxUpdate(kActionLocationServiceMode,
+ location_services_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);
+}
+
void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) {
if (message_host_ == message_host)
return;
@@ -139,14 +163,14 @@ void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) {
return;
}
+ SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_);
+ SendPreferenceCheckboxUpdate(kActionBackupAndRestoreMode,
+ backup_and_restore_checkbox_);
+ SendPreferenceCheckboxUpdate(kActionLocationServiceMode,
+ location_services_checkbox_);
+
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();
-
ShowPage(arc_auth_service->ui_page(), arc_auth_service->ui_page_status());
}
@@ -159,7 +183,6 @@ void ArcSupportHost::UnsetMessageHost(
void ArcSupportHost::DisconnectMessageHost() {
DCHECK(message_host_);
- preference_handler_.reset();
display::Screen::GetScreen()->RemoveObserver(this);
message_host_->SetObserver(nullptr);
message_host_ = nullptr;
@@ -280,31 +303,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 +310,17 @@ 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_) {
+ LOG(ERROR) << "No observer is found.";
+ return;
+ }
if (event == kEventOnWindowClosed) {
- arc_auth_service->CancelAuthCode();
- } else if (event == kEventOnAuthSuccedded) {
+ observer_->OnWindowClosed();
+ } else if (event == kEventOnAuthSucceeded) {
std::string code;
if (message.GetString(kCode, &code)) {
- arc_auth_service->SetAuthCodeAndStartArc(code);
+ observer_->OnAuthSucceeded(code);
} else {
NOTREACHED();
}
@@ -336,15 +333,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