summaryrefslogtreecommitdiffstats
path: root/components/pairing/fake_host_pairing_controller.h
blob: 862e3d5f7b3cd7fa7e5bf661e59da8eeda75d117 (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
// 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_FAKE_HOST_PAIRING_CONTROLLER_H_
#define COMPONENTS_PAIRING_FAKE_HOST_PAIRING_CONTROLLER_H_

#include "base/macros.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "components/pairing/host_pairing_controller.h"

namespace pairing_chromeos {

class FakeHostPairingController
    : public HostPairingController,
      public HostPairingController::Observer {
 public:
  typedef HostPairingController::Observer Observer;

  // Config is a comma separated list of key-value pairs separated by colon.
  // Supported options:
  // * async_duration - integer. Default: 3000.
  // * start_after_update - {0,1}. Default: 0.
  // * fail_enrollment - {0,1}. Default: 0.
  // * code - 6 digits or empty string. Default: empty string. If strings is
  // empty, random code is generated.
  // * device_name - string. Default: "Chromebox-01".
  // * domain - string. Default: "example.com".
  explicit FakeHostPairingController(const std::string& config);
  ~FakeHostPairingController() override;

  // Applies given |config| to flow.
  void ApplyConfig(const std::string& config);

 private:
  void ChangeStage(Stage new_stage);
  void ChangeStageLater(Stage new_stage);

  // HostPairingController:
  void AddObserver(Observer* observer) override;
  void RemoveObserver(Observer* observer) override;
  Stage GetCurrentStage() override;
  void StartPairing() override;
  std::string GetDeviceName() override;
  std::string GetConfirmationCode() override;
  std::string GetEnrollmentDomain() override;
  void OnUpdateStatusChanged(UpdateStatus update_status) override;
  void OnEnrollmentStatusChanged(EnrollmentStatus enrollment_status) override;
  void SetPermanentId(const std::string& permanent_id) override;

  // HostPairingController::Observer:
  void PairingStageChanged(Stage new_stage) override;

  base::ObserverList<Observer> observers_;
  Stage current_stage_;
  std::string device_name_;
  std::string confirmation_code_;
  base::TimeDelta async_duration_;

  // If this flag is true error happens on |STAGE_ENROLLING| once.
  bool enrollment_should_fail_;

  // Controller starts its work like if update and reboot already happened.
  bool start_after_update_;

  std::string enrollment_domain_;

  DISALLOW_COPY_AND_ASSIGN(FakeHostPairingController);
};

}  // namespace pairing_chromeos

#endif  // COMPONENTS_PAIRING_FAKE_HOST_PAIRING_CONTROLLER_H_