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 15 namespace policy { 16 17 namespace 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. 23 class DeviceManagementBackend : base::NonThreadSafe { 24 public: 25 enum ErrorCode { 26 // Request payload invalid. 27 kErrorRequestInvalid, 28 // The HTTP request failed. 29 kErrorRequestFailed, 30 // The server returned an error code that points to a temporary problem. 31 kErrorTemporaryUnavailable, 32 // The HTTP request returned a non-success code. 33 kErrorHttpStatus, 34 // Response could not be decoded. 35 kErrorResponseDecoding, 36 // Service error: Management not supported. 37 kErrorServiceManagementNotSupported, 38 // Service error: Device not found. 39 kErrorServiceDeviceNotFound, 40 // Service error: Device token invalid. 41 kErrorServiceManagementTokenInvalid, 42 // Service error: Activation pending. 43 kErrorServiceActivationPending, 44 // Service error: Policy not found. Error code defined by the DM folks. 45 kErrorServicePolicyNotFound = 902, 46 }; 47 48 class DeviceRegisterResponseDelegate { 49 public: 50 virtual ~DeviceRegisterResponseDelegate() {} 51 virtual void HandleRegisterResponse( 52 const em::DeviceRegisterResponse& response) = 0; 53 virtual void OnError(ErrorCode code) = 0; 54 55 protected: 56 DeviceRegisterResponseDelegate() {} 57 58 private: 59 DISALLOW_COPY_AND_ASSIGN(DeviceRegisterResponseDelegate); 60 }; 61 62 class DeviceUnregisterResponseDelegate { 63 public: 64 virtual ~DeviceUnregisterResponseDelegate() {} 65 virtual void HandleUnregisterResponse( 66 const em::DeviceUnregisterResponse& response) = 0; 67 virtual void OnError(ErrorCode code) = 0; 68 69 protected: 70 DeviceUnregisterResponseDelegate() {} 71 72 private: 73 DISALLOW_COPY_AND_ASSIGN(DeviceUnregisterResponseDelegate); 74 }; 75 76 class DevicePolicyResponseDelegate { 77 public: 78 virtual ~DevicePolicyResponseDelegate() {} 79 80 virtual void HandlePolicyResponse( 81 const em::DevicePolicyResponse& response) = 0; 82 virtual void OnError(ErrorCode code) = 0; 83 84 protected: 85 DevicePolicyResponseDelegate() {} 86 87 private: 88 DISALLOW_COPY_AND_ASSIGN(DevicePolicyResponseDelegate); 89 }; 90 91 virtual ~DeviceManagementBackend() {} 92 93 virtual void ProcessRegisterRequest( 94 const std::string& auth_token, 95 const std::string& device_id, 96 const em::DeviceRegisterRequest& request, 97 DeviceRegisterResponseDelegate* delegate) = 0; 98 99 virtual void ProcessUnregisterRequest( 100 const std::string& device_management_token, 101 const std::string& device_id, 102 const em::DeviceUnregisterRequest& request, 103 DeviceUnregisterResponseDelegate* delegate) = 0; 104 105 virtual void ProcessPolicyRequest( 106 const std::string& device_management_token, 107 const std::string& device_id, 108 const em::DevicePolicyRequest& request, 109 DevicePolicyResponseDelegate* delegate) = 0; 110 111 protected: 112 DeviceManagementBackend() {} 113 114 private: 115 DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackend); 116 }; 117 118 } // namespace policy 119 120 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_H_ 121