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

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

Issue 2844383006: Turn ArcSupportHost from Observer model to Delegate (Closed)
Patch Set: Turn ArcSupportHost from Observer model to Delegate Created 3 years, 7 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 #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 #include <string> 9 #include <string>
10 10
(...skipping 26 matching lines...) Expand all
37 NETWORK_UNAVAILABLE_ERROR, 37 NETWORK_UNAVAILABLE_ERROR,
38 SERVER_COMMUNICATION_ERROR, 38 SERVER_COMMUNICATION_ERROR,
39 SIGN_IN_BAD_AUTHENTICATION_ERROR, 39 SIGN_IN_BAD_AUTHENTICATION_ERROR,
40 SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR, 40 SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR,
41 SIGN_IN_GMS_NOT_AVAILABLE_ERROR, 41 SIGN_IN_GMS_NOT_AVAILABLE_ERROR,
42 SIGN_IN_NETWORK_ERROR, 42 SIGN_IN_NETWORK_ERROR,
43 SIGN_IN_SERVICE_UNAVAILABLE_ERROR, 43 SIGN_IN_SERVICE_UNAVAILABLE_ERROR,
44 SIGN_IN_UNKNOWN_ERROR, 44 SIGN_IN_UNKNOWN_ERROR,
45 }; 45 };
46 46
47 // Observer to notify UI event. 47 // Delegate to handle manual authentication related events. The life cycle of
Luis Héctor Chávez 2017/05/12 15:41:30 All the "The life cycle of the instance..." commen
victorhsieh0 2017/05/12 18:31:55 Removed, but add extra comment in the relevant cod
48 class Observer { 48 // the instance is as short as the manual authentication process.
49 class AuthDelegate {
49 public: 50 public:
50 virtual ~Observer() = default; 51 virtual ~AuthDelegate() = default;
51 52
52 // Called when the ARC support window is closed. 53 // Called when LSO auth token fetch is successfully completed.
53 virtual void OnWindowClosed() {} 54 virtual void OnAuthSucceeded(const std::string& auth_code) = 0;
54 55
55 // Called when the user press AGREE button on ToS page. 56 // Called when LSO auth token fetch has failed.
57 virtual void OnAuthFailed() = 0;
58
59 // Called when "RETRY" button on the error page is clicked during
60 // authentication.
61 virtual void OnAuthRetry() = 0;
62 };
63
64 // Delegate to handle manual authentication related events. The life cycle of
65 // the instance is as short as the terms of service negotiation.
66 class TermsOfServiceDelegate {
67 public:
68 virtual ~TermsOfServiceDelegate() = default;
69
70 // Called when the user press AGREE button on terms of service page.
56 virtual void OnTermsAgreed(bool is_metrics_enabled, 71 virtual void OnTermsAgreed(bool is_metrics_enabled,
57 bool is_backup_and_restore_enabled, 72 bool is_backup_and_restore_enabled,
58 bool is_location_service_enabled) {} 73 bool is_location_service_enabled) = 0;
59 74
60 // Called when LSO auth token fetch is successfully completed. 75 // Called when the user rejects the terms of service or close the page.
61 virtual void OnAuthSucceeded(const std::string& auth_code) {} 76 virtual void OnTermsRejected() = 0;
62 77
63 // Called when LSO auth token fetch has failed. 78 // Called when "RETRY" button on the error page is clicked during terms of
64 virtual void OnAuthFailed() {} 79 // service negotiation.
80 virtual void OnTermsRetry() = 0;
Luis Héctor Chávez 2017/05/12 15:41:31 OnTermsRetried? OnTermsRetryClicked? to be consist
victorhsieh0 2017/05/12 18:31:55 Done.
81 };
65 82
66 // Called when "RETRY" button on the error page is clicked. 83 class ErrorDelegate {
Luis Héctor Chávez 2017/05/12 15:41:31 Comment? At least mention that this is the "fallba
victorhsieh0 2017/05/12 18:31:55 Done.
84 public:
85 virtual ~ErrorDelegate() = default;
86
87 // Called when the opt-in process is aborted. This currently happens when
88 // the ARC support window is closed (except when when the terms of service
89 // negotiation is ongoing, the most specific function in
90 // TermsOfServiceDelegate is called).
91 virtual void OnOptInAborted() {}
Luis Héctor Chávez 2017/05/12 15:41:31 Any reason why this Delegate has implementations,
victorhsieh0 2017/05/12 18:31:55 Done.
92
93 // Called when "RETRY" button on the error page is clicked, except when
94 // terms of service negotiation or manual authentication is onging. In those
95 // cases, the more specific retry function in the other delegates is called.
67 virtual void OnRetryClicked() {} 96 virtual void OnRetryClicked() {}
68 97
69 // Called when send feedback button on error page is clicked. 98 // Called when send feedback button on error page is clicked.
70 virtual void OnSendFeedbackClicked() {} 99 virtual void OnSendFeedbackClicked() {}
71 }; 100 };
72 101
73 static const char kHostAppId[]; 102 static const char kHostAppId[];
74 static const char kStorageId[]; 103 static const char kStorageId[];
75 104
76 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>; 105 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>;
77 106
78 explicit ArcSupportHost(Profile* profile); 107 explicit ArcSupportHost(Profile* profile);
79 ~ArcSupportHost() override; 108 ~ArcSupportHost() override;
80 109
81 void AddObserver(Observer* observer); 110 void AddObserver(Observer* observer);
82 void RemoveObserver(Observer* observer); 111 void RemoveObserver(Observer* observer);
83 bool HasObserver(Observer* observer); 112 bool HasObserver(Observer* observer);
84 113
114 void SetAuthDelegate(AuthDelegate* delegate);
115 void SetTermsOfServiceDelegate(TermsOfServiceDelegate* delegate);
116 void SetErrorDelegate(ErrorDelegate* delegate);
117
85 // Called when the communication to arc_support Chrome App is ready. 118 // Called when the communication to arc_support Chrome App is ready.
86 void SetMessageHost(arc::ArcSupportMessageHost* message_host); 119 void SetMessageHost(arc::ArcSupportMessageHost* message_host);
87 120
88 // Called when the communication to arc_support Chrome App is closed. 121 // Called when the communication to arc_support Chrome App is closed.
89 // The argument message_host is used to check if the given |message_host| 122 // The argument message_host is used to check if the given |message_host|
90 // is what this instance uses know, to avoid racy case. 123 // is what this instance uses know, to avoid racy case.
91 // If |message_host| is different from the one this instance knows, 124 // If |message_host| is different from the one this instance knows,
92 // this is no op. 125 // this is no op.
93 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); 126 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host);
94 127
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // } 192 // }
160 void SendPreferenceCheckboxUpdate(const std::string& action_name, 193 void SendPreferenceCheckboxUpdate(const std::string& action_name,
161 const PreferenceCheckboxData& data); 194 const PreferenceCheckboxData& data);
162 195
163 void DisconnectMessageHost(); 196 void DisconnectMessageHost();
164 197
165 Profile* const profile_; 198 Profile* const profile_;
166 RequestOpenAppCallback request_open_app_callback_; 199 RequestOpenAppCallback request_open_app_callback_;
167 200
168 base::ObserverList<Observer> observer_list_; 201 base::ObserverList<Observer> observer_list_;
202 AuthDelegate* auth_delegate_ = nullptr; // not owned
203 TermsOfServiceDelegate* tos_delegate_ = nullptr; // not owned
204 ErrorDelegate* error_delegate_ = nullptr; // not owned
169 205
170 // True, if ARC support app is requested to start, but the connection is not 206 // True, if ARC support app is requested to start, but the connection is not
171 // yet established. Reset to false, when the app is started and the 207 // yet established. Reset to false, when the app is started and the
172 // connection to the app is established. 208 // connection to the app is established.
173 bool app_start_pending_ = false; 209 bool app_start_pending_ = false;
174 210
175 // The instance is created and managed by Chrome. 211 // The instance is created and managed by Chrome.
176 arc::ArcSupportMessageHost* message_host_ = nullptr; 212 arc::ArcSupportMessageHost* message_host_ = nullptr;
177 213
178 // The lifetime of the message_host_ is out of control from ARC. 214 // The lifetime of the message_host_ is out of control from ARC.
179 // Fields below are UI parameter cache in case the value is set before 215 // Fields below are UI parameter cache in case the value is set before
180 // connection to the ARC support Chrome app is established. 216 // connection to the ARC support Chrome app is established.
181 UIPage ui_page_ = UIPage::NO_PAGE; 217 UIPage ui_page_ = UIPage::NO_PAGE;
182 218
183 // These have valid values iff ui_page_ == ERROR. 219 // These have valid values iff ui_page_ == ERROR.
184 Error error_; 220 Error error_;
185 bool should_show_send_feedback_; 221 bool should_show_send_feedback_;
186 222
187 bool is_arc_managed_ = false; 223 bool is_arc_managed_ = false;
188 224
189 PreferenceCheckboxData metrics_checkbox_; 225 PreferenceCheckboxData metrics_checkbox_;
190 PreferenceCheckboxData backup_and_restore_checkbox_; 226 PreferenceCheckboxData backup_and_restore_checkbox_;
191 PreferenceCheckboxData location_services_checkbox_; 227 PreferenceCheckboxData location_services_checkbox_;
192 228
193 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 229 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
194 }; 230 };
195 231
196 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 232 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698