OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ |
6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
| 12 #include "base/basictypes.h" |
12 #include "chrome/browser/policy/device_management_backend.h" | 13 #include "chrome/browser/policy/device_management_backend.h" |
13 #include "chrome/common/net/url_fetcher.h" | |
14 #include "googleurl/src/gurl.h" | |
15 | |
16 class URLRequestContextGetter; | |
17 | 14 |
18 namespace policy { | 15 namespace policy { |
19 | 16 |
20 class ResponseHandler; | 17 class DeviceManagementService; |
21 class URLQueryParameters; | 18 class DeviceManagementJobBase; |
22 | 19 |
23 // Device management backend implementation. This implementation makes HTTP | 20 // Implements the actual backend interface. It creates device management jobs |
24 // requests to the policy server through the net layer. | 21 // and passes them on to the service for processing. |
25 class DeviceManagementBackendImpl : public DeviceManagementBackend, | 22 class DeviceManagementBackendImpl : public DeviceManagementBackend { |
26 public URLFetcher::Delegate { | |
27 public: | 23 public: |
28 explicit DeviceManagementBackendImpl(const std::string& server_url); | 24 explicit DeviceManagementBackendImpl(DeviceManagementService* service); |
29 virtual ~DeviceManagementBackendImpl(); | 25 virtual ~DeviceManagementBackendImpl(); |
30 | 26 |
31 // GoogleAppsPolicyService overrides: | 27 private: |
| 28 friend class DeviceManagementJobBase; |
| 29 |
| 30 typedef std::set<DeviceManagementJobBase*> JobSet; |
| 31 |
| 32 // Called by the DeviceManagementJobBase dtor so we can clean up. |
| 33 void JobDone(DeviceManagementJobBase* job); |
| 34 |
| 35 // Add a job to the pending job set and register it with the service (if |
| 36 // available). |
| 37 void AddJob(DeviceManagementJobBase* job); |
| 38 |
| 39 // DeviceManagementBackend overrides. |
32 virtual void ProcessRegisterRequest( | 40 virtual void ProcessRegisterRequest( |
33 const std::string& auth_token, | 41 const std::string& auth_token, |
34 const std::string& device_id, | 42 const std::string& device_id, |
35 const em::DeviceRegisterRequest& request, | 43 const em::DeviceRegisterRequest& request, |
36 DeviceRegisterResponseDelegate* response_delegate); | 44 DeviceRegisterResponseDelegate* response_delegate); |
37 virtual void ProcessUnregisterRequest( | 45 virtual void ProcessUnregisterRequest( |
38 const std::string& device_management_token, | 46 const std::string& device_management_token, |
39 const em::DeviceUnregisterRequest& request, | 47 const em::DeviceUnregisterRequest& request, |
40 DeviceUnregisterResponseDelegate* response_delegate); | 48 DeviceUnregisterResponseDelegate* response_delegate); |
41 virtual void ProcessPolicyRequest( | 49 virtual void ProcessPolicyRequest( |
42 const std::string& device_management_token, | 50 const std::string& device_management_token, |
43 const em::DevicePolicyRequest& request, | 51 const em::DevicePolicyRequest& request, |
44 DevicePolicyResponseDelegate* response_delegate); | 52 DevicePolicyResponseDelegate* response_delegate); |
45 | 53 |
46 // Get the agent string (used for HTTP user agent and as agent passed to the | 54 // Keeps track of the jobs currently in flight. |
47 // server). | 55 JobSet pending_jobs_; |
48 static std::string GetAgentString(); | |
49 | 56 |
50 private: | 57 DeviceManagementService* service_; |
51 typedef std::map<const URLFetcher*, ResponseHandler*> ResponseHandlerMap; | |
52 | |
53 // URLFetcher::Delegate override. | |
54 virtual void OnURLFetchComplete(const URLFetcher* source, | |
55 const GURL& url, | |
56 const URLRequestStatus& status, | |
57 int response_code, | |
58 const ResponseCookies& cookies, | |
59 const std::string& data); | |
60 | |
61 // Create a URLFetcher for a given request message and response handler. | |
62 void CreateFetcher(const em::DeviceManagementRequest& request, | |
63 ResponseHandler* handler, | |
64 const std::string& query_params, | |
65 const std::string& extra_headers); | |
66 | |
67 // Fill in the common query parameters. | |
68 void PutCommonQueryParameters(URLQueryParameters* params); | |
69 | |
70 // Server at which to contact the service. | |
71 const std::string server_url_; | |
72 | |
73 // The request context we use. | |
74 scoped_refptr<URLRequestContextGetter> request_context_getter_; | |
75 | |
76 // Keeps track of all in-flight requests an their response handlers. | |
77 ResponseHandlerMap response_handlers_; | |
78 | 58 |
79 DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackendImpl); | 59 DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackendImpl); |
80 }; | 60 }; |
81 | 61 |
82 } // namespace policy | 62 } // namespace policy |
83 | 63 |
84 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ | 64 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ |
OLD | NEW |