Home | History | Annotate | Download | only in pairing
      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 CHROMEOS_PAIRING_CONTROLLER_PAIRING_FLOW_H_
      6 #define CHROMEOS_PAIRING_CONTROLLER_PAIRING_FLOW_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/macros.h"
     12 #include "chromeos/chromeos_export.h"
     13 
     14 namespace chromeos {
     15 class UserContext;
     16 }
     17 
     18 namespace content {
     19 class BrowserContext;
     20 }
     21 
     22 namespace chromeos {
     23 
     24 class CHROMEOS_EXPORT ControllerPairingFlow {
     25  public:
     26   enum Stage {
     27     STAGE_NONE,
     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 flow 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_SCANNING_FOR_DEVICES| 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   ControllerPairingFlow();
     61   virtual ~ControllerPairingFlow();
     62 
     63   virtual void AddObserver(Observer* observer) = 0;
     64   virtual void RemoveObserver(Observer* observer) = 0;
     65 
     66   // Returns current stage of flow.
     67   virtual Stage GetCurrentStage() = 0;
     68 
     69   // Starts pairing flow. Can be called only on |STAGE_NONE| stage.
     70   virtual void StartFlow() = 0;
     71 
     72   // Returns list of discovered devices. Can be called only on
     73   // |STAGE_DEVICES_DISCOVERY| stage.
     74   virtual DeviceIdList GetDiscoveredDevices() = 0;
     75 
     76   // This method is called to start pairing with the device having |device_id|
     77   // ID. Can be called only on |STAGE_DEVICES_DISCOVERY| stage.
     78   virtual void ChooseDeviceForPairing(const std::string& device_id) = 0;
     79 
     80   // Rescan for devices to pair with. Can be called only on
     81   // |STAGE_DEVICE_NOT_FOUND| stage.
     82   virtual void RepeatDiscovery() = 0;
     83 
     84   // Returns pairing confirmation code.
     85   // Could be called only on |STATE_WAITING_FOR_CODE_CONFIRMATION| stage.
     86   virtual std::string GetConfirmationCode() = 0;
     87 
     88   // Called to confirm or deny confirmation code. Can be called only on
     89   // |STAGE_WAITING_FOR_CODE_CONFIRMATION| stage.
     90   virtual void SetConfirmationCodeIsCorrect(bool correct) = 0;
     91 
     92   // Called when user successfully authenticated on GAIA page. Can be called
     93   // only on |STAGE_WAITING_FOR_CREDENTIALS| stage.
     94   virtual void OnAuthenticationDone(
     95       const chromeos::UserContext& user_context,
     96       content::BrowserContext* browser_context) = 0;
     97 
     98   // Installs app and starts session.
     99   // Can be called only on |STAGE_PAIRING_DONE| stage.
    100   virtual void StartSession() = 0;
    101 
    102  private:
    103   DISALLOW_COPY_AND_ASSIGN(ControllerPairingFlow);
    104 };
    105 
    106 }  // namespace chromeos
    107 
    108 #endif  // CHROMEOS_PAIRING_CONTROLLER_PAIRING_FLOW_H_
    109