summaryrefslogtreecommitdiffstats
path: root/chromium/components/policy/core/common/remote_commands/test_support/echo_remote_command_job.h
blob: 2ffcab8541f12adbd3597a559769d7d64abc58d9 (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
// Copyright 2015 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_POLICY_CORE_COMMON_REMOTE_COMMANDS_TEST_SUPPORT_ECHO_REMOTE_COMMAND_JOB_H_
#define COMPONENTS_POLICY_CORE_COMMON_REMOTE_COMMANDS_TEST_SUPPORT_ECHO_REMOTE_COMMAND_JOB_H_

#include <string>

#include "base/time/time.h"
#include "components/policy/core/common/remote_commands/remote_command_job.h"
#include "components/policy/proto/device_management_backend.pb.h"

namespace policy {

// Remote Command Job that simply echos its payload.
// Used during unittest.
class EchoRemoteCommandJob : public RemoteCommandJob {
 public:
  EchoRemoteCommandJob(bool succeed, base::TimeDelta execution_duration);
  EchoRemoteCommandJob(const EchoRemoteCommandJob&) = delete;
  EchoRemoteCommandJob& operator=(const EchoRemoteCommandJob&) = delete;

  // RemoteCommandJob:
  enterprise_management::RemoteCommand_Type GetType() const override;

  static const char kMalformedCommandPayload[];

 private:
  class EchoPayload;

  // RemoteCommandJob:
  bool ParseCommandPayload(const std::string& command_payload) override;
  bool IsExpired(base::TimeTicks now) override;
  void RunImpl(CallbackWithResult succeed_callback,
               CallbackWithResult failed_callback) override;

  std::string command_payload_;

  const bool succeed_;
  const base::TimeDelta execution_duration_;
};

}  // namespace policy

#endif  // COMPONENTS_POLICY_CORE_COMMON_REMOTE_COMMANDS_TEST_SUPPORT_ECHO_REMOTE_COMMAND_JOB_H_