Home | History | Annotate | Download | only in policy
      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_IMPL_H_
      6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_
      7 #pragma once
      8 
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "chrome/browser/policy/device_management_backend.h"
     14 
     15 namespace policy {
     16 
     17 class DeviceManagementJobBase;
     18 class DeviceManagementService;
     19 
     20 // Implements the actual backend interface. It creates device management jobs
     21 // and passes them on to the service for processing.
     22 class DeviceManagementBackendImpl : public DeviceManagementBackend {
     23  public:
     24   explicit DeviceManagementBackendImpl(DeviceManagementService* service);
     25   virtual ~DeviceManagementBackendImpl();
     26 
     27   static std::string GetAgentString();
     28   static std::string GetPlatformString();
     29 
     30   // Name constants for URL query parameters.
     31   static const char kParamRequest[];
     32   static const char kParamDeviceType[];
     33   static const char kParamAppType[];
     34   static const char kParamDeviceID[];
     35   static const char kParamAgent[];
     36   static const char kParamPlatform[];
     37 
     38   // String constants for the device and app type we report to the server.
     39   static const char kValueRequestRegister[];
     40   static const char kValueRequestUnregister[];
     41   static const char kValueRequestPolicy[];
     42   static const char kValueDeviceType[];
     43   static const char kValueAppType[];
     44 
     45  private:
     46   friend class DeviceManagementJobBase;
     47 
     48   typedef std::set<DeviceManagementJobBase*> JobSet;
     49 
     50   // Called by the DeviceManagementJobBase dtor so we can clean up.
     51   void JobDone(DeviceManagementJobBase* job);
     52 
     53   // Add a job to the pending job set and register it with the service (if
     54   // available).
     55   void AddJob(DeviceManagementJobBase* job);
     56 
     57   // DeviceManagementBackend overrides.
     58   virtual void ProcessRegisterRequest(
     59       const std::string& auth_token,
     60       const std::string& device_id,
     61       const em::DeviceRegisterRequest& request,
     62       DeviceRegisterResponseDelegate* response_delegate);
     63   virtual void ProcessUnregisterRequest(
     64       const std::string& device_management_token,
     65       const std::string& device_id,
     66       const em::DeviceUnregisterRequest& request,
     67       DeviceUnregisterResponseDelegate* response_delegate);
     68   virtual void ProcessPolicyRequest(
     69       const std::string& device_management_token,
     70       const std::string& device_id,
     71       const em::DevicePolicyRequest& request,
     72       DevicePolicyResponseDelegate* response_delegate);
     73 
     74   // Keeps track of the jobs currently in flight.
     75   JobSet pending_jobs_;
     76 
     77   DeviceManagementService* service_;
     78 
     79   DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackendImpl);
     80 };
     81 
     82 }  // namespace policy
     83 
     84 #endif  // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_
     85