| 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 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 110 friend class DeviceManagementRequestJobImpl; | 120 friend class DeviceManagementRequestJobImpl; |
| 111 | 121 |
| 112 // net::URLFetcherDelegate override. | 122 // net::URLFetcherDelegate override. |
| 113 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 123 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 114 | 124 |
| 115 // Does the actual initialization using the request context specified for | 125 // Does the actual initialization using the request context specified for |
| 116 // |PrepareInitialization|. This will also fire any pending network requests. | 126 // |PrepareInitialization|. This will also fire any pending network requests. |
| 117 void Initialize(); | 127 void Initialize(); |
| 118 | 128 |
| 119 // Starts a job. | 129 // Starts a job. |
| 120 void StartJob(DeviceManagementRequestJobImpl* job, bool bypass_proxy); | 130 void StartJob(DeviceManagementRequestJobImpl* job); |
| 121 | 131 |
| 122 // Adds a job. Caller must make sure the job pointer stays valid until the job | 132 // Adds a job. Caller must make sure the job pointer stays valid until the job |
| 123 // completes or gets canceled via RemoveJob(). | 133 // completes or gets canceled via RemoveJob(). |
| 124 void AddJob(DeviceManagementRequestJobImpl* job); | 134 void AddJob(DeviceManagementRequestJobImpl* job); |
| 125 | 135 |
| 126 // Removes a job. The job will be removed and won't receive a completion | 136 // Removes a job. The job will be removed and won't receive a completion |
| 127 // callback. | 137 // callback. |
| 128 void RemoveJob(DeviceManagementRequestJobImpl* job); | 138 void RemoveJob(DeviceManagementRequestJobImpl* job); |
| 129 | 139 |
| 130 // Server at which to contact the service. | 140 // Server at which to contact the service. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 145 | 155 |
| 146 // Used to create tasks to run |Initialize| delayed on the UI thread. | 156 // Used to create tasks to run |Initialize| delayed on the UI thread. |
| 147 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_; | 157 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_; |
| 148 | 158 |
| 149 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); | 159 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService); |
| 150 }; | 160 }; |
| 151 | 161 |
| 152 } // namespace policy | 162 } // namespace policy |
| 153 | 163 |
| 154 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ | 164 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_ |
| OLD | NEW |