• 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_FAKE_HOST_PAIRING_CONTROLLER_H_
6 #define COMPONENTS_PAIRING_FAKE_HOST_PAIRING_CONTROLLER_H_
7 
8 #include "base/macros.h"
9 #include "base/observer_list.h"
10 #include "base/time/time.h"
11 #include "components/pairing/host_pairing_controller.h"
12 
13 namespace pairing_chromeos {
14 
15 class FakeHostPairingController
16     : public HostPairingController,
17       public HostPairingController::Observer {
18  public:
19   typedef HostPairingController::Observer Observer;
20 
21   // Config is a comma separated list of key-value pairs separated by colon.
22   // Supported options:
23   // * async_duration - integer. Default: 3000.
24   // * start_after_update - {0,1}. Default: 0.
25   // * fail_enrollment - {0,1}. Default: 0.
26   // * code - 6 digits or empty string. Default: empty string. If strings is
27   // empty, random code is generated.
28   // * device_name - string. Default: "Chromebox-01".
29   // * domain - string. Default: "example.com".
30   explicit FakeHostPairingController(const std::string& config);
31   virtual ~FakeHostPairingController();
32 
33   // Applies given |config| to flow.
34   void ApplyConfig(const std::string& config);
35 
36   // Overridden from HostPairingFlow:
37   virtual void AddObserver(Observer* observer) OVERRIDE;
38   virtual void RemoveObserver(Observer* observer) OVERRIDE;
39   virtual Stage GetCurrentStage() OVERRIDE;
40   virtual void StartPairing() OVERRIDE;
41   virtual std::string GetDeviceName() OVERRIDE;
42   virtual std::string GetConfirmationCode() OVERRIDE;
43   virtual std::string GetEnrollmentDomain() OVERRIDE;
44   virtual void OnUpdateStatusChanged(UpdateStatus update_status) OVERRIDE;
45   virtual void SetEnrollmentComplete(bool success) OVERRIDE;
46 
47  private:
48   void ChangeStage(Stage new_stage);
49   void ChangeStageLater(Stage new_stage);
50 
51   // HostPairingFlow::Observer:
52   virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
53   virtual void ConfigureHost(bool accepted_eula,
54                              const std::string& lang,
55                              const std::string& timezone,
56                              bool send_reports,
57                              const std::string& keyboard_layout) OVERRIDE;
58   virtual void EnrollHost(const std::string& auth_token) OVERRIDE;
59 
60   ObserverList<Observer> observers_;
61   Stage current_stage_;
62   std::string device_name_;
63   std::string confirmation_code_;
64   base::TimeDelta async_duration_;
65 
66   // If this flag is true error happens on |STAGE_ENROLLING| once.
67   bool enrollment_should_fail_;
68 
69   // Controller starts its work like if update and reboot already happened.
70   bool start_after_update_;
71 
72   std::string enrollment_domain_;
73 
74   DISALLOW_COPY_AND_ASSIGN(FakeHostPairingController);
75 };
76 
77 }  // namespace pairing_chromeos
78 
79 #endif  // COMPONENTS_PAIRING_FAKE_HOST_PAIRING_CONTROLLER_H_
80