| 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 // 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; |
| 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 opt-in process is aborted. This currently happens when |
| 89 // the ARC support window is closed (except when the terms of service |
| 90 // negotiation is ongoing, the most specific function in |
| 91 // TermsOfServiceDelegate is called). |
| 92 virtual void OnOptInAborted() = 0; |
| 93 |
| 94 // Called when "RETRY" button on the error page is clicked, except when |
| 95 // terms of service negotiation or manual authentication is onging. In those |
| 96 // cases, the more specific retry function in the other delegates is called. |
| 97 virtual void OnRetryClicked() = 0; |
| 68 | 98 |
| 69 // Called when send feedback button on error page is clicked. | 99 // Called when send feedback button on error page is clicked. |
| 70 virtual void OnSendFeedbackClicked() {} | 100 virtual void OnSendFeedbackClicked() = 0; |
| 71 }; | 101 }; |
| 72 | 102 |
| 73 static const char kStorageId[]; | 103 static const char kStorageId[]; |
| 74 | 104 |
| 75 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>; | 105 using RequestOpenAppCallback = base::Callback<void(Profile* profile)>; |
| 76 | 106 |
| 77 explicit ArcSupportHost(Profile* profile); | 107 explicit ArcSupportHost(Profile* profile); |
| 78 ~ArcSupportHost() override; | 108 ~ArcSupportHost() override; |
| 79 | 109 |
| 80 void AddObserver(Observer* observer); | 110 void AddObserver(Observer* observer); |
| 81 void RemoveObserver(Observer* observer); | 111 void RemoveObserver(Observer* observer); |
| 82 bool HasObserver(Observer* observer); | 112 bool HasObserver(Observer* observer); |
| 83 | 113 |
| 114 void SetAuthDelegate(AuthDelegate* delegate); |
| 115 void SetTermsOfServiceDelegate(TermsOfServiceDelegate* delegate); |
| 116 void SetErrorDelegate(ErrorDelegate* delegate); |
| 117 |
| 118 bool HasAuthDelegateForTest() { return auth_delegate_ != nullptr; } |
| 119 |
| 84 // Called when the communication to arc_support Chrome App is ready. | 120 // Called when the communication to arc_support Chrome App is ready. |
| 85 void SetMessageHost(arc::ArcSupportMessageHost* message_host); | 121 void SetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 86 | 122 |
| 87 // Called when the communication to arc_support Chrome App is closed. | 123 // 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| | 124 // The argument message_host is used to check if the given |message_host| |
| 89 // is what this instance uses know, to avoid racy case. | 125 // is what this instance uses know, to avoid racy case. |
| 90 // If |message_host| is different from the one this instance knows, | 126 // If |message_host| is different from the one this instance knows, |
| 91 // this is no op. | 127 // this is no op. |
| 92 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); | 128 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 93 | 129 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // } | 194 // } |
| 159 void SendPreferenceCheckboxUpdate(const std::string& action_name, | 195 void SendPreferenceCheckboxUpdate(const std::string& action_name, |
| 160 const PreferenceCheckboxData& data); | 196 const PreferenceCheckboxData& data); |
| 161 | 197 |
| 162 void DisconnectMessageHost(); | 198 void DisconnectMessageHost(); |
| 163 | 199 |
| 164 Profile* const profile_; | 200 Profile* const profile_; |
| 165 RequestOpenAppCallback request_open_app_callback_; | 201 RequestOpenAppCallback request_open_app_callback_; |
| 166 | 202 |
| 167 base::ObserverList<Observer> observer_list_; | 203 base::ObserverList<Observer> observer_list_; |
| 204 AuthDelegate* auth_delegate_ = nullptr; // not owned |
| 205 TermsOfServiceDelegate* tos_delegate_ = nullptr; // not owned |
| 206 ErrorDelegate* error_delegate_ = nullptr; // not owned |
| 168 | 207 |
| 169 // True, if ARC support app is requested to start, but the connection is not | 208 // 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 | 209 // yet established. Reset to false, when the app is started and the |
| 171 // connection to the app is established. | 210 // connection to the app is established. |
| 172 bool app_start_pending_ = false; | 211 bool app_start_pending_ = false; |
| 173 | 212 |
| 174 // The instance is created and managed by Chrome. | 213 // The instance is created and managed by Chrome. |
| 175 arc::ArcSupportMessageHost* message_host_ = nullptr; | 214 arc::ArcSupportMessageHost* message_host_ = nullptr; |
| 176 | 215 |
| 177 // The lifetime of the message_host_ is out of control from ARC. | 216 // 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 | 217 // Fields below are UI parameter cache in case the value is set before |
| 179 // connection to the ARC support Chrome app is established. | 218 // connection to the ARC support Chrome app is established. |
| 180 UIPage ui_page_ = UIPage::NO_PAGE; | 219 UIPage ui_page_ = UIPage::NO_PAGE; |
| 181 | 220 |
| 182 // These have valid values iff ui_page_ == ERROR. | 221 // These have valid values iff ui_page_ == ERROR. |
| 183 Error error_; | 222 Error error_; |
| 184 bool should_show_send_feedback_; | 223 bool should_show_send_feedback_; |
| 185 | 224 |
| 186 bool is_arc_managed_ = false; | 225 bool is_arc_managed_ = false; |
| 187 | 226 |
| 188 PreferenceCheckboxData metrics_checkbox_; | 227 PreferenceCheckboxData metrics_checkbox_; |
| 189 PreferenceCheckboxData backup_and_restore_checkbox_; | 228 PreferenceCheckboxData backup_and_restore_checkbox_; |
| 190 PreferenceCheckboxData location_services_checkbox_; | 229 PreferenceCheckboxData location_services_checkbox_; |
| 191 | 230 |
| 192 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); | 231 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); |
| 193 }; | 232 }; |
| 194 | 233 |
| 195 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ | 234 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ |
| OLD | NEW |