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

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

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 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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
12 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h" 11 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h"
13 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler_observe r.h"
14 #include "extensions/browser/api/messaging/native_message_host.h" 12 #include "extensions/browser/api/messaging/native_message_host.h"
15 #include "ui/display/display_observer.h" 13 #include "ui/display/display_observer.h"
16 14
17 namespace arc {
18 class ArcOptInPreferenceHandler;
19 }
20
21 // Native interface to control ARC support chrome App. 15 // Native interface to control ARC support chrome App.
22 // TODO(hidehiko): Move more implementation for the UI control from 16 // TODO(hidehiko): Move more implementation for the UI control from
23 // ArcAuthService to this class and remove 17 // ArcAuthService to this class.
24 // arc::ArcOptInPreferenceHandlerObserver inheritance.
25 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it 18 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it
26 // into "arc" namespace. Add unittests at the time. 19 // into "arc" namespace. Add unittests at the time.
27 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, 20 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer,
28 public arc::ArcOptInPreferenceHandlerObserver,
29 public display::DisplayObserver { 21 public display::DisplayObserver {
30 public: 22 public:
23 enum class UIPage {
24 NO_PAGE, // Hide everything.
25 TERMS, // Terms content page.
26 LSO_PROGRESS, // LSO loading progress page.
27 LSO, // LSO page to enter user's credentials.
28 START_PROGRESS, // Arc starting progress page.
29 ERROR, // Arc start error page.
30 ERROR_WITH_FEEDBACK, // Arc start error page, plus feedback button.
31 };
32
33 // Observer to notify UI event.
34 class Observer {
35 public:
36 virtual ~Observer() = default;
37
38 // Called when the ARC support window is closed.
39 virtual void OnWindowClosed() = 0;
40
41 // Called when the user press AGREE button on ToS page.
42 // TODO(hidehiko): Currently, due to implementation reason,
43 // this is also called when RETRY on error page is clicked. Fix this.
44 virtual void OnTermsAgreed(bool is_metrics_enabled,
45 bool is_backup_and_restore_enabled,
46 bool is_location_service_enabled) = 0;
47
48 // Called when LSO auth token fetch is successfully completed.
49 virtual void OnAuthSucceeded(const std::string& auth_code) = 0;
50
51 // Called when send feedback button on error page is clicked.
52 virtual void OnSendFeedbackClicked() = 0;
53 };
54
31 static const char kHostAppId[]; 55 static const char kHostAppId[];
32 static const char kStorageId[]; 56 static const char kStorageId[];
33 57
34 ArcSupportHost(); 58 ArcSupportHost();
35 ~ArcSupportHost() override; 59 ~ArcSupportHost() override;
36 60
61 void set_observer(Observer* observer) { observer_ = observer; }
Luis Héctor Chávez 2016/11/04 17:55:15 If the plan is to support multiple observers, I'd
hidehiko 2016/11/04 22:19:51 Done.
62
37 // Called when the communication to arc_support Chrome App is ready. 63 // Called when the communication to arc_support Chrome App is ready.
38 void SetMessageHost(arc::ArcSupportMessageHost* message_host); 64 void SetMessageHost(arc::ArcSupportMessageHost* message_host);
39 65
40 // Called when the communication to arc_support Chrome App is closed. 66 // Called when the communication to arc_support Chrome App is closed.
41 // The argument message_host is used to check if the given |message_host| 67 // The argument message_host is used to check if the given |message_host|
42 // is what this instance uses know, to avoid racy case. 68 // is what this instance uses know, to avoid racy case.
43 // If |message_host| is different from the one this instance knows, 69 // If |message_host| is different from the one this instance knows,
44 // this is no op. 70 // this is no op.
45 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); 71 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host);
46 72
47 // Requests to close the extension window. 73 // Requests to close the extension window.
48 void Close(); 74 void Close();
49 void ShowPage(arc::ArcAuthService::UIPage page, const base::string16& status); 75 void ShowPage(UIPage page, const base::string16& status);
76
77 void SetMetricsPreferenceCheckbox(bool is_enabled, bool is_managed);
78 void SetBackupAndRestorePreferenceCheckbox(bool is_enabled, bool is_managed);
79 void SetLocationServicesPreferenceCheckbox(bool is_enabled, bool is_managed);
50 80
51 // arc::ArcSupportMessageHost::Observer override: 81 // arc::ArcSupportMessageHost::Observer override:
52 void OnMessage(const base::DictionaryValue& message) override; 82 void OnMessage(const base::DictionaryValue& message) override;
53 83
54 // display::DisplayObserver: 84 // display::DisplayObserver:
55 void OnDisplayAdded(const display::Display& new_display) override; 85 void OnDisplayAdded(const display::Display& new_display) override;
56 void OnDisplayRemoved(const display::Display& old_display) override; 86 void OnDisplayRemoved(const display::Display& old_display) override;
57 void OnDisplayMetricsChanged(const display::Display& display, 87 void OnDisplayMetricsChanged(const display::Display& display,
58 uint32_t changed_metrics) override; 88 uint32_t changed_metrics) override;
59 89
60 // arc::ArcOptInPreferenceHandlerObserver: 90 private:
61 void OnMetricsModeChanged(bool enabled, bool managed) override; 91 struct PreferenceCheckboxData {
62 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override; 92 PreferenceCheckboxData() : PreferenceCheckboxData(false, false) {}
63 void OnLocationServicesModeChanged(bool enabled, bool managed) override; 93 PreferenceCheckboxData(bool is_enabled, bool is_managed)
94 : is_enabled(is_enabled), is_managed(is_managed) {}
64 95
65 private: 96 bool is_enabled;
97 bool is_managed;
98 };
99
66 bool Initialize(); 100 bool Initialize();
67 101
68 // Sends a preference update to the extension. 102 // Sends a preference update to the extension.
69 // The message will be 103 // The message will be
70 // { 104 // {
71 // 'action': action_name, 105 // 'action': action_name,
72 // 'enabled': is_enabled, 106 // 'enabled': is_enabled,
73 // 'managed': is_managed 107 // 'managed': is_managed
74 // } 108 // }
75 void SendPreferenceUpdate(const std::string& action_name, 109 void SendPreferenceCheckboxUpdate(const std::string& action_name,
76 bool is_enabled, 110 const PreferenceCheckboxData& data);
77 bool is_managed);
78 111
79 void DisconnectMessageHost(); 112 void DisconnectMessageHost();
80 113
114 // Currently Observer is only ArcAuthService, so it is unique.
115 // Use ObserverList when more classes start to observe it.
116 Observer* observer_ = nullptr;
117
118 PreferenceCheckboxData metrics_checkbox_;
119 PreferenceCheckboxData backup_and_restore_checkbox_;
120 PreferenceCheckboxData location_services_checkbox_;
121
81 // The instance is created and managed by Chrome. 122 // The instance is created and managed by Chrome.
82 arc::ArcSupportMessageHost* message_host_ = nullptr; 123 arc::ArcSupportMessageHost* message_host_ = nullptr;
83 124
84 // Handles preferences and metrics mode.
85 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_;
86
87 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 125 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
88 }; 126 };
89 127
90 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 128 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698