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

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

Issue 2844383006: Turn ArcSupportHost from Observer model to Delegate (Closed)
Patch Set: git cl try Created 3 years, 6 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.
48 class Observer { 48 class AuthDelegate {
49 public: 49 public:
50 virtual ~Observer() = default; 50 virtual ~AuthDelegate() = default;
Luis Héctor Chávez 2017/05/30 16:06:27 nit: make the dtors protected (per the ARC chromiu
victorhsieh0 2017/05/30 19:52:42 Done.
51 51
52 // Called when the ARC support window is closed. 52 // Called when LSO auth token fetch is successfully completed.
53 virtual void OnWindowClosed() {} 53 virtual void OnAuthSucceeded(const std::string& auth_code) = 0;
54 54
55 // Called when the user press AGREE button on ToS page. 55 // Called when LSO auth token fetch has failed.
56 virtual void OnAuthFailed() = 0;
57
58 // Called when "RETRY" button on the error page is clicked during
59 // authentication.
60 virtual void OnAuthRetryClicked() = 0;
61 };
62
63 // Delegate to handle manual authentication related events.
64 class TermsOfServiceDelegate {
65 public:
66 virtual ~TermsOfServiceDelegate() = default;
67
68 // Called when the user press AGREE button on terms of service page.
56 virtual void OnTermsAgreed(bool is_metrics_enabled, 69 virtual void OnTermsAgreed(bool is_metrics_enabled,
57 bool is_backup_and_restore_enabled, 70 bool is_backup_and_restore_enabled,
58 bool is_location_service_enabled) {} 71 bool is_location_service_enabled) = 0;
59 72
60 // Called when LSO auth token fetch is successfully completed. 73 // Called when the user rejects the terms of service or close the page.
61 virtual void OnAuthSucceeded(const std::string& auth_code) {} 74 virtual void OnTermsRejected() = 0;
62 75
63 // Called when LSO auth token fetch has failed. 76 // Called when "RETRY" button on the error page is clicked during terms of
64 virtual void OnAuthFailed() {} 77 // service negotiation.
78 virtual void OnTermsRetryClicked() = 0;
79 };
65 80
66 // Called when "RETRY" button on the error page is clicked. 81 // Delegate to handle general error events. Note that some of the callback
67 virtual void OnRetryClicked() {} 82 // will only be called when more the specific callback in the other delegate
83 // is not appropriate.
84 class ErrorDelegate {
85 public:
86 virtual ~ErrorDelegate() = default;
87
88 // Called when the window is closed but only after terms accepted. If the
89 // terms are rejected in the first place, OnTermsRejected will be called.
90 virtual void OnWindowClosedTermsAccepted() = 0;
91
92 // Called when "RETRY" button on the error page is clicked, except when
93 // terms of service negotiation or manual authentication is onging. In those
94 // cases, the more specific retry function in the other delegates is called.
95 virtual void OnRetryClicked() = 0;
68 96
69 // Called when send feedback button on error page is clicked. 97 // Called when send feedback button on error page is clicked.
70 virtual void OnSendFeedbackClicked() {} 98 virtual void OnSendFeedbackClicked() = 0;
71 }; 99 };
72 100
73 static const char kStorageId[]; 101 static const char kStorageId[];
74 102
75 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>; 103 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>;
76 104
77 explicit ArcSupportHost(Profile* profile); 105 explicit ArcSupportHost(Profile* profile);
78 ~ArcSupportHost() override; 106 ~ArcSupportHost() override;
79 107
80 void AddObserver(Observer* observer); 108 void AddObserver(Observer* observer);
81 void RemoveObserver(Observer* observer); 109 void RemoveObserver(Observer* observer);
82 bool HasObserver(Observer* observer); 110 bool HasObserver(Observer* observer);
83 111
112 void SetAuthDelegate(AuthDelegate* delegate);
113 void SetTermsOfServiceDelegate(TermsOfServiceDelegate* delegate);
114 void SetErrorDelegate(ErrorDelegate* delegate);
115
116 bool HasAuthDelegateForTest() { return auth_delegate_ != nullptr; }
Luis Héctor Chávez 2017/05/30 16:06:27 nit: you can make this const
victorhsieh0 2017/05/30 19:52:42 Done.
117
84 // Called when the communication to arc_support Chrome App is ready. 118 // Called when the communication to arc_support Chrome App is ready.
85 void SetMessageHost(arc::ArcSupportMessageHost* message_host); 119 void SetMessageHost(arc::ArcSupportMessageHost* message_host);
86 120
87 // Called when the communication to arc_support Chrome App is closed. 121 // Called when the communication to arc_support Chrome App is closed.
88 // 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|
89 // is what this instance uses know, to avoid racy case. 123 // is what this instance uses know, to avoid racy case.
90 // If |message_host| is different from the one this instance knows, 124 // If |message_host| is different from the one this instance knows,
91 // this is no op. 125 // this is no op.
92 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); 126 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host);
93 127
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // } 192 // }
159 void SendPreferenceCheckboxUpdate(const std::string& action_name, 193 void SendPreferenceCheckboxUpdate(const std::string& action_name,
160 const PreferenceCheckboxData& data); 194 const PreferenceCheckboxData& data);
161 195
162 void DisconnectMessageHost(); 196 void DisconnectMessageHost();
163 197
164 Profile* const profile_; 198 Profile* const profile_;
165 RequestOpenAppCallback request_open_app_callback_; 199 RequestOpenAppCallback request_open_app_callback_;
166 200
167 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
168 205
169 // 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
170 // 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
171 // connection to the app is established. 208 // connection to the app is established.
172 bool app_start_pending_ = false; 209 bool app_start_pending_ = false;
173 210
174 // The instance is created and managed by Chrome. 211 // The instance is created and managed by Chrome.
175 arc::ArcSupportMessageHost* message_host_ = nullptr; 212 arc::ArcSupportMessageHost* message_host_ = nullptr;
176 213
177 // 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.
178 // 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
179 // connection to the ARC support Chrome app is established. 216 // connection to the ARC support Chrome app is established.
180 UIPage ui_page_ = UIPage::NO_PAGE; 217 UIPage ui_page_ = UIPage::NO_PAGE;
181 218
182 // These have valid values iff ui_page_ == ERROR. 219 // These have valid values iff ui_page_ == ERROR.
183 Error error_; 220 Error error_;
184 bool should_show_send_feedback_; 221 bool should_show_send_feedback_;
185 222
186 bool is_arc_managed_ = false; 223 bool is_arc_managed_ = false;
187 224
188 PreferenceCheckboxData metrics_checkbox_; 225 PreferenceCheckboxData metrics_checkbox_;
189 PreferenceCheckboxData backup_and_restore_checkbox_; 226 PreferenceCheckboxData backup_and_restore_checkbox_;
190 PreferenceCheckboxData location_services_checkbox_; 227 PreferenceCheckboxData location_services_checkbox_;
191 228
192 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 229 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
193 }; 230 };
194 231
195 #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