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

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: Address comments. 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
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/arc_support/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "components/metrics/metrics_pref_names.h" 24 #include "components/metrics/metrics_pref_names.h"
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 constexpr char kAction[] = "action";
33 const char kArcManaged[] = "arcManaged"; 33 constexpr char kArcManaged[] = "arcManaged";
34 const char kCanEnable[] = "canEnable"; 34 constexpr char kCanEnable[] = "canEnable";
35 const char kCode[] = "code"; 35 constexpr char kData[] = "data";
36 const char kData[] = "data"; 36 constexpr char kDeviceId[] = "deviceId";
37 const char kDeviceId[] = "deviceId"; 37 constexpr char kEnabled[] = "enabled";
38 const char kEnabled[] = "enabled"; 38 constexpr char kManaged[] = "managed";
39 const char kManaged[] = "managed"; 39 constexpr char kOn[] = "on";
40 const char kOn[] = "on"; 40 constexpr char kPage[] = "page";
41 const char kPage[] = "page"; 41 constexpr char kStatus[] = "status";
42 const char kStatus[] = "status"; 42 constexpr char kText[] = "text";
43 const char kText[] = "text"; 43 constexpr char kActionInitialize[] = "initialize";
44 const char kActionInitialize[] = "initialize"; 44 constexpr char kActionSetMetricsMode[] = "setMetricsMode";
45 const char kActionSetMetricsMode[] = "setMetricsMode"; 45 constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
46 const char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode"; 46 constexpr char kActionLocationServiceMode[] = "setLocationServiceMode";
47 const char kActionLocationServiceMode[] = "setLocationServiceMode"; 47 constexpr char kActionSetWindowBounds[] = "setWindowBounds";
48 const char kActionSetWindowBounds[] = "setWindowBounds"; 48 constexpr char kActionCloseWindow[] = "closeWindow";
49 const char kActionStartLso[] = "startLso"; 49 constexpr char kActionShowPage[] = "showPage";
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";
56 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 constexpr char kEvent[] = "event";
55
56 // "onWindowClosed" is fired when the extension window is closed.
57 // No data will be provided.
58 constexpr 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 constexpr char kEventOnAuthSuccedded[] = "onAuthSucceeded";
64 constexpr char kCode[] = "code";
65
66 // "onAgree" is fired when a user clicks "Agree" button.
67 // The message should have the following three fields:
68 // - isMetricsEnabled
69 // - isBackupRestoreEnabled
70 // - isLocationServiceEnabled
71 constexpr char kEventOnAgreed[] = "onAgreed";
72 constexpr char kIsMetricsEnabled[] = "isMetricsEnabled";
73 constexpr char kIsBackupRestoreEnabled[] = "isBackupRestoreEnabled";
74 constexpr char kIsLocationServiceEnabled[] = "isLocationServiceEnabled";
75
76 // "onSendFeedbackClicked" is fired when a user clicks "Send Feedback" button.
77 constexpr 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled); 358 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled);
341 } 359 }
342 360
343 void ArcSupportHost::EnableLocationService(bool is_enabled) { 361 void ArcSupportHost::EnableLocationService(bool is_enabled) {
344 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 362 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
345 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); 363 DCHECK(arc_auth_service && arc_auth_service->IsAllowed());
346 PrefService* pref_service = arc_auth_service->profile()->GetPrefs(); 364 PrefService* pref_service = arc_auth_service->profile()->GetPrefs();
347 pref_service->SetBoolean(prefs::kArcLocationServiceEnabled, is_enabled); 365 pref_service->SetBoolean(prefs::kArcLocationServiceEnabled, is_enabled);
348 } 366 }
349 367
350 void ArcSupportHost::OnMessage(const std::string& request_string) { 368 void ArcSupportHost::OnMessage(const std::string& message_string) {
351 std::unique_ptr<base::Value> request_value = 369 std::unique_ptr<base::Value> message_value =
352 base::JSONReader::Read(request_string); 370 base::JSONReader::Read(message_string);
353 base::DictionaryValue* request; 371 base::DictionaryValue* message;
354 if (!request_value || !request_value->GetAsDictionary(&request)) { 372 if (!message_value || !message_value->GetAsDictionary(&message)) {
355 NOTREACHED(); 373 NOTREACHED();
356 return; 374 return;
357 } 375 }
358 376
359 std::string action; 377 std::string event;
360 if (!request->GetString(kAction, &action)) { 378 if (!message->GetString(kEvent, &event)) {
361 NOTREACHED(); 379 NOTREACHED();
362 return; 380 return;
363 } 381 }
364 382
383 // TODO(hidehiko): Replace by Observer.
365 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 384 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
366 DCHECK(arc_auth_service); 385 DCHECK(arc_auth_service);
367 386
368 if (action == kActionStartLso) { 387 if (event == kEventOnWindowClosed) {
369 arc_auth_service->StartLso();
370 } else if (action == kActionSetAuthCode) {
371 std::string code;
372 if (!request->GetString(kCode, &code)) {
373 NOTREACHED();
374 return;
375 }
376 arc_auth_service->SetAuthCodeAndStartArc(code);
377 } else if (action == kActionOnWindowClosed) {
378 if (!close_requested_) 388 if (!close_requested_)
379 arc_auth_service->CancelAuthCode(); 389 arc_auth_service->CancelAuthCode();
380 } else if (action == kActionEnableMetrics) { 390 } else if (event == kEventOnAuthSuccedded) {
381 bool is_enabled; 391 std::string code;
382 if (!request->GetBoolean(kEnabled, &is_enabled)) { 392 if (message->GetString(kCode, &code)) {
393 arc_auth_service->SetAuthCodeAndStartArc(code);
394 } else {
383 NOTREACHED(); 395 NOTREACHED();
384 return;
385 } 396 }
386 EnableMetrics(is_enabled); 397 } else if (event == kEventOnAgreed) {
387 } else if (action == kActionSendFeedback) { 398 bool is_metrics_enabled;
399 bool is_backup_restore_enabled;
400 bool is_location_service_enabled;
401 if (message->GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) &&
402 message->GetBoolean(kIsBackupRestoreEnabled,
403 &is_backup_restore_enabled) &&
404 message->GetBoolean(kIsLocationServiceEnabled,
405 &is_location_service_enabled)) {
406 EnableMetrics(is_metrics_enabled);
407 EnableBackupRestore(is_backup_restore_enabled);
408 EnableLocationService(is_location_service_enabled);
409 arc_auth_service->StartLso();
410 } else {
411 NOTREACHED();
412 }
413 } else if (event == kEventOnSendFeedbackClicked) {
388 chrome::OpenFeedbackDialog(nullptr); 414 chrome::OpenFeedbackDialog(nullptr);
389 } else if (action == kActionSetBackupRestore) {
390 bool is_enabled;
391 if (!request->GetBoolean(kEnabled, &is_enabled)) {
392 NOTREACHED();
393 return;
394 }
395 EnableBackupRestore(is_enabled);
396 } else if (action == kActionSetLocationService) {
397 bool is_enabled;
398 if (!request->GetBoolean(kEnabled, &is_enabled)) {
399 NOTREACHED();
400 return;
401 }
402 EnableLocationService(is_enabled);
403 } else { 415 } else {
416 LOG(ERROR) << "Unknown message: " << message_string;
404 NOTREACHED(); 417 NOTREACHED();
405 } 418 }
406 } 419 }
407 420
408 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() 421 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner()
409 const { 422 const {
410 return base::ThreadTaskRunnerHandle::Get(); 423 return base::ThreadTaskRunnerHandle::Get();
411 } 424 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/arc_support/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698