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

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

Issue 2501013002: Refactor ArcSupportHost and ArcAuthService part2. (Closed)
Patch Set: rebase 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/extensions/arc_support_message_host.h" 11 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h"
12 #include "extensions/browser/api/messaging/native_message_host.h" 12 #include "extensions/browser/api/messaging/native_message_host.h"
13 #include "ui/display/display_observer.h" 13 #include "ui/display/display_observer.h"
14 14
15 class Profile;
16
15 // Native interface to control ARC support chrome App. 17 // Native interface to control ARC support chrome App.
16 // TODO(hidehiko): Move more implementation for the UI control from
17 // ArcAuthService to this class.
18 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it 18 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it
19 // into "arc" namespace. Add unittests at the time. 19 // into "arc" namespace. Add unittests at the time.
20 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, 20 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer,
21 public display::DisplayObserver { 21 public display::DisplayObserver {
22 public: 22 public:
23 enum class UIPage { 23 enum class UIPage {
24 NO_PAGE, // Hide everything. 24 NO_PAGE, // Hide everything.
25 TERMS, // Terms content page. 25 TERMS, // Terms content page.
26 LSO_PROGRESS, // LSO loading progress page. 26 LSO, // LSO page to enter user's credentials.
27 LSO, // LSO page to enter user's credentials. 27 ARC_LOADING, // ARC loading progress page.
28 START_PROGRESS, // Arc starting progress page. 28 ERROR, // ARC start error page.
29 ERROR, // Arc start error page. 29 };
30 ERROR_WITH_FEEDBACK, // Arc start error page, plus feedback button. 30
31 // Error types whose corresponding message ARC support has.
32 enum class Error {
33 SIGN_IN_NETWORK_ERROR,
34 SIGN_IN_SERVICE_UNAVAILABLE_ERROR,
35 SIGN_IN_BAD_AUTHENTICATION_ERROR,
36 SIGN_IN_GMS_NOT_AVAILABLE_ERROR,
37 SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR,
38 SIGN_IN_UNKNOWN_ERROR,
39 SERVER_COMMUNICATION_ERROR,
40 ANDROID_MANAGEMENT_REQUIRED_ERROR,
31 }; 41 };
32 42
33 // Observer to notify UI event. 43 // Observer to notify UI event.
34 class Observer { 44 class Observer {
35 public: 45 public:
36 virtual ~Observer() = default; 46 virtual ~Observer() = default;
37 47
38 // Called when the ARC support window is closed. 48 // Called when the ARC support window is closed.
39 virtual void OnWindowClosed() = 0; 49 virtual void OnWindowClosed() = 0;
40 50
(...skipping 10 matching lines...) Expand all
51 // Called when "RETRY" button on the error page is clicked. 61 // Called when "RETRY" button on the error page is clicked.
52 virtual void OnRetryClicked() = 0; 62 virtual void OnRetryClicked() = 0;
53 63
54 // Called when send feedback button on error page is clicked. 64 // Called when send feedback button on error page is clicked.
55 virtual void OnSendFeedbackClicked() = 0; 65 virtual void OnSendFeedbackClicked() = 0;
56 }; 66 };
57 67
58 static const char kHostAppId[]; 68 static const char kHostAppId[];
59 static const char kStorageId[]; 69 static const char kStorageId[];
60 70
61 ArcSupportHost(); 71 explicit ArcSupportHost(Profile* profile);
62 ~ArcSupportHost() override; 72 ~ArcSupportHost() override;
63 73
64 // Currently only one observer can be added. 74 // Currently only one observer can be added.
65 // TODO(hidehiko): Support RemoveObserver. Support multiple observer. 75 // TODO(hidehiko): Support RemoveObserver. Support multiple observer.
66 void AddObserver(Observer* observer); 76 void AddObserver(Observer* observer);
67 77
68 // Called when the communication to arc_support Chrome App is ready. 78 // Called when the communication to arc_support Chrome App is ready.
69 void SetMessageHost(arc::ArcSupportMessageHost* message_host); 79 void SetMessageHost(arc::ArcSupportMessageHost* message_host);
70 80
71 // Called when the communication to arc_support Chrome App is closed. 81 // Called when the communication to arc_support Chrome App is closed.
72 // The argument message_host is used to check if the given |message_host| 82 // The argument message_host is used to check if the given |message_host|
73 // is what this instance uses know, to avoid racy case. 83 // is what this instance uses know, to avoid racy case.
74 // If |message_host| is different from the one this instance knows, 84 // If |message_host| is different from the one this instance knows,
75 // this is no op. 85 // this is no op.
76 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); 86 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host);
77 87
88 // Sets the ARC managed state. This must be called before ARC support app
89 // is started.
90 void SetArcManaged(bool is_arc_managed);
91
78 // Requests to close the extension window. 92 // Requests to close the extension window.
79 void Close(); 93 void Close();
80 void ShowPage(UIPage page, const base::string16& status); 94
95 // Requests to show the "Terms Of Service" page.
96 void ShowTermsOfService();
97
98 // Requests to show the LSO page.
99 void ShowLso();
100
101 // Requests to show the "ARC is loading" page.
102 void ShowArcLoading();
103
104 // Requests to show the error page
105 void ShowError(Error error, bool should_show_send_feedback);
81 106
82 void SetMetricsPreferenceCheckbox(bool is_enabled, bool is_managed); 107 void SetMetricsPreferenceCheckbox(bool is_enabled, bool is_managed);
83 void SetBackupAndRestorePreferenceCheckbox(bool is_enabled, bool is_managed); 108 void SetBackupAndRestorePreferenceCheckbox(bool is_enabled, bool is_managed);
84 void SetLocationServicesPreferenceCheckbox(bool is_enabled, bool is_managed); 109 void SetLocationServicesPreferenceCheckbox(bool is_enabled, bool is_managed);
85 110
86 // arc::ArcSupportMessageHost::Observer override: 111 // arc::ArcSupportMessageHost::Observer override:
87 void OnMessage(const base::DictionaryValue& message) override; 112 void OnMessage(const base::DictionaryValue& message) override;
88 113
89 // display::DisplayObserver: 114 // display::DisplayObserver:
90 void OnDisplayAdded(const display::Display& new_display) override; 115 void OnDisplayAdded(const display::Display& new_display) override;
91 void OnDisplayRemoved(const display::Display& old_display) override; 116 void OnDisplayRemoved(const display::Display& old_display) override;
92 void OnDisplayMetricsChanged(const display::Display& display, 117 void OnDisplayMetricsChanged(const display::Display& display,
93 uint32_t changed_metrics) override; 118 uint32_t changed_metrics) override;
94 119
120 // Returns current page that has to be shown in OptIn UI.
121 // Note that this can be inconsistent from the actually shown page.
122 // TODO(hidehiko): Remove this exposure.
123 UIPage ui_page() const { return ui_page_; }
124
95 private: 125 private:
96 struct PreferenceCheckboxData { 126 struct PreferenceCheckboxData {
97 PreferenceCheckboxData() : PreferenceCheckboxData(false, false) {} 127 PreferenceCheckboxData() : PreferenceCheckboxData(false, false) {}
98 PreferenceCheckboxData(bool is_enabled, bool is_managed) 128 PreferenceCheckboxData(bool is_enabled, bool is_managed)
99 : is_enabled(is_enabled), is_managed(is_managed) {} 129 : is_enabled(is_enabled), is_managed(is_managed) {}
100 130
101 bool is_enabled; 131 bool is_enabled;
102 bool is_managed; 132 bool is_managed;
103 }; 133 };
104 134
135 // Requests to start the ARC support Chrome app.
136 void RequestAppStart();
137
105 bool Initialize(); 138 bool Initialize();
106 139
140 // Requests to ARC support Chrome app to show the specified page.
141 void ShowPage(UIPage ui_page);
142
107 // Sends a preference update to the extension. 143 // Sends a preference update to the extension.
108 // The message will be 144 // The message will be
109 // { 145 // {
110 // 'action': action_name, 146 // 'action': action_name,
111 // 'enabled': is_enabled, 147 // 'enabled': is_enabled,
112 // 'managed': is_managed 148 // 'managed': is_managed
113 // } 149 // }
114 void SendPreferenceCheckboxUpdate(const std::string& action_name, 150 void SendPreferenceCheckboxUpdate(const std::string& action_name,
115 const PreferenceCheckboxData& data); 151 const PreferenceCheckboxData& data);
116 152
117 void DisconnectMessageHost(); 153 void DisconnectMessageHost();
118 154
155 Profile* const profile_;
156
119 // Currently Observer is only ArcAuthService, so it is unique. 157 // Currently Observer is only ArcAuthService, so it is unique.
120 // Use ObserverList when more classes start to observe it. 158 // Use ObserverList when more classes start to observe it.
121 Observer* observer_ = nullptr; 159 Observer* observer_ = nullptr;
122 160
161 // True, if ARC support app is requested to start, but the connection is not
162 // yet established. Reset to false, when the app is started and the
163 // connection to the app is established.
164 bool app_start_pending_ = false;
165
166 // The instance is created and managed by Chrome.
167 arc::ArcSupportMessageHost* message_host_ = nullptr;
168
169 // The lifetime of the message_host_ is out of control from ARC.
170 // Fields below are UI parameter cache in case the value is set before
171 // connection to the ARC support Chrome app is established.
172 UIPage ui_page_ = UIPage::NO_PAGE;
173
174 // These have valid values iff ui_page_ == ERROR.
175 Error error_;
176 bool should_show_send_feedback_;
177
178 bool is_arc_managed_ = false;
179
123 PreferenceCheckboxData metrics_checkbox_; 180 PreferenceCheckboxData metrics_checkbox_;
124 PreferenceCheckboxData backup_and_restore_checkbox_; 181 PreferenceCheckboxData backup_and_restore_checkbox_;
125 PreferenceCheckboxData location_services_checkbox_; 182 PreferenceCheckboxData location_services_checkbox_;
126 183
127 // The instance is created and managed by Chrome.
128 arc::ArcSupportMessageHost* message_host_ = nullptr;
129
130 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 184 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
131 }; 185 };
132 186
133 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 187 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/arc/arc_support_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698