blob: 4e6b6122c4ccba17c239da11ce5c816ae5abb8ae [file] [log] [blame]
[email protected]03c32fe12014-06-24 17:34:541// 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]7d54a192014-07-22 00:17:385#ifndef COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_
6#define COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_
[email protected]03c32fe12014-06-24 17:34:547
8#include <string>
9
10#include "base/macros.h"
[email protected]03c32fe12014-06-24 17:34:5411
[email protected]7d54a192014-07-22 00:17:3812namespace pairing_chromeos {
[email protected]03c32fe12014-06-24 17:34:5413
[email protected]7d54a192014-07-22 00:17:3814class HostPairingController {
[email protected]03c32fe12014-06-24 17:34:5415 public:
16 enum Stage {
17 STAGE_NONE,
zork5e61edc2014-08-28 03:41:1418 STAGE_INITIALIZATION_ERROR,
[email protected]03c32fe12014-06-24 17:34:5419 STAGE_WAITING_FOR_CONTROLLER,
20 STAGE_WAITING_FOR_CODE_CONFIRMATION,
xdai955dbfd2015-12-18 04:40:4421 STAGE_CONTROLLER_CONNECTION_ERROR,
xdai1bc23b72015-12-16 20:00:4922 STAGE_SETUP_BASIC_CONFIGURATION,
23 STAGE_SETUP_NETWORK_ERROR,
[email protected]03c32fe12014-06-24 17:34:5424 STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE,
25 STAGE_WAITING_FOR_CREDENTIALS,
26 STAGE_ENROLLING,
27 STAGE_ENROLLMENT_ERROR,
achuith76ebe812014-10-15 01:07:1328 STAGE_ENROLLMENT_SUCCESS,
[email protected]03c32fe12014-06-24 17:34:5429 STAGE_FINISHED
30 };
31
xdai1bc23b72015-12-16 20:00:4932 enum Connectivity {
33 CONNECTIVITY_UNTESTED,
34 CONNECTIVITY_NONE,
35 CONNECTIVITY_LIMITED,
36 CONNECTIVITY_CONNECTING,
37 CONNECTIVITY_CONNECTED,
38 };
39
zork5e61edc2014-08-28 03:41:1440 enum UpdateStatus {
41 UPDATE_STATUS_UNKNOWN,
42 UPDATE_STATUS_UPDATING,
43 UPDATE_STATUS_REBOOTING,
44 UPDATE_STATUS_UPDATED,
[email protected]03c32fe12014-06-24 17:34:5445 };
46
achuithebd853b32014-10-14 03:48:3447 enum EnrollmentStatus {
48 ENROLLMENT_STATUS_UNKNOWN,
49 ENROLLMENT_STATUS_ENROLLING,
50 ENROLLMENT_STATUS_FAILURE,
51 ENROLLMENT_STATUS_SUCCESS,
52 };
53
xdai74b40e5f2017-06-20 16:49:3154 enum class ErrorCode : int {
55 ERROR_NONE = 0,
56 NETWORK_ERROR,
57 AUTH_ERROR,
58 ENROLL_ERROR,
59 OTHER_ERROR,
60 };
61
[email protected]03c32fe12014-06-24 17:34:5462 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
zork5e61edc2014-08-28 03:41:1470 // Called when the controller has sent a configuration to apply.
zorkb7c25e12015-04-22 01:13:5271 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) {}
zork5e61edc2014-08-28 03:41:1479
80 // Called when the controller has provided an |auth_token| for enrollment.
zorkb7c25e12015-04-22 01:13:5281 virtual void EnrollHostRequested(const std::string& auth_token) {}
[email protected]03c32fe12014-06-24 17:34:5482
minch617dcc22017-05-25 00:19:5683 // 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]03c32fe12014-06-24 17:34:5487 private:
88 DISALLOW_COPY_AND_ASSIGN(Observer);
89 };
90
91 HostPairingController();
92 virtual ~HostPairingController();
93
[email protected]03c32fe12014-06-24 17:34:5494 // 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]7730e382014-07-04 18:38:05107 // Returns an enrollment domain name. Can be called on stage
108 // |STAGE_ENROLLMENT| and later.
109 virtual std::string GetEnrollmentDomain() = 0;
110
xdai1bc23b72015-12-16 20:00:49111 // Notify that the network connectivity status has changed.
112 virtual void OnNetworkConnectivityChanged(
113 Connectivity connectivity_status) = 0;
114
zork5e61edc2014-08-28 03:41:14115 // Notify that the update status has changed.
zork5e61edc2014-08-28 03:41:14116 virtual void OnUpdateStatusChanged(UpdateStatus update_status) = 0;
117
achuithebd853b32014-10-14 03:48:34118 // 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;
zorkfd2bb5ea2014-09-09 06:53:49122
zork01205e62015-05-01 03:20:13123 // Set the permanent id assigned during enrollment.
124 virtual void SetPermanentId(const std::string& permanent_id) = 0;
125
xdai74b40e5f2017-06-20 16:49:31126 virtual void SetErrorCodeAndMessage(int error_code,
127 const std::string& error_message) = 0;
128
xdai0532863a2016-05-10 23:15:23129 // Reset the controller.
130 virtual void Reset() = 0;
131
zork5e61edc2014-08-28 03:41:14132 virtual void AddObserver(Observer* observer) = 0;
133 virtual void RemoveObserver(Observer* observer) = 0;
134
[email protected]03c32fe12014-06-24 17:34:54135 private:
136 DISALLOW_COPY_AND_ASSIGN(HostPairingController);
137};
138
[email protected]7d54a192014-07-22 00:17:38139} // namespace pairing_chromeos
[email protected]03c32fe12014-06-24 17:34:54140
[email protected]7d54a192014-07-22 00:17:38141#endif // COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_