OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ |
| 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <deque> |
| 10 #include <map> |
| 11 #include <string> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "chrome/browser/policy/device_management_backend.h" |
| 15 #include "chrome/common/net/url_fetcher.h" |
| 16 #include "googleurl/src/gurl.h" |
| 17 |
| 18 class Profile; |
| 19 class URLRequestContextGetter; |
| 20 |
| 21 namespace policy { |
| 22 |
| 23 class DeviceManagementBackendImpl; |
| 24 |
| 25 // The device management service is responsible for everything related to |
| 26 // communication with the device management server. It creates the backends |
| 27 // objects that the device management policy provider and friends use to issue |
| 28 // requests. |
| 29 class DeviceManagementService : public URLFetcher::Delegate { |
| 30 public: |
| 31 // Describes a device management job handled by the service. |
| 32 class DeviceManagementJob { |
| 33 public: |
| 34 virtual ~DeviceManagementJob() {} |
| 35 |
| 36 // Handles the URL request response. |
| 37 virtual void HandleResponse(const URLRequestStatus& status, |
| 38 int response_code, |
| 39 const ResponseCookies& cookies, |
| 40 const std::string& data) = 0; |
| 41 |
| 42 // Gets the URL to contact. |
| 43 virtual GURL GetURL(const std::string& server_url) = 0; |
| 44 |
| 45 // Configures the fetcher, setting up payload and headers. |
| 46 virtual void ConfigureRequest(URLFetcher* fetcher) = 0; |
| 47 }; |
| 48 |
| 49 explicit DeviceManagementService(const std::string& server_url); |
| 50 virtual ~DeviceManagementService(); |
| 51 |
| 52 // Constructs a device management backend for use by client code. Ownership of |
| 53 // the returned backend object is transferred to the caller. |
| 54 DeviceManagementBackend* CreateBackend(); |
| 55 |
| 56 // Provides the backend with a request context so it can make actual network |
| 57 // requests. This will also fire any requests queued earlier. |
| 58 void Initialize(URLRequestContextGetter* request_context_getter); |
| 59 |
| 60 // Makes the service stop all requests and drop the reference to the request |
| 61 // context. |
| 62 void Shutdown(); |
| 63 |
| 64 // Adds a job. Caller must make sure the job pointer stays valid until the job |
| 65 // completes or gets cancelled via RemoveJob(). |
| 66 void AddJob(DeviceManagementJob* job); |
| 67 |
| 68 // Removes a job. The job will be removed and won't receive a completion |
| 69 // callback. |
| 70 void RemoveJob(DeviceManagementJob* job); |
| 71 |
| 72 private: |
| 73 typedef std::map<const URLFetcher*, DeviceManagementJob*> JobFetcherMap; |
| 74 typedef std::deque<DeviceManagementJob*> JobQueue; |
| 75 |
| 76 // Starts the given job. |
| 77 void StartJob(DeviceManagementJob* job); |
| 78 |
| 79 // URLFetcher::Delegate override. |
| 80 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 81 const GURL& url, |
| 82 const URLRequestStatus& status, |
| 83 int response_code, |
| 84 const ResponseCookies& cookies, |
| 85 const std::string& data); |
| 86 |
| 87 // Server at which to contact the service. |
| 88 const std::string server_url_; |
| 89 |
| 90 // The request context we use. |
| 91 scoped_refptr<URLRequestContextGetter> request_context_getter_; |
| 92 |
| 93 // The jobs we currently have in flight. |
| 94 JobFetcherMap pending_jobs_; |
| 95 |
| 96 // Jobs that are registered, but not started yet. |
| 97 JobQueue queued_jobs_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); |
| 100 }; |
| 101 |
| 102 } // namespace policy |
| 103 |
| 104 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ |
OLD | NEW |