• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef COMPONENTS_PAIRING_CONTROLLER_PAIRING_CONTROLLER_H_
6 #define COMPONENTS_PAIRING_CONTROLLER_PAIRING_CONTROLLER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/macros.h"
12 
13 namespace chromeos {
14 class UserContext;
15 }
16 
17 namespace content {
18 class BrowserContext;
19 }
20 
21 namespace pairing_chromeos {
22 
23 class ControllerPairingController {
24  public:
25   enum Stage {
26     STAGE_NONE,
27     STAGE_INITIALIZATION_ERROR,
28     STAGE_DEVICES_DISCOVERY,
29     STAGE_DEVICE_NOT_FOUND,
30     STAGE_ESTABLISHING_CONNECTION,
31     STAGE_ESTABLISHING_CONNECTION_ERROR,
32     STAGE_WAITING_FOR_CODE_CONFIRMATION,
33     STAGE_HOST_UPDATE_IN_PROGRESS,
34     STAGE_HOST_CONNECTION_LOST,
35     STAGE_WAITING_FOR_CREDENTIALS,
36     STAGE_HOST_ENROLLMENT_IN_PROGRESS,
37     STAGE_HOST_ENROLLMENT_ERROR,
38     STAGE_PAIRING_DONE,
39     STAGE_FINISHED
40   };
41 
42   class Observer {
43    public:
44     Observer();
45     virtual ~Observer();
46 
47     // Called when pairing has moved on from one stage to another.
48     virtual void PairingStageChanged(Stage new_stage) = 0;
49 
50     // Called when new device was discovered or existing device was lost.
51     // This notification is made only on |STAGE_DEVICES_DISCOVERY| stage.
52     virtual void DiscoveredDevicesListChanged() = 0;
53 
54    private:
55     DISALLOW_COPY_AND_ASSIGN(Observer);
56   };
57 
58   typedef std::vector<std::string> DeviceIdList;
59 
60   ControllerPairingController();
61   virtual ~ControllerPairingController();
62 
63   // Returns current stage of pairing process.
64   virtual Stage GetCurrentStage() = 0;
65 
66   // Starts pairing process. Can be called only on |STAGE_NONE| stage.
67   virtual void StartPairing() = 0;
68 
69   // Returns list of discovered devices. Can be called only on
70   // |STAGE_DEVICES_DISCOVERY| stage.
71   virtual DeviceIdList GetDiscoveredDevices() = 0;
72 
73   // This method is called to start pairing with the device having |device_id|
74   // ID. Can be called only on |STAGE_DEVICES_DISCOVERY| stage.
75   virtual void ChooseDeviceForPairing(const std::string& device_id) = 0;
76 
77   // Rescan for devices to pair with. Can be called only on
78   // stages |STAGE_DEVICE_NOT_FOUND|, |STAGE_ESTABLISHING_CONNECTION_ERROR|,
79   // |STAGE_HOST_ENROLLMENT_ERROR|.
80   virtual void RepeatDiscovery() = 0;
81 
82   // Returns pairing confirmation code.
83   // Could be called only on |STATE_WAITING_FOR_CODE_CONFIRMATION| stage.
84   virtual std::string GetConfirmationCode() = 0;
85 
86   // Called to confirm or deny confirmation code. Can be called only on
87   // |STAGE_WAITING_FOR_CODE_CONFIRMATION| stage.
88   virtual void SetConfirmationCodeIsCorrect(bool correct) = 0;
89 
90   // Set the values that will be sent to the host if it needs to be configured.
91   virtual void SetHostConfiguration(bool accepted_eula,
92                                     const std::string& lang,
93                                     const std::string& timezone,
94                                     bool send_reports,
95                                     const std::string& keyboard_layout) = 0;
96 
97   // Called when user successfully authenticated on GAIA page. Can be called
98   // only on |STAGE_WAITING_FOR_CREDENTIALS| stage.
99   // |auth_token| will be sent to the host to be used for enrollment.
100   virtual void OnAuthenticationDone(const std::string& domain,
101                                     const std::string& auth_token) = 0;
102 
103   // Installs app and starts session.
104   // Can be called only on |STAGE_PAIRING_DONE| stage.
105   virtual void StartSession() = 0;
106 
107   virtual void AddObserver(Observer* observer) = 0;
108   virtual void RemoveObserver(Observer* observer) = 0;
109 
110  private:
111   DISALLOW_COPY_AND_ASSIGN(ControllerPairingController);
112 };
113 
114 }  // namespace pairing_chromeos
115 
116 #endif  // COMPONENTS_PAIRING_CONTROLLER_PAIRING_CONTROLLER_H_
117