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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/arc/arc_support_host.h" 5 #include "chrome/browser/chromeos/arc/arc_support_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/common/system/chromeos/devicetype_utils.h" 9 #include "ash/common/system/chromeos/devicetype_utils.h"
10 #include "base/i18n/timezone.h" 10 #include "base/i18n/timezone.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/extensions/extension_util.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 19 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
20 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/extensions/app_launch_params.h"
21 #include "chrome/browser/ui/extensions/application_launch.h"
22 #include "chrome/common/pref_names.h"
21 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "components/prefs/pref_service.h"
22 #include "components/user_manager/known_user.h" 25 #include "components/user_manager/known_user.h"
26 #include "extensions/browser/extension_registry.h"
23 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/webui/web_ui_util.h" 28 #include "ui/base/webui/web_ui_util.h"
25 #include "ui/display/screen.h" 29 #include "ui/display/screen.h"
26 30
27 namespace { 31 namespace {
28 constexpr char kAction[] = "action"; 32 constexpr char kAction[] = "action";
29 constexpr char kArcManaged[] = "arcManaged"; 33 constexpr char kArcManaged[] = "arcManaged";
30 constexpr char kData[] = "data"; 34 constexpr char kData[] = "data";
31 constexpr char kDeviceId[] = "deviceId"; 35 constexpr char kDeviceId[] = "deviceId";
32 constexpr char kPage[] = "page";
33 constexpr char kStatus[] = "status"; 36 constexpr char kStatus[] = "status";
34 constexpr char kActionInitialize[] = "initialize"; 37 constexpr char kActionInitialize[] = "initialize";
38 constexpr char kActionSetWindowBounds[] = "setWindowBounds";
39 constexpr char kActionCloseWindow[] = "closeWindow";
40
41
42 // Action to show a specified page. "page" attribute should point an ID
43 // in the arc_support div.
44 constexpr char kActionShowPage[] = "showPage";
45 constexpr char kPage[] = "page";
46
47 // Action to show an error page. "errorMessage" should be localized error
48 // text. "showFeedbackButon" is the boolean to specify whether "Feedback"
49 // button should be shown.
50 constexpr char kActionShowErrorPage[] = "showErrorPage";
51 constexpr char kErrorMessage[] = "errorMessage";
52 constexpr char kShowFeedbackButton[] = "showFeedbackButton";
53
54 // Actions to update a Preference checkbox.
35 constexpr char kActionSetMetricsMode[] = "setMetricsMode"; 55 constexpr char kActionSetMetricsMode[] = "setMetricsMode";
36 constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode"; 56 constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
37 constexpr char kActionLocationServiceMode[] = "setLocationServiceMode"; 57 constexpr char kActionLocationServiceMode[] = "setLocationServiceMode";
38 constexpr char kActionSetWindowBounds[] = "setWindowBounds";
39 constexpr char kActionCloseWindow[] = "closeWindow";
40 constexpr char kActionShowPage[] = "showPage";
41 58
42 // The preference update should have those two fields. 59 // The preference checkbox should have those two fields.
43 constexpr char kEnabled[] = "enabled"; 60 constexpr char kEnabled[] = "enabled";
44 constexpr char kManaged[] = "managed"; 61 constexpr char kManaged[] = "managed";
45 62
46 // The JSON data sent from the extension should have at least "event" field. 63 // The JSON data sent from the extension should have at least "event" field.
47 // Each event data is defined below. 64 // Each event data is defined below.
48 // The key of the event type. 65 // The key of the event type.
49 constexpr char kEvent[] = "event"; 66 constexpr char kEvent[] = "event";
50 67
51 // "onWindowClosed" is fired when the extension window is closed. 68 // "onWindowClosed" is fired when the extension window is closed.
52 // No data will be provided. 69 // No data will be provided.
(...skipping 19 matching lines...) Expand all
72 constexpr char kEventOnSendFeedbackClicked[] = "onSendFeedbackClicked"; 89 constexpr char kEventOnSendFeedbackClicked[] = "onSendFeedbackClicked";
73 90
74 } // namespace 91 } // namespace
75 92
76 // static 93 // static
77 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; 94 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei";
78 95
79 // static 96 // static
80 const char ArcSupportHost::kStorageId[] = "arc_support"; 97 const char ArcSupportHost::kStorageId[] = "arc_support";
81 98
82 ArcSupportHost::ArcSupportHost() { 99 ArcSupportHost::ArcSupportHost(Profile* profile) : profile_(profile) {
83 // TODO(hidehiko): Get rid of dependency to ArcAuthService.
84 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
85 DCHECK(arc_auth_service);
86
87 if (!arc_auth_service->IsAllowed())
88 return;
89 } 100 }
90 101
91 ArcSupportHost::~ArcSupportHost() { 102 ArcSupportHost::~ArcSupportHost() {
92 if (message_host_) 103 if (message_host_)
93 DisconnectMessageHost(); 104 DisconnectMessageHost();
94 } 105 }
95 106
96 void ArcSupportHost::Close() { 107 void ArcSupportHost::Close() {
108 ui_page_ = UIPage::NO_PAGE;
97 if (!message_host_) { 109 if (!message_host_) {
98 VLOG(2) << "ArcSupportHost::Close() is called " 110 VLOG(2) << "ArcSupportHost::Close() is called "
99 << "but message_host_ is not available."; 111 << "but message_host_ is not available.";
100 return; 112 return;
101 } 113 }
102 114
103 base::DictionaryValue message; 115 base::DictionaryValue message;
104 message.SetString(kAction, kActionCloseWindow); 116 message.SetString(kAction, kActionCloseWindow);
105 message_host_->SendMessage(message); 117 message_host_->SendMessage(message);
106 118
107 // Disconnect immediately, so that onWindowClosed event will not be 119 // Disconnect immediately, so that onWindowClosed event will not be
108 // delivered to here. 120 // delivered to here.
109 DisconnectMessageHost(); 121 DisconnectMessageHost();
110 } 122 }
111 123
112 void ArcSupportHost::ShowPage(arc::ArcAuthService::UIPage page, 124 void ArcSupportHost::ShowTermsOfServicePage() {
113 const base::string16& status) { 125 ShowPageInternal(UIPage::TERMS);
126 }
127
128 void ArcSupportHost::ShowLsoPage() {
129 ShowPageInternal(UIPage::LSO);
130 }
131
132 void ArcSupportHost::ShowLoadingPage() {
133 ShowPageInternal(UIPage::LOADING);
134 }
135
136 void ArcSupportHost::ShowPageInternal(UIPage ui_page) {
137 ui_page_ = ui_page;
114 if (!message_host_) { 138 if (!message_host_) {
115 VLOG(2) << "ArcSupportHost::ShowPage() is called " 139 if (window_open_requested_) {
116 << "but message_host_ is not available."; 140 VLOG(2) << "ArcSupportHost::ShowPageInternal() is called "
141 << "but message_host_ is not available.";
142 return;
143 }
144
145 RequestWindowOpen();
117 return; 146 return;
118 } 147 }
119 148
120 base::DictionaryValue message; 149 base::DictionaryValue message;
121 message.SetString(kAction, kActionShowPage); 150 message.SetString(kAction, kActionShowPage);
122 message.SetInteger(kPage, static_cast<int>(page)); 151 switch (ui_page) {
123 message.SetString(kStatus, status); 152 case UIPage::TERMS:
153 message.SetString(kPage, "terms");
154 break;
155 case UIPage::LSO:
156 // TODO(hidehiko): Unify the LSO loading page into LSO page.
157 message.SetString(kPage, "lso-loading");
158 break;
159 case UIPage::LOADING:
160 message.SetString(kPage, "arc-loading");
161 break;
162 default:
163 NOTREACHED();
164 return;
165 }
124 message_host_->SendMessage(message); 166 message_host_->SendMessage(message);
125 } 167 }
126 168
169 void ArcSupportHost::ShowErrorPage(
170 ErrorType error_type, bool show_feedback_button) {
171 ui_page_ = UIPage::ERROR;
172 error_type_ = error_type;
173 show_feedback_button_ = show_feedback_button;
174 if (!message_host_) {
175 if (window_open_requested_) {
176 VLOG(2) << "ArcSupportHost::ShowErrorPage() is called "
177 << "but message_host_ is not available.";
178 return;
179 }
180
181 RequestWindowOpen();
182 return;
183 }
184
185 base::DictionaryValue message;
186 message.SetString(kAction, kActionShowErrorPage);
187 int message_id;
188 switch (error_type) {
189 case ErrorType::SIGN_IN_NETWORK_ERROR:
190 message_id = IDS_ARC_SIGN_IN_NETWORK_ERROR;
191 break;
192 case ErrorType::SIGN_IN_SERVICE_UNAVAILABLE_ERROR:
193 message_id = IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR;
194 break;
195 case ErrorType::SIGN_IN_BAD_AUTHENTICATION_ERROR:
196 message_id = IDS_ARC_SIGN_IN_BAD_AUTHENTICATION_ERROR;
197 break;
198 case ErrorType::SIGN_IN_GMS_NOT_AVAILABLE_ERROR:
199 message_id = IDS_ARC_SIGN_IN_GMS_NOT_AVAILABLE_ERROR;
200 break;
201 case ErrorType::SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR:
202 message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
203 break;
204 case ErrorType::SIGN_IN_UNKNOWN_ERROR:
205 message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR;
206 break;
207 case ErrorType::SERVER_COMMUNICATION_ERROR:
208 message_id = IDS_ARC_SERVER_COMMUNICATION_ERROR;
209 break;
210 case ErrorType::ANDROID_MANAGEMENT_REQUIRED_ERROR:
211 message_id = IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR;
212 break;
213 }
214 message.SetString(kErrorMessage, l10n_util::GetStringUTF16(message_id));
215 message.SetBoolean(kShowFeedbackButton, show_feedback_button);
216 message_host_->SendMessage(message);
217 }
218
219 void ArcSupportHost::SetMetricsCheckbox(bool is_enabled, bool is_managed) {
220 metrics_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
221 SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_);
222 }
223
224 void ArcSupportHost::SetBackupAndRestoreCheckbox(
225 bool is_enabled, bool is_managed) {
226 backup_and_restore_checkbox_ =
227 PreferenceCheckboxData(is_enabled, is_managed);
228 SendPreferenceCheckboxUpdate(kActionBackupAndRestoreMode,
229 backup_and_restore_checkbox_);
230 }
231
232 void ArcSupportHost::SetLocationServiceCheckbox(
233 bool is_enabled, bool is_managed) {
234 location_service_checkbox_ = PreferenceCheckboxData(is_enabled, is_managed);
235 SendPreferenceCheckboxUpdate(kActionLocationServiceMode,
236 location_service_checkbox_);
237 }
238
239 void ArcSupportHost::SendPreferenceCheckboxUpdate(
240 const std::string& action_name, const PreferenceCheckboxData& data) {
241 if (!message_host_)
242 return;
243
244 base::DictionaryValue message;
245 message.SetString(kAction, action_name);
246 message.SetBoolean(kEnabled, data.is_enabled);
247 message.SetBoolean(kManaged, data.is_managed);
248 message_host_->SendMessage(message);
249 }
250
127 void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) { 251 void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) {
128 if (message_host_ == message_host) 252 if (message_host_ == message_host)
129 return; 253 return;
130 254
255 window_open_requested_ = false;
131 if (message_host_) 256 if (message_host_)
132 DisconnectMessageHost(); 257 DisconnectMessageHost();
133 message_host_ = message_host; 258 message_host_ = message_host;
134 message_host_->SetObserver(this); 259 message_host_->SetObserver(this);
135 display::Screen::GetScreen()->AddObserver(this); 260 display::Screen::GetScreen()->AddObserver(this);
136 261
137 if (!Initialize()) { 262 if (!Initialize()) {
138 Close(); 263 Close();
139 return; 264 return;
140 } 265 }
141 266
142 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 267 // Send cached PreferenceCheckbox data.
143 DCHECK(arc_auth_service); 268 SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_);
269 SendPreferenceCheckboxUpdate(
270 kActionBackupAndRestoreMode, backup_and_restore_checkbox_);
271 SendPreferenceCheckboxUpdate(
272 kActionLocationServiceMode, location_service_checkbox_);
144 273
145 preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>( 274 // Update UI page.
146 this, arc_auth_service->profile()->GetPrefs()); 275 if (ui_page_ == UIPage::NO_PAGE) {
147 // This automatically updates all preferences. 276 // Close() is called before opening the window.
148 preference_handler_->Start(); 277 Close();
149 278 } else if (ui_page_ == UIPage::ERROR) {
150 ShowPage(arc_auth_service->ui_page(), arc_auth_service->ui_page_status()); 279 ShowErrorPage(error_type_, show_feedback_button_);
280 } else {
281 ShowPageInternal(ui_page_);
282 }
151 } 283 }
152 284
153 void ArcSupportHost::UnsetMessageHost( 285 void ArcSupportHost::UnsetMessageHost(
154 arc::ArcSupportMessageHost* message_host) { 286 arc::ArcSupportMessageHost* message_host) {
155 if (message_host_ != message_host) 287 if (message_host_ != message_host)
156 return; 288 return;
157 DisconnectMessageHost(); 289 DisconnectMessageHost();
158 } 290 }
159 291
160 void ArcSupportHost::DisconnectMessageHost() { 292 void ArcSupportHost::DisconnectMessageHost() {
161 DCHECK(message_host_); 293 DCHECK(message_host_);
162 preference_handler_.reset();
163 display::Screen::GetScreen()->RemoveObserver(this); 294 display::Screen::GetScreen()->RemoveObserver(this);
164 message_host_->SetObserver(nullptr); 295 message_host_->SetObserver(nullptr);
165 message_host_ = nullptr; 296 message_host_ = nullptr;
166 } 297 }
167 298
299 void ArcSupportHost::RequestWindowOpen() {
300 DCHECK(!message_host_);
301 DCHECK(!window_open_requested_);
302
303 const extensions::Extension* extension =
304 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
305 kHostAppId);
306 CHECK(extension);
307 CHECK(extensions::util::IsAppLaunchable(kHostAppId, profile_));
308 OpenApplication(CreateAppLaunchParamsUserContainer(
309 profile_, extension, WindowOpenDisposition::NEW_WINDOW,
310 extensions::SOURCE_CHROME_INTERNAL));
311 window_open_requested_ = true;
312 }
313
168 bool ArcSupportHost::Initialize() { 314 bool ArcSupportHost::Initialize() {
169 DCHECK(message_host_); 315 DCHECK(message_host_);
170 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
171 if (!arc_auth_service->IsAllowed())
172 return false;
173
174 std::unique_ptr<base::DictionaryValue> loadtime_data( 316 std::unique_ptr<base::DictionaryValue> loadtime_data(
175 new base::DictionaryValue()); 317 new base::DictionaryValue());
176 base::string16 device_name = ash::GetChromeOSDeviceName(); 318 base::string16 device_name = ash::GetChromeOSDeviceName();
177 loadtime_data->SetString( 319 loadtime_data->SetString(
178 "greetingHeader", 320 "greetingHeader",
179 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); 321 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name));
180 loadtime_data->SetString("greetingDescription", 322 loadtime_data->SetString("greetingDescription",
181 l10n_util::GetStringFUTF16( 323 l10n_util::GetStringFUTF16(
182 IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, device_name)); 324 IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, device_name));
183 loadtime_data->SetString( 325 loadtime_data->SetString(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 loadtime_data->SetString( 382 loadtime_data->SetString(
241 "overlayClose", 383 "overlayClose",
242 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_LEARN_MORE_CLOSE)); 384 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_LEARN_MORE_CLOSE));
243 loadtime_data->SetString( 385 loadtime_data->SetString(
244 "privacyPolicyLink", 386 "privacyPolicyLink",
245 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_PRIVACY_POLICY_LINK)); 387 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_PRIVACY_POLICY_LINK));
246 388
247 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 389 const std::string& app_locale = g_browser_process->GetApplicationLocale();
248 const std::string& country_code = base::CountryCodeForCurrentTimezone(); 390 const std::string& country_code = base::CountryCodeForCurrentTimezone();
249 loadtime_data->SetString("countryCode", country_code); 391 loadtime_data->SetString("countryCode", country_code);
250 loadtime_data->SetBoolean(kArcManaged, arc_auth_service->IsArcManaged()); 392 // TODO(hidehiko): Temporarily duplicate the code for the refactoring.
251 393 // Merge IsArcManaged function well.
394 loadtime_data->SetBoolean(
395 kArcManaged,
396 profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled));
252 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); 397 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get());
253 DCHECK(arc_auth_service);
254 const std::string device_id = user_manager::known_user::GetDeviceId( 398 const std::string device_id = user_manager::known_user::GetDeviceId(
255 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); 399 multi_user_util::GetAccountIdFromProfile(profile_));
256 DCHECK(!device_id.empty()); 400 DCHECK(!device_id.empty());
257 loadtime_data->SetBoolean( 401 loadtime_data->SetBoolean(
258 "isOwnerProfile", 402 "isOwnerProfile", chromeos::ProfileHelper::IsOwnerProfile(profile_));
259 chromeos::ProfileHelper::IsOwnerProfile(arc_auth_service->profile()));
260 403
261 base::DictionaryValue message; 404 base::DictionaryValue message;
262 message.SetString(kAction, kActionInitialize); 405 message.SetString(kAction, kActionInitialize);
263 message.Set(kData, std::move(loadtime_data)); 406 message.Set(kData, std::move(loadtime_data));
264 message.SetString(kDeviceId, device_id); 407 message.SetString(kDeviceId, device_id);
265 message_host_->SendMessage(message); 408 message_host_->SendMessage(message);
266 return true; 409 return true;
267 } 410 }
268 411
269 void ArcSupportHost::OnDisplayAdded(const display::Display& new_display) {} 412 void ArcSupportHost::OnDisplayAdded(const display::Display& new_display) {}
270 413
271 void ArcSupportHost::OnDisplayRemoved(const display::Display& old_display) {} 414 void ArcSupportHost::OnDisplayRemoved(const display::Display& old_display) {}
272 415
273 void ArcSupportHost::OnDisplayMetricsChanged(const display::Display& display, 416 void ArcSupportHost::OnDisplayMetricsChanged(const display::Display& display,
274 uint32_t changed_metrics) { 417 uint32_t changed_metrics) {
275 if (!message_host_) 418 if (!message_host_)
276 return; 419 return;
277 420
278 base::DictionaryValue message; 421 base::DictionaryValue message;
279 message.SetString(kAction, kActionSetWindowBounds); 422 message.SetString(kAction, kActionSetWindowBounds);
280 message_host_->SendMessage(message); 423 message_host_->SendMessage(message);
281 } 424 }
282 425
283 void ArcSupportHost::OnMetricsModeChanged(bool enabled, bool managed) {
284 SendPreferenceUpdate(kActionSetMetricsMode, enabled, managed);
285 }
286
287 void ArcSupportHost::OnBackupAndRestoreModeChanged(bool enabled, bool managed) {
288 SendPreferenceUpdate(kActionBackupAndRestoreMode, enabled, managed);
289 }
290
291 void ArcSupportHost::OnLocationServicesModeChanged(bool enabled, bool managed) {
292 SendPreferenceUpdate(kActionLocationServiceMode, enabled, managed);
293 }
294
295 void ArcSupportHost::SendPreferenceUpdate(const std::string& action_name,
296 bool is_enabled,
297 bool is_managed) {
298 if (!message_host_)
299 return;
300
301 base::DictionaryValue message;
302 message.SetString(kAction, action_name);
303 message.SetBoolean(kEnabled, is_enabled);
304 message.SetBoolean(kManaged, is_managed);
305 message_host_->SendMessage(message);
306 }
307
308 void ArcSupportHost::OnMessage(const base::DictionaryValue& message) { 426 void ArcSupportHost::OnMessage(const base::DictionaryValue& message) {
309 std::string event; 427 std::string event;
310 if (!message.GetString(kEvent, &event)) { 428 if (!message.GetString(kEvent, &event)) {
311 NOTREACHED(); 429 NOTREACHED();
312 return; 430 return;
313 } 431 }
314 432
315 // TODO(hidehiko): Replace by Observer. 433 if (!observer_)
316 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 434 return;
317 DCHECK(arc_auth_service);
318
319 DCHECK(preference_handler_);
320 435
321 if (event == kEventOnWindowClosed) { 436 if (event == kEventOnWindowClosed) {
322 arc_auth_service->CancelAuthCode(); 437 observer_->OnWindowClosed();
323 } else if (event == kEventOnAuthSuccedded) { 438 } else if (event == kEventOnAuthSuccedded) {
324 std::string code; 439 std::string code;
325 if (message.GetString(kCode, &code)) { 440 if (message.GetString(kCode, &code)) {
326 arc_auth_service->SetAuthCodeAndStartArc(code); 441 observer_->OnAuthSucceeded(code);
327 } else { 442 } else {
328 NOTREACHED(); 443 NOTREACHED();
329 } 444 }
330 } else if (event == kEventOnAgreed) { 445 } else if (event == kEventOnAgreed) {
331 bool is_metrics_enabled; 446 bool is_metrics_enabled;
332 bool is_backup_restore_enabled; 447 bool is_backup_restore_enabled;
333 bool is_location_service_enabled; 448 bool is_location_service_enabled;
334 if (message.GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) && 449 if (message.GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) &&
335 message.GetBoolean(kIsBackupRestoreEnabled, 450 message.GetBoolean(kIsBackupRestoreEnabled,
336 &is_backup_restore_enabled) && 451 &is_backup_restore_enabled) &&
337 message.GetBoolean(kIsLocationServiceEnabled, 452 message.GetBoolean(kIsLocationServiceEnabled,
338 &is_location_service_enabled)) { 453 &is_location_service_enabled)) {
339 preference_handler_->EnableMetrics(is_metrics_enabled); 454 observer_->OnTermsAgreed(is_metrics_enabled, is_backup_restore_enabled,
340 preference_handler_->EnableBackupRestore(is_backup_restore_enabled); 455 is_location_service_enabled);
341 preference_handler_->EnableLocationService(is_location_service_enabled);
342 arc_auth_service->StartLso();
343 } else { 456 } else {
344 NOTREACHED(); 457 NOTREACHED();
345 } 458 }
346 } else if (event == kEventOnSendFeedbackClicked) { 459 } else if (event == kEventOnSendFeedbackClicked) {
347 chrome::OpenFeedbackDialog(nullptr); 460 observer_->OnSendFeedbackClicked();
348 } else { 461 } else {
349 LOG(ERROR) << "Unknown message: " << event; 462 LOG(ERROR) << "Unknown message: " << event;
350 NOTREACHED(); 463 NOTREACHED();
351 } 464 }
352 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698