[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 7d54a19 | 2014-07-22 00:17:38 | [diff] [blame] | 5 | #ifndef COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_ |
| 6 | #define COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_ |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/macros.h" |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 11 | |
[email protected] | 7d54a19 | 2014-07-22 00:17:38 | [diff] [blame] | 12 | namespace pairing_chromeos { |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 13 | |
[email protected] | 7d54a19 | 2014-07-22 00:17:38 | [diff] [blame] | 14 | class HostPairingController { |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 15 | public: |
| 16 | enum Stage { |
| 17 | STAGE_NONE, |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 18 | STAGE_INITIALIZATION_ERROR, |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 19 | STAGE_WAITING_FOR_CONTROLLER, |
| 20 | STAGE_WAITING_FOR_CODE_CONFIRMATION, |
xdai | 955dbfd | 2015-12-18 04:40:44 | [diff] [blame] | 21 | STAGE_CONTROLLER_CONNECTION_ERROR, |
xdai | 1bc23b7 | 2015-12-16 20:00:49 | [diff] [blame] | 22 | STAGE_SETUP_BASIC_CONFIGURATION, |
| 23 | STAGE_SETUP_NETWORK_ERROR, |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 24 | STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE, |
| 25 | STAGE_WAITING_FOR_CREDENTIALS, |
| 26 | STAGE_ENROLLING, |
| 27 | STAGE_ENROLLMENT_ERROR, |
achuith | 76ebe81 | 2014-10-15 01:07:13 | [diff] [blame] | 28 | STAGE_ENROLLMENT_SUCCESS, |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 29 | STAGE_FINISHED |
| 30 | }; |
| 31 | |
xdai | 1bc23b7 | 2015-12-16 20:00:49 | [diff] [blame] | 32 | enum Connectivity { |
| 33 | CONNECTIVITY_UNTESTED, |
| 34 | CONNECTIVITY_NONE, |
| 35 | CONNECTIVITY_LIMITED, |
| 36 | CONNECTIVITY_CONNECTING, |
| 37 | CONNECTIVITY_CONNECTED, |
| 38 | }; |
| 39 | |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 40 | enum UpdateStatus { |
| 41 | UPDATE_STATUS_UNKNOWN, |
| 42 | UPDATE_STATUS_UPDATING, |
| 43 | UPDATE_STATUS_REBOOTING, |
| 44 | UPDATE_STATUS_UPDATED, |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 45 | }; |
| 46 | |
achuith | ebd853b3 | 2014-10-14 03:48:34 | [diff] [blame] | 47 | enum EnrollmentStatus { |
| 48 | ENROLLMENT_STATUS_UNKNOWN, |
| 49 | ENROLLMENT_STATUS_ENROLLING, |
| 50 | ENROLLMENT_STATUS_FAILURE, |
| 51 | ENROLLMENT_STATUS_SUCCESS, |
| 52 | }; |
| 53 | |
xdai | 74b40e5f | 2017-06-20 16:49:31 | [diff] [blame] | 54 | enum class ErrorCode : int { |
| 55 | ERROR_NONE = 0, |
| 56 | NETWORK_ERROR, |
| 57 | AUTH_ERROR, |
| 58 | ENROLL_ERROR, |
| 59 | OTHER_ERROR, |
| 60 | }; |
| 61 | |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 62 | class Observer { |
| 63 | public: |
| 64 | Observer(); |
| 65 | virtual ~Observer(); |
| 66 | |
| 67 | // Called when pairing has moved on from one stage to another. |
| 68 | virtual void PairingStageChanged(Stage new_stage) = 0; |
| 69 | |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 70 | // Called when the controller has sent a configuration to apply. |
zork | b7c25e1 | 2015-04-22 01:13:52 | [diff] [blame] | 71 | virtual void ConfigureHostRequested(bool accepted_eula, |
| 72 | const std::string& lang, |
| 73 | const std::string& timezone, |
| 74 | bool send_reports, |
| 75 | const std::string& keyboard_layout) {} |
| 76 | |
| 77 | // Called when the controller has sent a network to add. |
| 78 | virtual void AddNetworkRequested(const std::string& onc_spec) {} |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 79 | |
| 80 | // Called when the controller has provided an |auth_token| for enrollment. |
zork | b7c25e1 | 2015-04-22 01:13:52 | [diff] [blame] | 81 | virtual void EnrollHostRequested(const std::string& auth_token) {} |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 82 | |
minch | 617dcc2 | 2017-05-25 00:19:56 | [diff] [blame] | 83 | // Called when the controller has sent a reboot request. This will happen |
| 84 | // when the host enrollment fails. |
| 85 | virtual void RebootHostRequested() {} |
| 86 | |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 87 | private: |
| 88 | DISALLOW_COPY_AND_ASSIGN(Observer); |
| 89 | }; |
| 90 | |
| 91 | HostPairingController(); |
| 92 | virtual ~HostPairingController(); |
| 93 | |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 94 | // Returns current stage of pairing process. |
| 95 | virtual Stage GetCurrentStage() = 0; |
| 96 | |
| 97 | // Starts pairing process. Can be called only on |STAGE_NONE| stage. |
| 98 | virtual void StartPairing() = 0; |
| 99 | |
| 100 | // Returns device name. |
| 101 | virtual std::string GetDeviceName() = 0; |
| 102 | |
| 103 | // Returns 6-digit confirmation code. Can be called only on |
| 104 | // |STAGE_WAITING_FOR_CODE_CONFIRMATION| stage. |
| 105 | virtual std::string GetConfirmationCode() = 0; |
| 106 | |
[email protected] | 7730e38 | 2014-07-04 18:38:05 | [diff] [blame] | 107 | // Returns an enrollment domain name. Can be called on stage |
| 108 | // |STAGE_ENROLLMENT| and later. |
| 109 | virtual std::string GetEnrollmentDomain() = 0; |
| 110 | |
xdai | 1bc23b7 | 2015-12-16 20:00:49 | [diff] [blame] | 111 | // Notify that the network connectivity status has changed. |
| 112 | virtual void OnNetworkConnectivityChanged( |
| 113 | Connectivity connectivity_status) = 0; |
| 114 | |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 115 | // Notify that the update status has changed. |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 116 | virtual void OnUpdateStatusChanged(UpdateStatus update_status) = 0; |
| 117 | |
achuith | ebd853b3 | 2014-10-14 03:48:34 | [diff] [blame] | 118 | // Notify that enrollment status has changed. |
| 119 | // Can be called on stage |STAGE_WAITING_FOR_CREDENTIALS|. |
| 120 | virtual void OnEnrollmentStatusChanged( |
| 121 | EnrollmentStatus enrollment_status) = 0; |
zork | fd2bb5ea | 2014-09-09 06:53:49 | [diff] [blame] | 122 | |
zork | 01205e6 | 2015-05-01 03:20:13 | [diff] [blame] | 123 | // Set the permanent id assigned during enrollment. |
| 124 | virtual void SetPermanentId(const std::string& permanent_id) = 0; |
| 125 | |
xdai | 74b40e5f | 2017-06-20 16:49:31 | [diff] [blame] | 126 | virtual void SetErrorCodeAndMessage(int error_code, |
| 127 | const std::string& error_message) = 0; |
| 128 | |
xdai | 0532863a | 2016-05-10 23:15:23 | [diff] [blame] | 129 | // Reset the controller. |
| 130 | virtual void Reset() = 0; |
| 131 | |
zork | 5e61edc | 2014-08-28 03:41:14 | [diff] [blame] | 132 | virtual void AddObserver(Observer* observer) = 0; |
| 133 | virtual void RemoveObserver(Observer* observer) = 0; |
| 134 | |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 135 | private: |
| 136 | DISALLOW_COPY_AND_ASSIGN(HostPairingController); |
| 137 | }; |
| 138 | |
[email protected] | 7d54a19 | 2014-07-22 00:17:38 | [diff] [blame] | 139 | } // namespace pairing_chromeos |
[email protected] | 03c32fe1 | 2014-06-24 17:34:54 | [diff] [blame] | 140 | |
[email protected] | 7d54a19 | 2014-07-22 00:17:38 | [diff] [blame] | 141 | #endif // COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_ |