OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CLOUD_DEVICE_MANAGEMENT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_DEVICE_MANAGEMENT_SERVICE_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_DEVICE_MANAGEMENT_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_DEVICE_MANAGEMENT_SERVICE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 private: | 94 private: |
95 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJob); | 95 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJob); |
96 }; | 96 }; |
97 | 97 |
98 // The device management service is responsible for everything related to | 98 // The device management service is responsible for everything related to |
99 // communication with the device management server. It creates the backends | 99 // communication with the device management server. It creates the backends |
100 // objects that the device management policy provider and friends use to issue | 100 // objects that the device management policy provider and friends use to issue |
101 // requests. | 101 // requests. |
102 class DeviceManagementService : public net::URLFetcherDelegate { | 102 class DeviceManagementService : public net::URLFetcherDelegate { |
103 public: | 103 public: |
| 104 // Obtains the parameters used to contact the server. |
| 105 // This allows creating the DeviceManagementService early and getting these |
| 106 // parameters later. Passing the parameters directly in the ctor isn't |
| 107 // possible because some aren't ready during startup. http://crbug.com/302798 |
| 108 class Configuration { |
| 109 public: |
| 110 virtual ~Configuration() {} |
| 111 |
| 112 // Server at which to contact the service. |
| 113 virtual std::string GetServerUrl() = 0; |
| 114 |
| 115 // Value for the User-Agent header. |
| 116 virtual std::string GetUserAgent() = 0; |
| 117 |
| 118 // Agent reported in the "agent" query parameter. |
| 119 virtual std::string GetAgentParameter() = 0; |
| 120 |
| 121 // The platform reported in the "platform" query parameter. |
| 122 virtual std::string GetPlatformParameter() = 0; |
| 123 }; |
| 124 |
104 DeviceManagementService( | 125 DeviceManagementService( |
105 scoped_refptr<net::URLRequestContextGetter> request_context, | 126 scoped_ptr<Configuration> configuration, |
106 const std::string& server_url, | 127 scoped_refptr<net::URLRequestContextGetter> request_context); |
107 const std::string& user_agent, | |
108 const std::string& agent_parameter, | |
109 const std::string& platform_parameter); | |
110 virtual ~DeviceManagementService(); | 128 virtual ~DeviceManagementService(); |
111 | 129 |
112 // The ID of URLFetchers created by the DeviceManagementService. This can be | 130 // The ID of URLFetchers created by the DeviceManagementService. This can be |
113 // used by tests that use a TestURLFetcherFactory to get the pending fetchers | 131 // used by tests that use a TestURLFetcherFactory to get the pending fetchers |
114 // created by the DeviceManagementService. | 132 // created by the DeviceManagementService. |
115 static const int kURLFetcherID; | 133 static const int kURLFetcherID; |
116 | 134 |
117 // Creates a new device management request job. Ownership is transferred to | 135 // Creates a new device management request job. Ownership is transferred to |
118 // the caller. | 136 // the caller. |
119 virtual DeviceManagementRequestJob* CreateJob( | 137 virtual DeviceManagementRequestJob* CreateJob( |
(...skipping 24 matching lines...) Expand all Loading... |
144 void StartJob(DeviceManagementRequestJobImpl* job); | 162 void StartJob(DeviceManagementRequestJobImpl* job); |
145 | 163 |
146 // Adds a job. Caller must make sure the job pointer stays valid until the job | 164 // Adds a job. Caller must make sure the job pointer stays valid until the job |
147 // completes or gets canceled via RemoveJob(). | 165 // completes or gets canceled via RemoveJob(). |
148 void AddJob(DeviceManagementRequestJobImpl* job); | 166 void AddJob(DeviceManagementRequestJobImpl* job); |
149 | 167 |
150 // Removes a job. The job will be removed and won't receive a completion | 168 // Removes a job. The job will be removed and won't receive a completion |
151 // callback. | 169 // callback. |
152 void RemoveJob(DeviceManagementRequestJobImpl* job); | 170 void RemoveJob(DeviceManagementRequestJobImpl* job); |
153 | 171 |
| 172 // A Configuration implementation that is used to obtain various parameters |
| 173 // used to talk to the device management server. |
| 174 scoped_ptr<Configuration> configuration_; |
| 175 |
154 // The request context is wrapped by the |request_context_getter_|. | 176 // The request context is wrapped by the |request_context_getter_|. |
155 scoped_refptr<net::URLRequestContextGetter> request_context_; | 177 scoped_refptr<net::URLRequestContextGetter> request_context_; |
156 | 178 |
157 // Server at which to contact the service. | |
158 const std::string server_url_; | |
159 | |
160 // Value for the User-Agent header. | |
161 const std::string user_agent_; | |
162 | |
163 // Agent reported in the "agent" query parameter. | |
164 const std::string agent_parameter_; | |
165 | |
166 // The platform reported in the "platform" query parameter. | |
167 const std::string platform_parameter_; | |
168 | |
169 // The request context we use. This is a wrapper of |request_context_|. | 179 // The request context we use. This is a wrapper of |request_context_|. |
170 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 180 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
171 | 181 |
172 // The jobs we currently have in flight. | 182 // The jobs we currently have in flight. |
173 JobFetcherMap pending_jobs_; | 183 JobFetcherMap pending_jobs_; |
174 | 184 |
175 // Jobs that are registered, but not started yet. | 185 // Jobs that are registered, but not started yet. |
176 JobQueue queued_jobs_; | 186 JobQueue queued_jobs_; |
177 | 187 |
178 // If this service is initialized, incoming requests get fired instantly. | 188 // If this service is initialized, incoming requests get fired instantly. |
179 // If it is not initialized, incoming requests are queued. | 189 // If it is not initialized, incoming requests are queued. |
180 bool initialized_; | 190 bool initialized_; |
181 | 191 |
182 // Used to create tasks to run |Initialize| delayed on the UI thread. | 192 // Used to create tasks to run |Initialize| delayed on the UI thread. |
183 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_; | 193 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_; |
184 | 194 |
185 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); | 195 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); |
186 }; | 196 }; |
187 | 197 |
188 } // namespace policy | 198 } // namespace policy |
189 | 199 |
190 #endif // CHROME_BROWSER_POLICY_CLOUD_DEVICE_MANAGEMENT_SERVICE_H_ | 200 #endif // CHROME_BROWSER_POLICY_CLOUD_DEVICE_MANAGEMENT_SERVICE_H_ |
OLD | NEW |