Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: chrome/browser/local_discovery/privet_http_impl.h

Issue 320683002: Extracted PrivetV1HTTPClient with Privet v1 specific operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/local_discovery/privet_http.h" 14 #include "chrome/browser/local_discovery/privet_http.h"
15 #include "components/cloud_devices/common/cloud_device_description.h" 15 #include "components/cloud_devices/common/cloud_device_description.h"
16 #include "printing/pdf_render_settings.h" 16 #include "printing/pdf_render_settings.h"
17 17
18 namespace printing { 18 namespace printing {
19 struct PwgRasterSettings; 19 struct PwgRasterSettings;
20 }; 20 };
21 21
22 namespace local_discovery { 22 namespace local_discovery {
23 23
24 class PrivetHTTPClientImpl; 24 class PrivetHTTPClient;
25 25
26 class PrivetInfoOperationImpl : public PrivetJSONOperation, 26 class PrivetInfoOperationImpl : public PrivetJSONOperation,
27 public PrivetURLFetcher::Delegate { 27 public PrivetURLFetcher::Delegate {
28 public: 28 public:
29 PrivetInfoOperationImpl(PrivetHTTPClientImpl* privet_client, 29 PrivetInfoOperationImpl(PrivetHTTPClient* privet_client,
30 const PrivetJSONOperation::ResultCallback& callback); 30 const PrivetJSONOperation::ResultCallback& callback);
31 virtual ~PrivetInfoOperationImpl(); 31 virtual ~PrivetInfoOperationImpl();
32 32
33 virtual void Start() OVERRIDE; 33 virtual void Start() OVERRIDE;
34 34
35 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE; 35 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE;
36 36
37 virtual void OnError(PrivetURLFetcher* fetcher, 37 virtual void OnError(PrivetURLFetcher* fetcher,
38 PrivetURLFetcher::ErrorType error) OVERRIDE; 38 PrivetURLFetcher::ErrorType error) OVERRIDE;
39 virtual void OnParsedJson(PrivetURLFetcher* fetcher, 39 virtual void OnParsedJson(PrivetURLFetcher* fetcher,
40 const base::DictionaryValue* value, 40 const base::DictionaryValue* value,
41 bool has_error) OVERRIDE; 41 bool has_error) OVERRIDE;
42 42
43 private: 43 private:
44 PrivetHTTPClientImpl* privet_client_; 44 PrivetHTTPClient* privet_client_;
45 PrivetJSONOperation::ResultCallback callback_; 45 PrivetJSONOperation::ResultCallback callback_;
46 scoped_ptr<PrivetURLFetcher> url_fetcher_; 46 scoped_ptr<PrivetURLFetcher> url_fetcher_;
47 }; 47 };
48 48
49 class PrivetRegisterOperationImpl 49 class PrivetRegisterOperationImpl
50 : public PrivetRegisterOperation, 50 : public PrivetRegisterOperation,
51 public PrivetURLFetcher::Delegate, 51 public PrivetURLFetcher::Delegate,
52 public base::SupportsWeakPtr<PrivetRegisterOperationImpl> { 52 public base::SupportsWeakPtr<PrivetRegisterOperationImpl> {
53 public: 53 public:
54 PrivetRegisterOperationImpl(PrivetHTTPClientImpl* privet_client, 54 PrivetRegisterOperationImpl(PrivetHTTPClient* privet_client,
55 const std::string& user, 55 const std::string& user,
56 PrivetRegisterOperation::Delegate* delegate); 56 PrivetRegisterOperation::Delegate* delegate);
57 virtual ~PrivetRegisterOperationImpl(); 57 virtual ~PrivetRegisterOperationImpl();
58 58
59 virtual void Start() OVERRIDE; 59 virtual void Start() OVERRIDE;
60 virtual void Cancel() OVERRIDE; 60 virtual void Cancel() OVERRIDE;
61 virtual void CompleteRegistration() OVERRIDE; 61 virtual void CompleteRegistration() OVERRIDE;
62 62
63 virtual void OnError(PrivetURLFetcher* fetcher, 63 virtual void OnError(PrivetURLFetcher* fetcher,
64 PrivetURLFetcher::ErrorType error) OVERRIDE; 64 PrivetURLFetcher::ErrorType error) OVERRIDE;
65 65
66 virtual void OnParsedJson(PrivetURLFetcher* fetcher, 66 virtual void OnParsedJson(PrivetURLFetcher* fetcher,
67 const base::DictionaryValue* value, 67 const base::DictionaryValue* value,
68 bool has_error) OVERRIDE; 68 bool has_error) OVERRIDE;
69 69
70 virtual void OnNeedPrivetToken( 70 virtual void OnNeedPrivetToken(
71 PrivetURLFetcher* fetcher, 71 PrivetURLFetcher* fetcher,
72 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE; 72 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE;
73 73
74 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE; 74 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE;
75 private: 75 private:
76 class Cancelation : public PrivetURLFetcher::Delegate { 76 class Cancelation : public PrivetURLFetcher::Delegate {
77 public: 77 public:
78 Cancelation(PrivetHTTPClientImpl* privet_client, 78 Cancelation(PrivetHTTPClient* privet_client, const std::string& user);
79 const std::string& user);
80 virtual ~Cancelation(); 79 virtual ~Cancelation();
81 80
82 virtual void OnError(PrivetURLFetcher* fetcher, 81 virtual void OnError(PrivetURLFetcher* fetcher,
83 PrivetURLFetcher::ErrorType error) OVERRIDE; 82 PrivetURLFetcher::ErrorType error) OVERRIDE;
84 83
85 virtual void OnParsedJson(PrivetURLFetcher* fetcher, 84 virtual void OnParsedJson(PrivetURLFetcher* fetcher,
86 const base::DictionaryValue* value, 85 const base::DictionaryValue* value,
87 bool has_error) OVERRIDE; 86 bool has_error) OVERRIDE;
88 87
89 void Cleanup(); 88 void Cleanup();
(...skipping 12 matching lines...) Expand all
102 void StartResponse(const base::DictionaryValue& value); 101 void StartResponse(const base::DictionaryValue& value);
103 void GetClaimTokenResponse(const base::DictionaryValue& value); 102 void GetClaimTokenResponse(const base::DictionaryValue& value);
104 void CompleteResponse(const base::DictionaryValue& value); 103 void CompleteResponse(const base::DictionaryValue& value);
105 104
106 void SendRequest(const std::string& action); 105 void SendRequest(const std::string& action);
107 106
108 std::string user_; 107 std::string user_;
109 std::string current_action_; 108 std::string current_action_;
110 scoped_ptr<PrivetURLFetcher> url_fetcher_; 109 scoped_ptr<PrivetURLFetcher> url_fetcher_;
111 PrivetRegisterOperation::Delegate* delegate_; 110 PrivetRegisterOperation::Delegate* delegate_;
112 PrivetHTTPClientImpl* privet_client_; 111 PrivetHTTPClient* privet_client_;
113 ResponseHandler next_response_handler_; 112 ResponseHandler next_response_handler_;
114 // Required to ensure destroying completed register operations doesn't cause 113 // Required to ensure destroying completed register operations doesn't cause
115 // extraneous cancelations. 114 // extraneous cancelations.
116 bool ongoing_; 115 bool ongoing_;
117 116
118 scoped_ptr<PrivetJSONOperation> info_operation_; 117 scoped_ptr<PrivetJSONOperation> info_operation_;
119 std::string expected_id_; 118 std::string expected_id_;
120 }; 119 };
121 120
122 class PrivetJSONOperationImpl : public PrivetJSONOperation, 121 class PrivetJSONOperationImpl : public PrivetJSONOperation,
123 public PrivetURLFetcher::Delegate { 122 public PrivetURLFetcher::Delegate {
124 public: 123 public:
125 PrivetJSONOperationImpl( 124 PrivetJSONOperationImpl(PrivetHTTPClient* privet_client,
126 PrivetHTTPClientImpl* privet_client, 125 const std::string& path,
127 const std::string& path, 126 const std::string& query_params,
128 const std::string& query_params, 127 const PrivetJSONOperation::ResultCallback& callback);
129 const PrivetJSONOperation::ResultCallback& callback);
130 virtual ~PrivetJSONOperationImpl(); 128 virtual ~PrivetJSONOperationImpl();
131 virtual void Start() OVERRIDE; 129 virtual void Start() OVERRIDE;
132 130
133 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE; 131 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE;
134 132
135 virtual void OnError(PrivetURLFetcher* fetcher, 133 virtual void OnError(PrivetURLFetcher* fetcher,
136 PrivetURLFetcher::ErrorType error) OVERRIDE; 134 PrivetURLFetcher::ErrorType error) OVERRIDE;
137 virtual void OnParsedJson(PrivetURLFetcher* fetcher, 135 virtual void OnParsedJson(PrivetURLFetcher* fetcher,
138 const base::DictionaryValue* value, 136 const base::DictionaryValue* value,
139 bool has_error) OVERRIDE; 137 bool has_error) OVERRIDE;
140 virtual void OnNeedPrivetToken( 138 virtual void OnNeedPrivetToken(
141 PrivetURLFetcher* fetcher, 139 PrivetURLFetcher* fetcher,
142 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE; 140 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE;
143 141
144 private: 142 private:
145 PrivetHTTPClientImpl* privet_client_; 143 PrivetHTTPClient* privet_client_;
146 std::string path_; 144 std::string path_;
147 std::string query_params_; 145 std::string query_params_;
148 PrivetJSONOperation::ResultCallback callback_; 146 PrivetJSONOperation::ResultCallback callback_;
149 147
150 scoped_ptr<PrivetURLFetcher> url_fetcher_; 148 scoped_ptr<PrivetURLFetcher> url_fetcher_;
151 }; 149 };
152 150
153 class PrivetDataReadOperationImpl : public PrivetDataReadOperation, 151 class PrivetDataReadOperationImpl : public PrivetDataReadOperation,
154 public PrivetURLFetcher::Delegate { 152 public PrivetURLFetcher::Delegate {
155 public: 153 public:
156 PrivetDataReadOperationImpl( 154 PrivetDataReadOperationImpl(
157 PrivetHTTPClientImpl* privet_client, 155 PrivetHTTPClient* privet_client,
158 const std::string& path, 156 const std::string& path,
159 const std::string& query_params, 157 const std::string& query_params,
160 const PrivetDataReadOperation::ResultCallback& callback); 158 const PrivetDataReadOperation::ResultCallback& callback);
161 virtual ~PrivetDataReadOperationImpl(); 159 virtual ~PrivetDataReadOperationImpl();
162 160
163 virtual void Start() OVERRIDE; 161 virtual void Start() OVERRIDE;
164 162
165 virtual void SetDataRange(int range_start, int range_end) OVERRIDE; 163 virtual void SetDataRange(int range_start, int range_end) OVERRIDE;
166 164
167 virtual void SaveDataToFile() OVERRIDE; 165 virtual void SaveDataToFile() OVERRIDE;
168 166
169 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE; 167 virtual PrivetHTTPClient* GetHTTPClient() OVERRIDE;
170 168
171 virtual void OnError(PrivetURLFetcher* fetcher, 169 virtual void OnError(PrivetURLFetcher* fetcher,
172 PrivetURLFetcher::ErrorType error) OVERRIDE; 170 PrivetURLFetcher::ErrorType error) OVERRIDE;
173 virtual void OnParsedJson(PrivetURLFetcher* fetcher, 171 virtual void OnParsedJson(PrivetURLFetcher* fetcher,
174 const base::DictionaryValue* value, 172 const base::DictionaryValue* value,
175 bool has_error) OVERRIDE; 173 bool has_error) OVERRIDE;
176 virtual void OnNeedPrivetToken( 174 virtual void OnNeedPrivetToken(
177 PrivetURLFetcher* fetcher, 175 PrivetURLFetcher* fetcher,
178 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE; 176 const PrivetURLFetcher::TokenCallback& callback) OVERRIDE;
179 virtual bool OnRawData(PrivetURLFetcher* fetcher, 177 virtual bool OnRawData(PrivetURLFetcher* fetcher,
180 bool is_file, 178 bool is_file,
181 const std::string& data_str, 179 const std::string& data_str,
182 const base::FilePath& file_path) OVERRIDE; 180 const base::FilePath& file_path) OVERRIDE;
183 181
184 private: 182 private:
185 PrivetHTTPClientImpl* privet_client_; 183 PrivetHTTPClient* privet_client_;
186 std::string path_; 184 std::string path_;
187 std::string query_params_; 185 std::string query_params_;
188 int range_start_; 186 int range_start_;
189 int range_end_; 187 int range_end_;
190 PrivetDataReadOperation::ResultCallback callback_; 188 PrivetDataReadOperation::ResultCallback callback_;
191 189
192 bool has_range_; 190 bool has_range_;
193 bool save_to_file_; 191 bool save_to_file_;
194 192
195 scoped_ptr<PrivetURLFetcher> url_fetcher_; 193 scoped_ptr<PrivetURLFetcher> url_fetcher_;
196 }; 194 };
197 195
198 class PrivetLocalPrintOperationImpl 196 class PrivetLocalPrintOperationImpl
199 : public PrivetLocalPrintOperation, 197 : public PrivetLocalPrintOperation,
200 public PrivetURLFetcher::Delegate { 198 public PrivetURLFetcher::Delegate {
201 public: 199 public:
202 PrivetLocalPrintOperationImpl( 200 PrivetLocalPrintOperationImpl(PrivetHTTPClient* privet_client,
203 PrivetHTTPClientImpl* privet_client, 201 PrivetLocalPrintOperation::Delegate* delegate);
204 PrivetLocalPrintOperation::Delegate* delegate);
205 202
206 virtual ~PrivetLocalPrintOperationImpl(); 203 virtual ~PrivetLocalPrintOperationImpl();
207 virtual void Start() OVERRIDE; 204 virtual void Start() OVERRIDE;
208 205
209 virtual void SetData(base::RefCountedBytes* data) OVERRIDE; 206 virtual void SetData(base::RefCountedBytes* data) OVERRIDE;
210 207
211 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 208 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
212 209
213 virtual void SetTicket(const std::string& ticket) OVERRIDE; 210 virtual void SetTicket(const std::string& ticket) OVERRIDE;
214 211
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void StartPrinting(); 243 void StartPrinting();
247 244
248 void OnPrivetInfoDone(const base::DictionaryValue* value); 245 void OnPrivetInfoDone(const base::DictionaryValue* value);
249 void OnSubmitdocResponse(bool has_error, 246 void OnSubmitdocResponse(bool has_error,
250 const base::DictionaryValue* value); 247 const base::DictionaryValue* value);
251 void OnCreatejobResponse(bool has_error, 248 void OnCreatejobResponse(bool has_error,
252 const base::DictionaryValue* value); 249 const base::DictionaryValue* value);
253 void OnPWGRasterConverted(bool success, const base::FilePath& pwg_file_path); 250 void OnPWGRasterConverted(bool success, const base::FilePath& pwg_file_path);
254 void FillPwgRasterSettings(printing::PwgRasterSettings* transfrom_settings); 251 void FillPwgRasterSettings(printing::PwgRasterSettings* transfrom_settings);
255 252
256 PrivetHTTPClientImpl* privet_client_; 253 PrivetHTTPClient* privet_client_;
257 PrivetLocalPrintOperation::Delegate* delegate_; 254 PrivetLocalPrintOperation::Delegate* delegate_;
258 255
259 ResponseCallback current_response_; 256 ResponseCallback current_response_;
260 257
261 cloud_devices::CloudDeviceDescription ticket_; 258 cloud_devices::CloudDeviceDescription ticket_;
262 cloud_devices::CloudDeviceDescription capabilities_; 259 cloud_devices::CloudDeviceDescription capabilities_;
263 260
264 scoped_refptr<base::RefCountedBytes> data_; 261 scoped_refptr<base::RefCountedBytes> data_;
265 base::FilePath pwg_file_path_; 262 base::FilePath pwg_file_path_;
266 263
(...skipping 19 matching lines...) Expand all
286 }; 283 };
287 284
288 class PrivetHTTPClientImpl : public PrivetHTTPClient { 285 class PrivetHTTPClientImpl : public PrivetHTTPClient {
289 public: 286 public:
290 PrivetHTTPClientImpl( 287 PrivetHTTPClientImpl(
291 const std::string& name, 288 const std::string& name,
292 const net::HostPortPair& host_port, 289 const net::HostPortPair& host_port,
293 net::URLRequestContextGetter* request_context); 290 net::URLRequestContextGetter* request_context);
294 virtual ~PrivetHTTPClientImpl(); 291 virtual ~PrivetHTTPClientImpl();
295 292
296 virtual scoped_ptr<PrivetRegisterOperation> CreateRegisterOperation( 293 // PrivetHTTPClient implementation.
297 const std::string& user, 294 virtual const std::string& GetName() OVERRIDE;
298 PrivetRegisterOperation::Delegate* delegate) OVERRIDE;
299
300 virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation( 295 virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
301 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE; 296 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
302 297 virtual scoped_ptr<PrivetURLFetcher> CreateURLFetcher(
303 virtual scoped_ptr<PrivetJSONOperation> CreateCapabilitiesOperation(
304 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
305
306 virtual scoped_ptr<PrivetLocalPrintOperation> CreateLocalPrintOperation(
307 PrivetLocalPrintOperation::Delegate* delegate) OVERRIDE;
308
309 virtual scoped_ptr<PrivetJSONOperation> CreateStorageListOperation(
310 const std::string& path,
311 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
312
313 virtual scoped_ptr<PrivetDataReadOperation> CreateStorageReadOperation(
314 const std::string& path,
315 const PrivetDataReadOperation::ResultCallback& callback) OVERRIDE;
316
317 virtual const std::string& GetName() OVERRIDE;
318
319 scoped_ptr<PrivetURLFetcher> CreateURLFetcher(
320 const GURL& url, 298 const GURL& url,
321 net::URLFetcher::RequestType request_type, 299 net::URLFetcher::RequestType request_type,
322 PrivetURLFetcher::Delegate* delegate) const; 300 PrivetURLFetcher::Delegate* delegate) OVERRIDE;
323 301 virtual void RefreshPrivetToken(
324 void RefreshPrivetToken( 302 const PrivetURLFetcher::TokenCallback& token_callback) OVERRIDE;
325 const PrivetURLFetcher::TokenCallback& token_callback);
326 303
327 private: 304 private:
328 typedef std::vector<PrivetURLFetcher::TokenCallback> TokenCallbackVector; 305 typedef std::vector<PrivetURLFetcher::TokenCallback> TokenCallbackVector;
329 306
330 void OnPrivetInfoDone(const base::DictionaryValue* value); 307 void OnPrivetInfoDone(const base::DictionaryValue* value);
331 308
332 std::string name_; 309 std::string name_;
333 scoped_refptr<net::URLRequestContextGetter> request_context_; 310 scoped_refptr<net::URLRequestContextGetter> request_context_;
334 net::HostPortPair host_port_; 311 net::HostPortPair host_port_;
335 312
336 scoped_ptr<PrivetJSONOperation> info_operation_; 313 scoped_ptr<PrivetJSONOperation> info_operation_;
337 TokenCallbackVector token_callbacks_; 314 TokenCallbackVector token_callbacks_;
315
316 DISALLOW_COPY_AND_ASSIGN(PrivetHTTPClientImpl);
317 };
318
319 class PrivetV1HTTPClientImpl : public PrivetV1HTTPClient {
320 public:
321 explicit PrivetV1HTTPClientImpl(scoped_ptr<PrivetHTTPClient> info_client);
322 virtual ~PrivetV1HTTPClientImpl();
323
324 virtual const std::string& GetName() OVERRIDE;
325 virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
326 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
327 virtual scoped_ptr<PrivetRegisterOperation> CreateRegisterOperation(
328 const std::string& user,
329 PrivetRegisterOperation::Delegate* delegate) OVERRIDE;
330 virtual scoped_ptr<PrivetJSONOperation> CreateCapabilitiesOperation(
331 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
332 virtual scoped_ptr<PrivetLocalPrintOperation> CreateLocalPrintOperation(
333 PrivetLocalPrintOperation::Delegate* delegate) OVERRIDE;
334 virtual scoped_ptr<PrivetJSONOperation> CreateStorageListOperation(
335 const std::string& path,
336 const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
337 virtual scoped_ptr<PrivetDataReadOperation> CreateStorageReadOperation(
338 const std::string& path,
339 const PrivetDataReadOperation::ResultCallback& callback) OVERRIDE;
340
341 private:
342 PrivetHTTPClient* info_client() { return info_client_.get(); }
343
344 scoped_ptr<PrivetHTTPClient> info_client_;
345
346 DISALLOW_COPY_AND_ASSIGN(PrivetV1HTTPClientImpl);
338 }; 347 };
339 348
340 } // namespace local_discovery 349 } // namespace local_discovery
341 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ 350 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698