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 <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "chrome/browser/policy/device_management_backend.h" | 12 #include "chrome/browser/policy/device_management_backend.h" |
13 #include "chrome/common/net/url_fetcher.h" | 13 #include "chrome/common/net/url_fetcher.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 | 15 |
16 class Profile; | |
16 class URLRequestContextGetter; | 17 class URLRequestContextGetter; |
17 | 18 |
18 namespace policy { | 19 namespace policy { |
19 | 20 |
20 class ResponseHandler; | 21 class DeviceManagementJob; |
21 class URLQueryParameters; | |
22 | 22 |
23 // Device management backend implementation. This implementation makes HTTP | 23 // Device management backend implementation. This implementation makes HTTP |
24 // requests to the policy server through the net layer. | 24 // requests to the policy server through the net layer. |
25 class DeviceManagementBackendImpl : public DeviceManagementBackend, | 25 class DeviceManagementBackendImpl : public URLFetcher::Delegate { |
26 public URLFetcher::Delegate { | |
27 public: | 26 public: |
28 explicit DeviceManagementBackendImpl(const std::string& server_url); | 27 // Construct a new device management backend. Client code should not call |
28 // this, it's only public so tests can access it. | |
markusheintz_
2010/11/18 12:40:36
If the constructor should be private, wouldn't it
Mattias Nissler (ping if slow)
2010/11/19 17:21:53
doesn't apply any longer.
| |
29 DeviceManagementBackendImpl(const std::string& server_url, | |
30 URLRequestContextGetter* request_context_getter); | |
danno
2010/11/16 22:02:56
I don't know if it would be cleaner/better, but yo
Mattias Nissler (ping if slow)
2010/11/19 17:21:53
doesn't apply any longer.
| |
29 virtual ~DeviceManagementBackendImpl(); | 31 virtual ~DeviceManagementBackendImpl(); |
30 | 32 |
31 // GoogleAppsPolicyService overrides: | 33 // Constructs a device management backend for use by client code. |
32 virtual void ProcessRegisterRequest( | 34 static DeviceManagementBackend* Get(); |
danno
2010/11/16 22:02:56
I am unsure about the name. I get the whole multi
Mattias Nissler (ping if slow)
2010/11/19 17:21:53
Done.
| |
33 const std::string& auth_token, | 35 |
34 const std::string& device_id, | 36 // Initialize the backend. |
35 const em::DeviceRegisterRequest& request, | 37 static DeviceManagementBackendImpl* Initialize(Profile* profile); |
36 DeviceRegisterResponseDelegate* response_delegate); | |
37 virtual void ProcessUnregisterRequest( | |
38 const std::string& device_management_token, | |
39 const em::DeviceUnregisterRequest& request, | |
40 DeviceUnregisterResponseDelegate* response_delegate); | |
41 virtual void ProcessPolicyRequest( | |
42 const std::string& device_management_token, | |
43 const em::DevicePolicyRequest& request, | |
44 DevicePolicyResponseDelegate* response_delegate); | |
45 | 38 |
46 // Get the agent string (used for HTTP user agent and as agent passed to the | 39 // Get the agent string (used for HTTP user agent and as agent passed to the |
47 // server). | 40 // server). |
48 static std::string GetAgentString(); | 41 static std::string GetAgentString(); |
49 | 42 |
50 private: | 43 private: |
51 typedef std::map<const URLFetcher*, ResponseHandler*> ResponseHandlerMap; | 44 typedef std::map<const URLFetcher*, DeviceManagementJob*> JobFetcherMap; |
45 | |
46 friend class DeviceManagementBackendProxy; | |
47 | |
48 // Starts the given job. Caller must make sure the job pointer stays valid | |
49 // until the job completes or CancelJob() gets called. | |
50 void StartJob(DeviceManagementJob* job); | |
51 | |
52 // Cancels a job. The job will be removed and won't receive a completion | |
53 // callback. | |
54 void CancelJob(DeviceManagementJob* job); | |
52 | 55 |
53 // URLFetcher::Delegate override. | 56 // URLFetcher::Delegate override. |
54 virtual void OnURLFetchComplete(const URLFetcher* source, | 57 virtual void OnURLFetchComplete(const URLFetcher* source, |
55 const GURL& url, | 58 const GURL& url, |
56 const URLRequestStatus& status, | 59 const URLRequestStatus& status, |
57 int response_code, | 60 int response_code, |
58 const ResponseCookies& cookies, | 61 const ResponseCookies& cookies, |
59 const std::string& data); | 62 const std::string& data); |
60 | 63 |
61 // Create a URLFetcher for a given request message and response handler. | 64 // The static device management backend instance. |
62 void CreateFetcher(const em::DeviceManagementRequest& request, | 65 static DeviceManagementBackendImpl* instance_; |
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 | 66 |
70 // Server at which to contact the service. | 67 // Server at which to contact the service. |
71 const std::string server_url_; | 68 const std::string server_url_; |
72 | 69 |
73 // The request context we use. | 70 // The request context we use. |
74 scoped_refptr<URLRequestContextGetter> request_context_getter_; | 71 scoped_refptr<URLRequestContextGetter> request_context_getter_; |
75 | 72 |
76 // Keeps track of all in-flight requests an their response handlers. | 73 // The jobs we currently have in flight. |
77 ResponseHandlerMap response_handlers_; | 74 JobFetcherMap pending_jobs_; |
78 | 75 |
79 DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackendImpl); | 76 DISALLOW_COPY_AND_ASSIGN(DeviceManagementBackendImpl); |
80 }; | 77 }; |
81 | 78 |
82 } // namespace policy | 79 } // namespace policy |
83 | 80 |
84 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ | 81 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_IMPL_H_ |
OLD | NEW |