Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 class AuthHandler { |
| 48 class Observer { | |
| 49 public: | 48 public: |
| 50 virtual ~Observer() = default; | 49 virtual ~AuthHandler() = default; |
| 51 | 50 |
| 52 // Called when the ARC support window is closed. | 51 // Called when LSO auth token fetch is successfully completed. |
| 53 virtual void OnWindowClosed() {} | 52 virtual void OnAuthSucceeded(const std::string& auth_code) = 0; |
| 53 | |
| 54 // Called when LSO auth token fetch has failed. | |
| 55 virtual void OnAuthFailed() = 0; | |
| 56 | |
| 57 // Called when the user clicks retry. | |
| 58 virtual void OnAuthRetry() = 0; | |
| 59 }; | |
| 60 | |
| 61 class TosHandler { | |
| 62 public: | |
| 63 virtual ~TosHandler() = default; | |
| 54 | 64 |
| 55 // Called when the user press AGREE button on ToS page. | 65 // Called when the user press AGREE button on ToS page. |
| 56 virtual void OnTermsAgreed(bool is_metrics_enabled, | 66 virtual void OnTermsAgreed(bool is_metrics_enabled, |
| 57 bool is_backup_and_restore_enabled, | 67 bool is_backup_and_restore_enabled, |
| 58 bool is_location_service_enabled) {} | 68 bool is_location_service_enabled) = 0; |
| 59 | 69 |
| 60 // Called when LSO auth token fetch is successfully completed. | 70 // Called when the user rejects the ToS or close the page. |
| 61 virtual void OnAuthSucceeded(const std::string& auth_code) {} | 71 virtual void OnTermsRejected() = 0; |
| 62 | 72 |
| 63 // Called when LSO auth token fetch has failed. | 73 // Called when the user click "RETRY" button on ToS error. |
| 64 virtual void OnAuthFailed() {} | 74 virtual void OnTermsError() = 0; |
| 75 }; | |
| 65 | 76 |
| 66 // Called when "RETRY" button on the error page is clicked. | 77 class ErrorHandler { |
| 67 virtual void OnRetryClicked() {} | 78 public: |
| 79 virtual ~ErrorHandler() = default; | |
| 80 | |
| 81 // Called when the ARC support window is closed, except when ToS negotiation | |
| 82 // is ongoing, TosHandler::OnTermsRejected() will be called. | |
| 83 virtual void OnWindowClosed() {} // FIXME | |
| 84 | |
| 85 // Called when "RETRY" button on the error page is clicked, except when ToS | |
| 86 // negotiation is ongoing. In that case, TosHandler::OnTermsError() will be | |
| 87 // called. | |
| 88 virtual void OnRetryClicked() {} // TODO rename to match OnTermsError? | |
| 68 | 89 |
| 69 // Called when send feedback button on error page is clicked. | 90 // Called when send feedback button on error page is clicked. |
| 70 virtual void OnSendFeedbackClicked() {} | 91 virtual void OnSendFeedbackClicked() {} |
| 71 }; | 92 }; |
| 72 | 93 |
| 73 static const char kHostAppId[]; | 94 static const char kHostAppId[]; |
| 74 static const char kStorageId[]; | 95 static const char kStorageId[]; |
| 75 | 96 |
| 76 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>; | 97 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>; |
| 77 | 98 |
| 78 explicit ArcSupportHost(Profile* profile); | 99 explicit ArcSupportHost(Profile* profile); |
| 79 ~ArcSupportHost() override; | 100 ~ArcSupportHost() override; |
| 80 | 101 |
| 81 void AddObserver(Observer* observer); | 102 void AddObserver(Observer* observer); |
| 82 void RemoveObserver(Observer* observer); | 103 void RemoveObserver(Observer* observer); |
| 83 bool HasObserver(Observer* observer); | 104 bool HasObserver(Observer* observer); |
| 84 | 105 |
| 106 void SetAuthHandler(AuthHandler* handler); | |
|
Luis Héctor Chávez
2017/05/01 16:45:56
Probably a naming nit, but typically Handlers are
victorhsieh0
2017/05/11 23:51:36
Done.
| |
| 107 void UnsetAuthHandler(); | |
|
Luis Héctor Chávez
2017/05/01 16:45:56
Maybe remove all the Unset*() and just call SetXxx
victorhsieh0
2017/05/11 23:51:36
Done.
| |
| 108 | |
| 109 void SetTosHandler(TosHandler* handler); | |
| 110 void UnsetTosHandler(); | |
| 111 | |
| 112 void SetErrorHandler(ErrorHandler* handler); | |
| 113 void UnsetErrorHandler(); | |
| 114 | |
| 85 // Called when the communication to arc_support Chrome App is ready. | 115 // Called when the communication to arc_support Chrome App is ready. |
| 86 void SetMessageHost(arc::ArcSupportMessageHost* message_host); | 116 void SetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 87 | 117 |
| 88 // Called when the communication to arc_support Chrome App is closed. | 118 // 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| | 119 // The argument message_host is used to check if the given |message_host| |
| 90 // is what this instance uses know, to avoid racy case. | 120 // is what this instance uses know, to avoid racy case. |
| 91 // If |message_host| is different from the one this instance knows, | 121 // If |message_host| is different from the one this instance knows, |
| 92 // this is no op. | 122 // this is no op. |
| 93 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); | 123 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 94 | 124 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // } | 189 // } |
| 160 void SendPreferenceCheckboxUpdate(const std::string& action_name, | 190 void SendPreferenceCheckboxUpdate(const std::string& action_name, |
| 161 const PreferenceCheckboxData& data); | 191 const PreferenceCheckboxData& data); |
| 162 | 192 |
| 163 void DisconnectMessageHost(); | 193 void DisconnectMessageHost(); |
| 164 | 194 |
| 165 Profile* const profile_; | 195 Profile* const profile_; |
| 166 RequestOpenAppCallback request_open_app_callback_; | 196 RequestOpenAppCallback request_open_app_callback_; |
| 167 | 197 |
| 168 base::ObserverList<Observer> observer_list_; | 198 base::ObserverList<Observer> observer_list_; |
| 199 AuthHandler* auth_handler_ = nullptr; // not owned | |
| 200 TosHandler* tos_handler_ = nullptr; // not owned | |
| 201 ErrorHandler* error_handler_ = nullptr; // not owned | |
|
Luis Héctor Chávez
2017/05/01 16:45:56
Should you DCHECK if any of these are non-nullptr
victorhsieh0
2017/05/11 23:51:36
Done.
| |
| 169 | 202 |
| 170 // True, if ARC support app is requested to start, but the connection is not | 203 // 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 | 204 // yet established. Reset to false, when the app is started and the |
| 172 // connection to the app is established. | 205 // connection to the app is established. |
| 173 bool app_start_pending_ = false; | 206 bool app_start_pending_ = false; |
| 174 | 207 |
| 175 // The instance is created and managed by Chrome. | 208 // The instance is created and managed by Chrome. |
| 176 arc::ArcSupportMessageHost* message_host_ = nullptr; | 209 arc::ArcSupportMessageHost* message_host_ = nullptr; |
| 177 | 210 |
| 178 // The lifetime of the message_host_ is out of control from ARC. | 211 // 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 | 212 // Fields below are UI parameter cache in case the value is set before |
| 180 // connection to the ARC support Chrome app is established. | 213 // connection to the ARC support Chrome app is established. |
| 181 UIPage ui_page_ = UIPage::NO_PAGE; | 214 UIPage ui_page_ = UIPage::NO_PAGE; |
| 182 | 215 |
| 183 // These have valid values iff ui_page_ == ERROR. | 216 // These have valid values iff ui_page_ == ERROR. |
| 184 Error error_; | 217 Error error_; |
| 185 bool should_show_send_feedback_; | 218 bool should_show_send_feedback_; |
| 186 | 219 |
| 187 bool is_arc_managed_ = false; | 220 bool is_arc_managed_ = false; |
| 188 | 221 |
| 189 PreferenceCheckboxData metrics_checkbox_; | 222 PreferenceCheckboxData metrics_checkbox_; |
| 190 PreferenceCheckboxData backup_and_restore_checkbox_; | 223 PreferenceCheckboxData backup_and_restore_checkbox_; |
| 191 PreferenceCheckboxData location_services_checkbox_; | 224 PreferenceCheckboxData location_services_checkbox_; |
| 192 | 225 |
| 193 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); | 226 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); |
| 194 }; | 227 }; |
| 195 | 228 |
| 196 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ | 229 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ |
| OLD | NEW |