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

Side by Side Diff: chrome/browser/chromeos/arc/arc_support_host.cc

Issue 2388763002: Remove controller concept from the ARC support extension. (Closed)
Patch Set: Created 4 years, 2 months 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"
(...skipping 14 matching lines...) Expand all
25 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
26 #include "components/user_manager/known_user.h" 26 #include "components/user_manager/known_user.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/webui/web_ui_util.h" 28 #include "ui/base/webui/web_ui_util.h"
29 #include "ui/display/screen.h" 29 #include "ui/display/screen.h"
30 30
31 namespace { 31 namespace {
32 const char kAction[] = "action"; 32 const char kAction[] = "action";
33 const char kArcManaged[] = "arcManaged"; 33 const char kArcManaged[] = "arcManaged";
34 const char kCanEnable[] = "canEnable"; 34 const char kCanEnable[] = "canEnable";
35 const char kCode[] = "code";
36 const char kData[] = "data"; 35 const char kData[] = "data";
37 const char kDeviceId[] = "deviceId"; 36 const char kDeviceId[] = "deviceId";
38 const char kEnabled[] = "enabled"; 37 const char kEnabled[] = "enabled";
39 const char kManaged[] = "managed"; 38 const char kManaged[] = "managed";
40 const char kOn[] = "on"; 39 const char kOn[] = "on";
41 const char kPage[] = "page"; 40 const char kPage[] = "page";
42 const char kStatus[] = "status"; 41 const char kStatus[] = "status";
43 const char kText[] = "text"; 42 const char kText[] = "text";
44 const char kActionInitialize[] = "initialize"; 43 const char kActionInitialize[] = "initialize";
45 const char kActionSetMetricsMode[] = "setMetricsMode"; 44 const char kActionSetMetricsMode[] = "setMetricsMode";
46 const char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode"; 45 const char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
47 const char kActionLocationServiceMode[] = "setLocationServiceMode"; 46 const char kActionLocationServiceMode[] = "setLocationServiceMode";
48 const char kActionSetWindowBounds[] = "setWindowBounds"; 47 const char kActionSetWindowBounds[] = "setWindowBounds";
49 const char kActionStartLso[] = "startLso";
50 const char kActionSetAuthCode[] = "setAuthCode";
51 const char kActionEnableMetrics[] = "enableMetrics";
52 const char kActionSendFeedback[] = "sendFeedback";
53 const char kActionSetBackupRestore[] = "setBackupRestore";
54 const char kActionSetLocationService[] = "setLocationService";
55 const char kActionCloseWindow[] = "closeWindow"; 48 const char kActionCloseWindow[] = "closeWindow";
56 const char kActionShowPage[] = "showPage"; 49 const char kActionShowPage[] = "showPage";
57 50
58 // Fired when the extension window is closed. 51 // The JSON data sent from the extension should have at least "event" field.
59 const char kActionOnWindowClosed[] = "onWindowClosed"; 52 // Each event data is defined below.
53 // The key of the event type.
54 const char kEvent[] = "event";
Luis Héctor Chávez 2016/10/03 20:40:16 can you make all of these constexpr now that you'r
hidehiko 2016/10/04 04:48:19 Sure. Done.
55
56 // "onWindowClosed" is fired when the extension window is closed.
57 // No data will be provided.
58 const char kEventOnWindowClosed[] = "onWindowClosed";
59
60 // "onAuthSucceeded" is fired when successfully done to LSO authorization in
61 // extension.
62 // The auth token is passed via "code" field.
63 const char kEventOnAuthSuccedded[] = "onAuthSucceeded";
64 const char kCode[] = "code";
65
66 // "onAgree" is fired when a user clicks "Agree" button.
67 // The message can have the following three optional fields:
68 // - isMetricsEnabled
69 // - isBackupRestoreEnabled
70 // - isLocationServiceEnabled
71 const char kEventOnAgreed[] = "onAgreed";
72 const char kIsMetricsEnabled[] = "isMetricsEnabled";
73 const char kIsBackupRestoreEnabled[] = "isBackupRestoreEnabled";
74 const char kIsLocationServiceEnabled[] = "isLocationServiceEnabled";
75
76 // "onSendFeedbackClicked" is fired when a user clicks "Send Feedback" button.
77 const char kEventOnSendFeedbackClicked[] = "onSendFeedbackClicked";
60 78
61 } // namespace 79 } // namespace
62 80
63 // static 81 // static
64 const char ArcSupportHost::kHostName[] = "com.google.arc_support"; 82 const char ArcSupportHost::kHostName[] = "com.google.arc_support";
65 83
66 // static 84 // static
67 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; 85 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei";
68 86
69 // static 87 // static
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled); 346 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled);
329 } 347 }
330 348
331 void ArcSupportHost::EnableLocationService(bool is_enabled) { 349 void ArcSupportHost::EnableLocationService(bool is_enabled) {
332 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 350 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
333 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); 351 DCHECK(arc_auth_service && arc_auth_service->IsAllowed());
334 PrefService* pref_service = arc_auth_service->profile()->GetPrefs(); 352 PrefService* pref_service = arc_auth_service->profile()->GetPrefs();
335 pref_service->SetBoolean(prefs::kArcLocationServiceEnabled, is_enabled); 353 pref_service->SetBoolean(prefs::kArcLocationServiceEnabled, is_enabled);
336 } 354 }
337 355
338 void ArcSupportHost::OnMessage(const std::string& request_string) { 356 void ArcSupportHost::OnMessage(const std::string& message_string) {
339 std::unique_ptr<base::Value> request_value = 357 std::unique_ptr<base::Value> message_value =
340 base::JSONReader::Read(request_string); 358 base::JSONReader::Read(message_string);
341 base::DictionaryValue* request; 359 base::DictionaryValue* message;
342 if (!request_value || !request_value->GetAsDictionary(&request)) { 360 if (!message_value || !message_value->GetAsDictionary(&message)) {
343 NOTREACHED(); 361 NOTREACHED();
344 return; 362 return;
345 } 363 }
346 364
347 std::string action; 365 std::string event;
348 if (!request->GetString(kAction, &action)) { 366 if (!message->GetString(kEvent, &event)) {
349 NOTREACHED(); 367 NOTREACHED();
350 return; 368 return;
351 } 369 }
352 370
371 // TODO(hidehiko): Replace by Observer.
353 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 372 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
354 DCHECK(arc_auth_service); 373 DCHECK(arc_auth_service);
355 374
356 if (action == kActionStartLso) { 375 if (event == kEventOnWindowClosed) {
357 arc_auth_service->StartLso(); 376 if (!close_requested_)
358 } else if (action == kActionSetAuthCode) { 377 arc_auth_service->CancelAuthCode();
378 return;
379 }
380 if (event == kEventOnAuthSuccedded) {
Luis Héctor Chávez 2016/10/03 20:40:16 any reason why you're not going with "} else if {"
hidehiko 2016/10/04 04:48:19 if ( ... ) { ... return; } is also idiomatic,
Luis Héctor Chávez 2016/10/04 04:57:12 I've mostly seen the early return style when the l
hidehiko 2016/10/04 06:13:08 Ok, done.
359 std::string code; 381 std::string code;
360 if (!request->GetString(kCode, &code)) { 382 if (!message->GetString(kCode, &code)) {
361 NOTREACHED(); 383 NOTREACHED();
362 return; 384 return;
363 } 385 }
364 arc_auth_service->SetAuthCodeAndStartArc(code); 386 arc_auth_service->SetAuthCodeAndStartArc(code);
365 } else if (action == kActionOnWindowClosed) { 387 return;
366 if (!close_requested_) 388 }
367 arc_auth_service->CancelAuthCode(); 389 if (event == kEventOnAgreed) {
368 } else if (action == kActionEnableMetrics) {
369 bool is_enabled; 390 bool is_enabled;
370 if (!request->GetBoolean(kEnabled, &is_enabled)) { 391 if (message->GetBoolean(kIsMetricsEnabled, &is_enabled))
Luis Héctor Chávez 2016/10/03 20:40:16 With the change I suggested, it's probably better
hidehiko 2016/10/04 04:48:19 Done.
371 NOTREACHED(); 392 EnableMetrics(is_enabled);
372 return; 393 if (message->GetBoolean(kIsBackupRestoreEnabled, &is_enabled))
373 } 394 EnableBackupRestore(is_enabled);
374 EnableMetrics(is_enabled); 395 if (message->GetBoolean(kIsLocationServiceEnabled, &is_enabled))
375 } else if (action == kActionSendFeedback) { 396 EnableLocationService(is_enabled);
397 arc_auth_service->StartLso();
398 return;
399 }
400 if (event == kEventOnSendFeedbackClicked) {
376 chrome::OpenFeedbackDialog(nullptr); 401 chrome::OpenFeedbackDialog(nullptr);
377 } else if (action == kActionSetBackupRestore) { 402 return;
378 bool is_enabled;
379 if (!request->GetBoolean(kEnabled, &is_enabled)) {
380 NOTREACHED();
381 return;
382 }
383 EnableBackupRestore(is_enabled);
384 } else if (action == kActionSetLocationService) {
385 bool is_enabled;
386 if (!request->GetBoolean(kEnabled, &is_enabled)) {
387 NOTREACHED();
388 return;
389 }
390 EnableLocationService(is_enabled);
391 } else {
392 NOTREACHED();
393 } 403 }
404
405 LOG(ERROR) << "Unknown message: " << message_string;
406 NOTREACHED();
394 } 407 }
395 408
396 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() 409 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner()
397 const { 410 const {
398 return base::ThreadTaskRunnerHandle::Get(); 411 return base::ThreadTaskRunnerHandle::Get();
399 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698