Chromium Code Reviews| Index: chrome/browser/policy/device_management_service.h |
| diff --git a/chrome/browser/policy/device_management_service.h b/chrome/browser/policy/device_management_service.h |
| index 2170c8f68ccc03a3dba064b7e7d2d59d32c98c80..9d8661566089bf87ec9935e3dc8fb9b72fa5444f 100644 |
| --- a/chrome/browser/policy/device_management_service.h |
| +++ b/chrome/browser/policy/device_management_service.h |
| @@ -12,21 +12,75 @@ |
| #include <vector> |
|
Joao da Silva
2012/01/02 16:14:43
Nit: not used
Mattias Nissler (ping if slow)
2012/01/02 17:53:23
Done.
|
| #include "base/basictypes.h" |
| +#include "base/callback.h" |
| #include "base/compiler_specific.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/policy/cloud_policy_constants.h" |
| +#include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| #include "content/public/common/url_fetcher_delegate.h" |
| #include "googleurl/src/gurl.h" |
|
Joao da Silva
2012/01/02 16:14:43
Nit: move to .cc
Mattias Nissler (ping if slow)
2012/01/02 17:53:23
Done.
|
| namespace net { |
| class URLRequestContextGetter; |
| class URLRequestStatus; |
|
Joao da Silva
2012/01/02 16:14:43
Nit: not used
Mattias Nissler (ping if slow)
2012/01/02 17:53:23
Done.
|
| -typedef std::vector<std::string> ResponseCookies; |
| } |
| namespace policy { |
| class DeviceManagementBackend; |
| +class DeviceManagementRequestJobImpl; |
| +class DeviceManagementService; |
| + |
| +// DeviceManagementRequestJob describes a request to send to the device |
| +// management service. Jobs are created by DeviceManagementService. They can be |
| +// canceled by deleting the object. |
| +class DeviceManagementRequestJob { |
| + public: |
| + // Describes the job type. |
| + enum JobType { |
| + TYPE_AUTO_ENROLLMENT, |
| + TYPE_REGISTRATION, |
| + TYPE_POLICY_FETCH, |
| + TYPE_UNREGISTRATION, |
| + }; |
| + |
| + typedef base::Callback< |
| + void(DeviceManagementStatus, |
| + const enterprise_management::DeviceManagementResponse&)> Callback; |
| + |
| + virtual ~DeviceManagementRequestJob(); |
| + |
| + // Functions for configuring the job. These should only be called before |
| + // Start()ing the job, but never afterwards. |
| + void SetGaiaToken(const std::string& gaia_token); |
| + void SetOAuthToken(const std::string& oauth_token); |
| + void SetUserAffiliation(UserAffiliation user_affiliation); |
| + void SetDMToken(const std::string& dm_token); |
| + void SetClientID(const std::string& client_id); |
| + enterprise_management::DeviceManagementRequest* GetRequest(); |
| + |
| + // Starts the job. |callback| will be invoked on completion. |
| + void Start(const DeviceManagementRequestJob::Callback& callback); |
| + |
| + protected: |
| + typedef std::map<std::string, std::string> ParameterMap; |
| + |
| + explicit DeviceManagementRequestJob(JobType type); |
| + |
| + // Fires the job, to be filled in by implementations. |
| + virtual void Run() = 0; |
| + |
| + ParameterMap query_params_; |
|
Joao da Silva
2012/01/02 16:14:43
This broke some tests on linux_chromeos. It used t
Mattias Nissler (ping if slow)
2012/01/02 17:53:23
Sigh. Reverted.
|
| + std::string gaia_token_; |
| + std::string dm_token_; |
| + enterprise_management::DeviceManagementRequest request_; |
| + |
| + Callback callback_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJob); |
| +}; |
| // The device management service is responsible for everything related to |
| // communication with the device management server. It creates the backends |
| @@ -34,32 +88,20 @@ class DeviceManagementBackend; |
| // requests. |
| class DeviceManagementService : public content::URLFetcherDelegate { |
| public: |
| - // Describes a device management job handled by the service. |
| - class DeviceManagementJob { |
| - public: |
| - virtual ~DeviceManagementJob() {} |
| - |
| - // Handles the URL request response. |
| - virtual void HandleResponse(const net::URLRequestStatus& status, |
| - int response_code, |
| - const net::ResponseCookies& cookies, |
| - const std::string& data) = 0; |
| - |
| - // Gets the URL to contact. |
| - virtual GURL GetURL(const std::string& server_url) = 0; |
| - |
| - // Configures the fetcher, setting up payload and headers. |
| - virtual void ConfigureRequest(content::URLFetcher* fetcher) = 0; |
| - }; |
| - |
| explicit DeviceManagementService(const std::string& server_url); |
| virtual ~DeviceManagementService(); |
| // Constructs a device management backend for use by client code. Ownership of |
| // the returned backend object is transferred to the caller. |
| // Marked virtual for the benefit of tests. |
| + // TODO(mnissler): This is deprecated, remove. Use CreateJob() instead. |
| virtual DeviceManagementBackend* CreateBackend(); |
| + // Creates a new device management request job. Ownership is transferred to |
| + // the caller. |
| + virtual DeviceManagementRequestJob* CreateJob( |
| + DeviceManagementRequestJob::JobType type); |
| + |
| // Schedules a task to run |Initialize| after |delay_milliseconds| had passed. |
| void ScheduleInitialization(int64 delay_milliseconds); |
| @@ -67,22 +109,12 @@ class DeviceManagementService : public content::URLFetcherDelegate { |
| // context. |
| void Shutdown(); |
| - // Adds a job. Caller must make sure the job pointer stays valid until the job |
| - // completes or gets canceled via RemoveJob(). |
| - void AddJob(DeviceManagementJob* job); |
| - |
| - // Removes a job. The job will be removed and won't receive a completion |
| - // callback. |
| - void RemoveJob(DeviceManagementJob* job); |
| - |
| - protected: |
| - // Starts the given job. |
| - virtual void StartJob(DeviceManagementJob* job, bool bypass_proxy); |
| - |
| private: |
| - typedef std::map<const content::URLFetcher*, DeviceManagementJob*> |
| - JobFetcherMap; |
| - typedef std::deque<DeviceManagementJob*> JobQueue; |
| + typedef std::map<const content::URLFetcher*, |
| + DeviceManagementRequestJobImpl*> JobFetcherMap; |
| + typedef std::deque<DeviceManagementRequestJobImpl*> JobQueue; |
| + |
| + friend class DeviceManagementRequestJobImpl; |
| // content::URLFetcherDelegate override. |
| virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| @@ -91,6 +123,17 @@ class DeviceManagementService : public content::URLFetcherDelegate { |
| // |PrepareInitialization|. This will also fire any pending network requests. |
| void Initialize(); |
| + // Starts a job. |
| + void StartJob(DeviceManagementRequestJobImpl* job, bool bypass_proxy); |
| + |
| + // Adds a job. Caller must make sure the job pointer stays valid until the job |
| + // completes or gets canceled via RemoveJob(). |
| + void AddJob(DeviceManagementRequestJobImpl* job); |
| + |
| + // Removes a job. The job will be removed and won't receive a completion |
| + // callback. |
| + void RemoveJob(DeviceManagementRequestJobImpl* job); |
| + |
| // Server at which to contact the service. |
| const std::string server_url_; |