OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ |
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/local_discovery/privet_http.h" | 14 #include "chrome/browser/local_discovery/privet_http.h" |
14 | 15 |
15 namespace local_discovery { | 16 namespace local_discovery { |
16 | 17 |
17 class PrivetHTTPClientImpl; | 18 class PrivetHTTPClientImpl; |
18 | 19 |
19 class PrivetInfoOperationImpl : public PrivetInfoOperation, | 20 class PrivetInfoOperationImpl : public PrivetInfoOperation, |
20 public PrivetURLFetcher::Delegate { | 21 public PrivetURLFetcher::Delegate { |
21 public: | 22 public: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 public PrivetURLFetcher::Delegate, | 150 public PrivetURLFetcher::Delegate, |
150 public PrivetInfoOperation::Delegate { | 151 public PrivetInfoOperation::Delegate { |
151 public: | 152 public: |
152 PrivetLocalPrintOperationImpl( | 153 PrivetLocalPrintOperationImpl( |
153 PrivetHTTPClientImpl* privet_client, | 154 PrivetHTTPClientImpl* privet_client, |
154 PrivetLocalPrintOperation::Delegate* delegate); | 155 PrivetLocalPrintOperation::Delegate* delegate); |
155 | 156 |
156 virtual ~PrivetLocalPrintOperationImpl(); | 157 virtual ~PrivetLocalPrintOperationImpl(); |
157 virtual void Start() OVERRIDE; | 158 virtual void Start() OVERRIDE; |
158 | 159 |
159 virtual void SendData(const std::string& data) OVERRIDE; | 160 virtual void SetData(base::RefCountedBytes* data) OVERRIDE; |
160 virtual void SendDataFile(const base::FilePath& data) OVERRIDE; | |
161 | 161 |
162 virtual void SetTicket(const std::string& ticket) OVERRIDE; | 162 virtual void SetTicket(const std::string& ticket) OVERRIDE; |
163 | 163 |
164 virtual void SetUsername(const std::string& user) OVERRIDE; | 164 virtual void SetUsername(const std::string& user) OVERRIDE; |
165 | 165 |
166 virtual void SetJobname(const std::string& jobname) OVERRIDE; | 166 virtual void SetJobname(const std::string& jobname) OVERRIDE; |
167 | 167 |
168 virtual void SetOffline(bool offline) OVERRIDE; | 168 virtual void SetOffline(bool offline) OVERRIDE; |
169 | 169 |
| 170 virtual void SetPWGRasterConverterForTesting( |
| 171 scoped_ptr<PWGRasterConverter> pwg_raster_converter) OVERRIDE; |
| 172 |
170 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE; | 173 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE; |
171 | 174 |
172 virtual void OnError(PrivetURLFetcher* fetcher, | 175 virtual void OnError(PrivetURLFetcher* fetcher, |
173 PrivetURLFetcher::ErrorType error) OVERRIDE; | 176 PrivetURLFetcher::ErrorType error) OVERRIDE; |
174 virtual void OnParsedJson(PrivetURLFetcher* fetcher, | 177 virtual void OnParsedJson(PrivetURLFetcher* fetcher, |
175 const base::DictionaryValue* value, | 178 const base::DictionaryValue* value, |
176 bool has_error) OVERRIDE; | 179 bool has_error) OVERRIDE; |
177 virtual void OnNeedPrivetToken( | 180 virtual void OnNeedPrivetToken( |
178 PrivetURLFetcher* fetcher, | 181 PrivetURLFetcher* fetcher, |
179 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE; | 182 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE; |
180 | 183 |
181 virtual void OnPrivetInfoDone(PrivetInfoOperation* operation, | 184 virtual void OnPrivetInfoDone(PrivetInfoOperation* operation, |
182 int http_code, | 185 int http_code, |
183 const base::DictionaryValue* value) OVERRIDE; | 186 const base::DictionaryValue* value) OVERRIDE; |
184 private: | 187 private: |
185 typedef base::Callback<void(bool, const base::DictionaryValue* value)> | 188 typedef base::Callback<void(bool, const base::DictionaryValue* value)> |
186 ResponseCallback; | 189 ResponseCallback; |
187 | 190 |
188 void StartInitialRequest(); | 191 void StartInitialRequest(); |
189 void GetCapabilities(); | 192 void GetCapabilities(); |
190 void DoCreatejob(); | 193 void DoCreatejob(); |
191 void DoSubmitdoc(); | 194 void DoSubmitdoc(); |
192 | 195 |
| 196 void StartConvertToPWG(); |
| 197 void StartPrinting(); |
| 198 |
193 void OnCapabilitiesResponse(bool has_error, | 199 void OnCapabilitiesResponse(bool has_error, |
194 const base::DictionaryValue* value); | 200 const base::DictionaryValue* value); |
195 void OnSubmitdocResponse(bool has_error, | 201 void OnSubmitdocResponse(bool has_error, |
196 const base::DictionaryValue* value); | 202 const base::DictionaryValue* value); |
197 void OnCreatejobResponse(bool has_error, | 203 void OnCreatejobResponse(bool has_error, |
198 const base::DictionaryValue* value); | 204 const base::DictionaryValue* value); |
199 | 205 void OnPWGRasterConverted(bool success, const base::FilePath& pwg_file_path); |
200 void SendDataInternal(); | |
201 | 206 |
202 PrivetHTTPClientImpl* privet_client_; | 207 PrivetHTTPClientImpl* privet_client_; |
203 PrivetLocalPrintOperation::Delegate* delegate_; | 208 PrivetLocalPrintOperation::Delegate* delegate_; |
204 | 209 |
205 ResponseCallback current_response_; | 210 ResponseCallback current_response_; |
206 | 211 |
207 std::string ticket_; | 212 std::string ticket_; |
208 std::string data_; | 213 scoped_refptr<base::RefCountedBytes> data_; |
209 base::FilePath data_file_; | 214 base::FilePath pwg_file_path_; |
210 | 215 |
211 bool use_pdf_; | 216 bool use_pdf_; |
212 bool has_capabilities_; | 217 bool has_capabilities_; |
213 bool has_extended_workflow_; | 218 bool has_extended_workflow_; |
214 bool started_; | 219 bool started_; |
215 bool offline_; | 220 bool offline_; |
216 | 221 |
217 std::string user_; | 222 std::string user_; |
218 std::string jobname_; | 223 std::string jobname_; |
219 | 224 |
220 std::string jobid_; | 225 std::string jobid_; |
221 | 226 |
222 int invalid_job_retries_; | 227 int invalid_job_retries_; |
223 | 228 |
224 scoped_ptr<PrivetURLFetcher> url_fetcher_; | 229 scoped_ptr<PrivetURLFetcher> url_fetcher_; |
225 scoped_ptr<PrivetInfoOperation> info_operation_; | 230 scoped_ptr<PrivetInfoOperation> info_operation_; |
| 231 scoped_ptr<PWGRasterConverter> pwg_raster_converter_; |
226 | 232 |
227 base::WeakPtrFactory<PrivetLocalPrintOperationImpl> weak_factory_; | 233 base::WeakPtrFactory<PrivetLocalPrintOperationImpl> weak_factory_; |
228 }; | 234 }; |
229 | 235 |
230 class PrivetHTTPClientImpl : public PrivetHTTPClient, | 236 class PrivetHTTPClientImpl : public PrivetHTTPClient, |
231 public PrivetInfoOperation::Delegate { | 237 public PrivetInfoOperation::Delegate { |
232 public: | 238 public: |
233 PrivetHTTPClientImpl( | 239 PrivetHTTPClientImpl( |
234 const std::string& name, | 240 const std::string& name, |
235 const net::HostPortPair& host_port, | 241 const net::HostPortPair& host_port, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 PrivetURLFetcherFactory fetcher_factory_; | 281 PrivetURLFetcherFactory fetcher_factory_; |
276 net::HostPortPair host_port_; | 282 net::HostPortPair host_port_; |
277 scoped_ptr<base::DictionaryValue> cached_info_; | 283 scoped_ptr<base::DictionaryValue> cached_info_; |
278 | 284 |
279 scoped_ptr<PrivetInfoOperation> info_operation_; | 285 scoped_ptr<PrivetInfoOperation> info_operation_; |
280 TokenCallbackVector token_callbacks_; | 286 TokenCallbackVector token_callbacks_; |
281 }; | 287 }; |
282 | 288 |
283 } // namespace local_discovery | 289 } // namespace local_discovery |
284 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ | 290 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ |
OLD | NEW |