summaryrefslogtreecommitdiffstats
path: root/components/pairing/host_pairing_controller.h
blob: b360d071fea3fef03e0b7ae4b48979ab3d4ba5e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_
#define COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_

#include <string>

#include "base/macros.h"

namespace pairing_chromeos {

class HostPairingController {
 public:
  enum Stage {
    STAGE_NONE,
    STAGE_INITIALIZATION_ERROR,
    STAGE_WAITING_FOR_CONTROLLER,
    STAGE_WAITING_FOR_CODE_CONFIRMATION,
    STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE,
    STAGE_WAITING_FOR_CREDENTIALS,
    STAGE_ENROLLING,
    STAGE_ENROLLMENT_ERROR,
    STAGE_ENROLLMENT_SUCCESS,
    STAGE_FINISHED
  };

  enum UpdateStatus {
    UPDATE_STATUS_UNKNOWN,
    UPDATE_STATUS_UPDATING,
    UPDATE_STATUS_REBOOTING,
    UPDATE_STATUS_UPDATED,
  };

  enum EnrollmentStatus {
    ENROLLMENT_STATUS_UNKNOWN,
    ENROLLMENT_STATUS_ENROLLING,
    ENROLLMENT_STATUS_FAILURE,
    ENROLLMENT_STATUS_SUCCESS,
  };

  class Observer {
   public:
    Observer();
    virtual ~Observer();

    // Called when pairing has moved on from one stage to another.
    virtual void PairingStageChanged(Stage new_stage) = 0;

    // Called when the controller has sent a configuration to apply.
    virtual void ConfigureHostRequested(bool accepted_eula,
                                        const std::string& lang,
                                        const std::string& timezone,
                                        bool send_reports,
                                        const std::string& keyboard_layout) {}

    // Called when the controller has sent a network to add.
    virtual void AddNetworkRequested(const std::string& onc_spec) {}

    // Called when the controller has provided an |auth_token| for enrollment.
    virtual void EnrollHostRequested(const std::string& auth_token) {}

   private:
    DISALLOW_COPY_AND_ASSIGN(Observer);
  };

  HostPairingController();
  virtual ~HostPairingController();

  // Returns current stage of pairing process.
  virtual Stage GetCurrentStage() = 0;

  // Starts pairing process. Can be called only on |STAGE_NONE| stage.
  virtual void StartPairing() = 0;

  // Returns device name.
  virtual std::string GetDeviceName() = 0;

  // Returns 6-digit confirmation code. Can be called only on
  // |STAGE_WAITING_FOR_CODE_CONFIRMATION| stage.
  virtual std::string GetConfirmationCode() = 0;

  // Returns an enrollment domain name. Can be called on stage
  // |STAGE_ENROLLMENT| and later.
  virtual std::string GetEnrollmentDomain() = 0;

  // Notify that the update status has changed.
  virtual void OnUpdateStatusChanged(UpdateStatus update_status) = 0;

  // Notify that enrollment status has changed.
  // Can be called on stage |STAGE_WAITING_FOR_CREDENTIALS|.
  virtual void OnEnrollmentStatusChanged(
      EnrollmentStatus enrollment_status) = 0;

  // Set the permanent id assigned during enrollment.
  virtual void SetPermanentId(const std::string& permanent_id) = 0;

  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;

 private:
  DISALLOW_COPY_AND_ASSIGN(HostPairingController);
};

}  // namespace pairing_chromeos

#endif  // COMPONENTS_PAIRING_HOST_PAIRING_CONTROLLER_H_