device_management_backend.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 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 CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_H_
6#define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_H_
7#pragma once
8
9#include <string>
10
11#include "base/basictypes.h"
12#include "base/threading/non_thread_safe.h"
13#include "chrome/browser/policy/proto/device_management_backend.pb.h"
14
15namespace policy {
16
17namespace em = enterprise_management;
18
19// Interface for clients that need to converse with the device management
20// server, which provides services to register Chrome installations and CrOS
21// devices for the purpose of fetching centrally-administered policy from the
22// cloud.
23class DeviceManagementBackend : base::NonThreadSafe {
24 public:
25  enum ErrorCode {
26    // Request payload invalid.
27    kErrorRequestInvalid,
28    // The HTTP request failed.
29    kErrorRequestFailed,
30    // The HTTP request returned a non-success code.
31    kErrorHttpStatus,
32    // Response could not be decoded.
33    kErrorResponseDecoding,
34    // Service error: Management not supported.
35    kErrorServiceManagementNotSupported,
36    // Service error: Device not found.
37    kErrorServiceDeviceNotFound,
38    // Service error: Device token invalid.
39    kErrorServiceManagementTokenInvalid,
40    // Service error: Activation pending.
41    kErrorServiceActivationPending,
42    // Service error: Policy not found.
43    kErrorServicePolicyNotFound,
44  };
45
46  class DeviceRegisterResponseDelegate {
47   public:
48    virtual ~DeviceRegisterResponseDelegate() {}
49    virtual void HandleRegisterResponse(
50        const em::DeviceRegisterResponse& response) = 0;
51    virtual void OnError(ErrorCode code) = 0;
52
53   protected:
54    DeviceRegisterResponseDelegate() {}
55
56   private:
57    DISALLOW_COPY_AND_ASSIGN(DeviceRegisterResponseDelegate);
58  };
59
60  class DeviceUnregisterResponseDelegate {
61   public:
62    virtual ~DeviceUnregisterResponseDelegate() {}
63    virtual void HandleUnregisterResponse(
64        const em::DeviceUnregisterResponse& response) = 0;
65    virtual void OnError(ErrorCode code) = 0;
66
67   protected:
68    DeviceUnregisterResponseDelegate() {}
69
70   private:
71    DISALLOW_COPY_AND_ASSIGN(DeviceUnregisterResponseDelegate);
72  };
73
74  class DevicePolicyResponseDelegate {
75   public:
76    virtual ~DevicePolicyResponseDelegate() {}
77
78    virtual void HandlePolicyResponse(
79        const em::DevicePolicyResponse& response) = 0;
80    virtual void OnError(ErrorCode code) = 0;
81
82   protected:
83    DevicePolicyResponseDelegate() {}
84
85   private:
86    DISALLOW_COPY_AND_ASSIGN(DevicePolicyResponseDelegate);
87  };
88
89  virtual ~DeviceManagementBackend() {}
90
91  virtual void ProcessRegisterRequest(
92      const std::string& auth_token,
93      const std::string& device_id,
94      const em::DeviceRegisterRequest& request,
95      DeviceRegisterResponseDelegate* delegate) = 0;
96
97  virtual void ProcessUnregisterRequest(
98      const std::string& device_management_token,
99      const std::string& device_id,
100      const em::DeviceUnregisterRequest& request,
101      DeviceUnregisterResponseDelegate* delegate) = 0;
102
103  virtual void ProcessPolicyRequest(
104      const std::string& device_management_token,
105      const std::string& device_id,
106      const em::DevicePolicyRequest& request,
107      DevicePolicyResponseDelegate* delegate) = 0;
108
109 protected:
110  DeviceManagementBackend() {}
111
112 private:
113  DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackend);
114};
115
116}  // namespace policy
117
118#endif  // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_H_
119