| 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_DEVICE_MANAGEMENT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ |
| 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_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 27 matching lines...) Expand all Loading... |
| 38 TYPE_AUTO_ENROLLMENT, | 38 TYPE_AUTO_ENROLLMENT, |
| 39 TYPE_REGISTRATION, | 39 TYPE_REGISTRATION, |
| 40 TYPE_POLICY_FETCH, | 40 TYPE_POLICY_FETCH, |
| 41 TYPE_UNREGISTRATION, | 41 TYPE_UNREGISTRATION, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 typedef base::Callback< | 44 typedef base::Callback< |
| 45 void(DeviceManagementStatus, | 45 void(DeviceManagementStatus, |
| 46 const enterprise_management::DeviceManagementResponse&)> Callback; | 46 const enterprise_management::DeviceManagementResponse&)> Callback; |
| 47 | 47 |
| 48 typedef base::Callback<void(DeviceManagementRequestJob*)> RetryCallback; |
| 49 |
| 48 virtual ~DeviceManagementRequestJob(); | 50 virtual ~DeviceManagementRequestJob(); |
| 49 | 51 |
| 50 // Functions for configuring the job. These should only be called before | 52 // Functions for configuring the job. These should only be called before |
| 51 // Start()ing the job, but never afterwards. | 53 // Start()ing the job, but never afterwards. |
| 52 void SetGaiaToken(const std::string& gaia_token); | 54 void SetGaiaToken(const std::string& gaia_token); |
| 53 void SetOAuthToken(const std::string& oauth_token); | 55 void SetOAuthToken(const std::string& oauth_token); |
| 54 void SetUserAffiliation(UserAffiliation user_affiliation); | 56 void SetUserAffiliation(UserAffiliation user_affiliation); |
| 55 void SetDMToken(const std::string& dm_token); | 57 void SetDMToken(const std::string& dm_token); |
| 56 void SetClientID(const std::string& client_id); | 58 void SetClientID(const std::string& client_id); |
| 57 enterprise_management::DeviceManagementRequest* GetRequest(); | 59 enterprise_management::DeviceManagementRequest* GetRequest(); |
| 58 | 60 |
| 61 // A job may automatically retry if it fails due to a temporary condition, or |
| 62 // due to proxy misconfigurations. If a |retry_callback| is set then it will |
| 63 // be invoked with the DeviceManagementRequestJob as an argument when that |
| 64 // happens, so that the job's owner can customize the retry request before |
| 65 // it's sent. |
| 66 void SetRetryCallback(const RetryCallback& retry_callback); |
| 67 |
| 59 // Starts the job. |callback| will be invoked on completion. | 68 // Starts the job. |callback| will be invoked on completion. |
| 60 void Start(const DeviceManagementRequestJob::Callback& callback); | 69 void Start(const Callback& callback); |
| 61 | 70 |
| 62 protected: | 71 protected: |
| 63 typedef std::vector<std::pair<std::string, std::string> > ParameterMap; | 72 typedef std::vector<std::pair<std::string, std::string> > ParameterMap; |
| 64 | 73 |
| 65 explicit DeviceManagementRequestJob(JobType type); | 74 explicit DeviceManagementRequestJob(JobType type); |
| 66 | 75 |
| 67 // Appends a parameter to |query_params|. | 76 // Appends a parameter to |query_params|. |
| 68 void AddParameter(const std::string& name, const std::string& value); | 77 void AddParameter(const std::string& name, const std::string& value); |
| 69 | 78 |
| 70 // Fires the job, to be filled in by implementations. | 79 // Fires the job, to be filled in by implementations. |
| 71 virtual void Run() = 0; | 80 virtual void Run() = 0; |
| 72 | 81 |
| 73 ParameterMap query_params_; | 82 ParameterMap query_params_; |
| 74 std::string gaia_token_; | 83 std::string gaia_token_; |
| 75 std::string dm_token_; | 84 std::string dm_token_; |
| 76 enterprise_management::DeviceManagementRequest request_; | 85 enterprise_management::DeviceManagementRequest request_; |
| 86 RetryCallback retry_callback_; |
| 77 | 87 |
| 78 Callback callback_; | 88 Callback callback_; |
| 79 | 89 |
| 80 private: | 90 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJob); | 91 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJob); |
| 82 }; | 92 }; |
| 83 | 93 |
| 84 // The device management service is responsible for everything related to | 94 // The device management service is responsible for everything related to |
| 85 // communication with the device management server. It creates the backends | 95 // communication with the device management server. It creates the backends |
| 86 // objects that the device management policy provider and friends use to issue | 96 // objects that the device management policy provider and friends use to issue |
| 87 // requests. | 97 // requests. |
| 88 class DeviceManagementService : public net::URLFetcherDelegate { | 98 class DeviceManagementService : public net::URLFetcherDelegate { |
| 89 public: | 99 public: |
| 90 explicit DeviceManagementService(const std::string& server_url); | 100 explicit DeviceManagementService(const std::string& server_url); |
| 91 virtual ~DeviceManagementService(); | 101 virtual ~DeviceManagementService(); |
| 92 | 102 |
| 103 // The ID of URLFetchers created by the DeviceManagementService. This can be |
| 104 // used by tests that use a TestURLFetcherFactory to get the pending fetchers |
| 105 // created by the DeviceManagementService. |
| 106 static const int kURLFetcherID; |
| 107 |
| 93 // Creates a new device management request job. Ownership is transferred to | 108 // Creates a new device management request job. Ownership is transferred to |
| 94 // the caller. | 109 // the caller. |
| 95 virtual DeviceManagementRequestJob* CreateJob( | 110 virtual DeviceManagementRequestJob* CreateJob( |
| 96 DeviceManagementRequestJob::JobType type); | 111 DeviceManagementRequestJob::JobType type); |
| 97 | 112 |
| 98 // Schedules a task to run |Initialize| after |delay_milliseconds| had passed. | 113 // Schedules a task to run |Initialize| after |delay_milliseconds| had passed. |
| 99 void ScheduleInitialization(int64 delay_milliseconds); | 114 void ScheduleInitialization(int64 delay_milliseconds); |
| 100 | 115 |
| 101 // Makes the service stop all requests and drop the reference to the request | 116 // Makes the service stop all requests and drop the reference to the request |
| 102 // context. | 117 // context. |
| 103 void Shutdown(); | 118 void Shutdown(); |
| 104 | 119 |
| 105 private: | 120 private: |
| 106 typedef std::map<const net::URLFetcher*, | 121 typedef std::map<const net::URLFetcher*, |
| 107 DeviceManagementRequestJobImpl*> JobFetcherMap; | 122 DeviceManagementRequestJobImpl*> JobFetcherMap; |
| 108 typedef std::deque<DeviceManagementRequestJobImpl*> JobQueue; | 123 typedef std::deque<DeviceManagementRequestJobImpl*> JobQueue; |
| 109 | 124 |
| 110 friend class DeviceManagementRequestJobImpl; | 125 friend class DeviceManagementRequestJobImpl; |
| 111 | 126 |
| 112 // net::URLFetcherDelegate override. | 127 // net::URLFetcherDelegate override. |
| 113 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 128 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 114 | 129 |
| 115 // Does the actual initialization using the request context specified for | 130 // Does the actual initialization using the request context specified for |
| 116 // |PrepareInitialization|. This will also fire any pending network requests. | 131 // |PrepareInitialization|. This will also fire any pending network requests. |
| 117 void Initialize(); | 132 void Initialize(); |
| 118 | 133 |
| 119 // Starts a job. | 134 // Starts a job. |
| 120 void StartJob(DeviceManagementRequestJobImpl* job, bool bypass_proxy); | 135 void StartJob(DeviceManagementRequestJobImpl* job); |
| 121 | 136 |
| 122 // Adds a job. Caller must make sure the job pointer stays valid until the job | 137 // Adds a job. Caller must make sure the job pointer stays valid until the job |
| 123 // completes or gets canceled via RemoveJob(). | 138 // completes or gets canceled via RemoveJob(). |
| 124 void AddJob(DeviceManagementRequestJobImpl* job); | 139 void AddJob(DeviceManagementRequestJobImpl* job); |
| 125 | 140 |
| 126 // Removes a job. The job will be removed and won't receive a completion | 141 // Removes a job. The job will be removed and won't receive a completion |
| 127 // callback. | 142 // callback. |
| 128 void RemoveJob(DeviceManagementRequestJobImpl* job); | 143 void RemoveJob(DeviceManagementRequestJobImpl* job); |
| 129 | 144 |
| 130 // Server at which to contact the service. | 145 // Server at which to contact the service. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 145 | 160 |
| 146 // Used to create tasks to run |Initialize| delayed on the UI thread. | 161 // Used to create tasks to run |Initialize| delayed on the UI thread. |
| 147 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_; | 162 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_; |
| 148 | 163 |
| 149 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); | 164 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); |
| 150 }; | 165 }; |
| 151 | 166 |
| 152 } // namespace policy | 167 } // namespace policy |
| 153 | 168 |
| 154 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ | 169 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ |
| OLD | NEW |