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

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

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 #include "chrome/browser/local_discovery/privet_http_impl.h" 5 #include "chrome/browser/local_discovery/privet_http_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 replacements.SetPathStr(path); 80 replacements.SetPathStr(path);
81 if (!query_params.empty()) { 81 if (!query_params.empty()) {
82 replacements.SetQueryStr(query_params); 82 replacements.SetQueryStr(query_params);
83 } 83 }
84 return url.ReplaceComponents(replacements); 84 return url.ReplaceComponents(replacements);
85 } 85 }
86 86
87 } // namespace 87 } // namespace
88 88
89 PrivetInfoOperationImpl::PrivetInfoOperationImpl( 89 PrivetInfoOperationImpl::PrivetInfoOperationImpl(
90 PrivetHTTPClientImpl* privet_client, 90 PrivetHTTPClient* privet_client,
91 const PrivetJSONOperation::ResultCallback& callback) 91 const PrivetJSONOperation::ResultCallback& callback)
92 : privet_client_(privet_client), callback_(callback) { 92 : privet_client_(privet_client), callback_(callback) {
93 } 93 }
94 94
95 PrivetInfoOperationImpl::~PrivetInfoOperationImpl() { 95 PrivetInfoOperationImpl::~PrivetInfoOperationImpl() {
96 } 96 }
97 97
98 void PrivetInfoOperationImpl::Start() { 98 void PrivetInfoOperationImpl::Start() {
99 url_fetcher_ = privet_client_->CreateURLFetcher( 99 url_fetcher_ = privet_client_->CreateURLFetcher(
100 CreatePrivetURL(kPrivetInfoPath), net::URLFetcher::GET, this); 100 CreatePrivetURL(kPrivetInfoPath), net::URLFetcher::GET, this);
(...skipping 13 matching lines...) Expand all
114 callback_.Run(NULL); 114 callback_.Run(NULL);
115 } 115 }
116 116
117 void PrivetInfoOperationImpl::OnParsedJson(PrivetURLFetcher* fetcher, 117 void PrivetInfoOperationImpl::OnParsedJson(PrivetURLFetcher* fetcher,
118 const base::DictionaryValue* value, 118 const base::DictionaryValue* value,
119 bool has_error) { 119 bool has_error) {
120 callback_.Run(value); 120 callback_.Run(value);
121 } 121 }
122 122
123 PrivetRegisterOperationImpl::PrivetRegisterOperationImpl( 123 PrivetRegisterOperationImpl::PrivetRegisterOperationImpl(
124 PrivetHTTPClientImpl* privet_client, 124 PrivetHTTPClient* privet_client,
125 const std::string& user, 125 const std::string& user,
126 PrivetRegisterOperation::Delegate* delegate) 126 PrivetRegisterOperation::Delegate* delegate)
127 : user_(user), delegate_(delegate), privet_client_(privet_client), 127 : user_(user),
128 delegate_(delegate),
129 privet_client_(privet_client),
128 ongoing_(false) { 130 ongoing_(false) {
129 } 131 }
130 132
131 PrivetRegisterOperationImpl::~PrivetRegisterOperationImpl() { 133 PrivetRegisterOperationImpl::~PrivetRegisterOperationImpl() {
132 } 134 }
133 135
134 void PrivetRegisterOperationImpl::Start() { 136 void PrivetRegisterOperationImpl::Start() {
135 ongoing_ = true; 137 ongoing_ = true;
136 next_response_handler_ = 138 next_response_handler_ =
137 base::Bind(&PrivetRegisterOperationImpl::StartResponse, 139 base::Bind(&PrivetRegisterOperationImpl::StartResponse,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 309 }
308 310
309 void PrivetRegisterOperationImpl::StartInfoOperation() { 311 void PrivetRegisterOperationImpl::StartInfoOperation() {
310 info_operation_ = privet_client_->CreateInfoOperation( 312 info_operation_ = privet_client_->CreateInfoOperation(
311 base::Bind(&PrivetRegisterOperationImpl::OnPrivetInfoDone, 313 base::Bind(&PrivetRegisterOperationImpl::OnPrivetInfoDone,
312 base::Unretained(this))); 314 base::Unretained(this)));
313 info_operation_->Start(); 315 info_operation_->Start();
314 } 316 }
315 317
316 PrivetRegisterOperationImpl::Cancelation::Cancelation( 318 PrivetRegisterOperationImpl::Cancelation::Cancelation(
317 PrivetHTTPClientImpl* privet_client, 319 PrivetHTTPClient* privet_client,
318 const std::string& user) { 320 const std::string& user) {
319 url_fetcher_ = 321 url_fetcher_ =
320 privet_client->CreateURLFetcher( 322 privet_client->CreateURLFetcher(
321 CreatePrivetRegisterURL(kPrivetActionCancel, user), 323 CreatePrivetRegisterURL(kPrivetActionCancel, user),
322 net::URLFetcher::POST, this); 324 net::URLFetcher::POST, this);
323 url_fetcher_->DoNotRetryOnTransientError(); 325 url_fetcher_->DoNotRetryOnTransientError();
324 url_fetcher_->Start(); 326 url_fetcher_->Start();
325 } 327 }
326 328
327 PrivetRegisterOperationImpl::Cancelation::~Cancelation() { 329 PrivetRegisterOperationImpl::Cancelation::~Cancelation() {
(...skipping 10 matching lines...) Expand all
338 bool has_error) { 340 bool has_error) {
339 } 341 }
340 342
341 void PrivetRegisterOperationImpl::Cancelation::Cleanup() { 343 void PrivetRegisterOperationImpl::Cancelation::Cleanup() {
342 // Nothing needs to be done, as base::Owned will delete this object, 344 // Nothing needs to be done, as base::Owned will delete this object,
343 // this callback is just here to pass ownership of the Cancelation to 345 // this callback is just here to pass ownership of the Cancelation to
344 // the message loop. 346 // the message loop.
345 } 347 }
346 348
347 PrivetJSONOperationImpl::PrivetJSONOperationImpl( 349 PrivetJSONOperationImpl::PrivetJSONOperationImpl(
348 PrivetHTTPClientImpl* privet_client, 350 PrivetHTTPClient* privet_client,
349 const std::string& path, 351 const std::string& path,
350 const std::string& query_params, 352 const std::string& query_params,
351 const PrivetJSONOperation::ResultCallback& callback) 353 const PrivetJSONOperation::ResultCallback& callback)
352 : privet_client_(privet_client), path_(path), query_params_(query_params), 354 : privet_client_(privet_client),
355 path_(path),
356 query_params_(query_params),
353 callback_(callback) { 357 callback_(callback) {
354 } 358 }
355 359
356 PrivetJSONOperationImpl::~PrivetJSONOperationImpl() { 360 PrivetJSONOperationImpl::~PrivetJSONOperationImpl() {
357 } 361 }
358 362
359 void PrivetJSONOperationImpl::Start() { 363 void PrivetJSONOperationImpl::Start() {
360 url_fetcher_ = privet_client_->CreateURLFetcher( 364 url_fetcher_ = privet_client_->CreateURLFetcher(
361 CreatePrivetParamURL(path_, query_params_), net::URLFetcher::GET, this); 365 CreatePrivetParamURL(path_, query_params_), net::URLFetcher::GET, this);
362 url_fetcher_->DoNotRetryOnTransientError(); 366 url_fetcher_->DoNotRetryOnTransientError();
(...skipping 17 matching lines...) Expand all
380 callback_.Run(value); 384 callback_.Run(value);
381 } 385 }
382 386
383 void PrivetJSONOperationImpl::OnNeedPrivetToken( 387 void PrivetJSONOperationImpl::OnNeedPrivetToken(
384 PrivetURLFetcher* fetcher, 388 PrivetURLFetcher* fetcher,
385 const PrivetURLFetcher::TokenCallback& callback) { 389 const PrivetURLFetcher::TokenCallback& callback) {
386 privet_client_->RefreshPrivetToken(callback); 390 privet_client_->RefreshPrivetToken(callback);
387 } 391 }
388 392
389 PrivetDataReadOperationImpl::PrivetDataReadOperationImpl( 393 PrivetDataReadOperationImpl::PrivetDataReadOperationImpl(
390 PrivetHTTPClientImpl* privet_client, 394 PrivetHTTPClient* privet_client,
391 const std::string& path, 395 const std::string& path,
392 const std::string& query_params, 396 const std::string& query_params,
393 const PrivetDataReadOperation::ResultCallback& callback) 397 const PrivetDataReadOperation::ResultCallback& callback)
394 : privet_client_(privet_client), path_(path), query_params_(query_params), 398 : privet_client_(privet_client),
395 callback_(callback), has_range_(false), save_to_file_(false) { 399 path_(path),
400 query_params_(query_params),
401 callback_(callback),
402 has_range_(false),
403 save_to_file_(false) {
396 } 404 }
397 405
398 PrivetDataReadOperationImpl::~PrivetDataReadOperationImpl() { 406 PrivetDataReadOperationImpl::~PrivetDataReadOperationImpl() {
399 } 407 }
400 408
401 409
402 void PrivetDataReadOperationImpl::Start() { 410 void PrivetDataReadOperationImpl::Start() {
403 url_fetcher_ = privet_client_->CreateURLFetcher( 411 url_fetcher_ = privet_client_->CreateURLFetcher(
404 CreatePrivetParamURL(path_, query_params_), net::URLFetcher::GET, this); 412 CreatePrivetParamURL(path_, query_params_), net::URLFetcher::GET, this);
405 url_fetcher_->DoNotRetryOnTransientError(); 413 url_fetcher_->DoNotRetryOnTransientError();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 bool PrivetDataReadOperationImpl::OnRawData(PrivetURLFetcher* fetcher, 459 bool PrivetDataReadOperationImpl::OnRawData(PrivetURLFetcher* fetcher,
452 bool is_file, 460 bool is_file,
453 const std::string& data_str, 461 const std::string& data_str,
454 const base::FilePath& file_path) { 462 const base::FilePath& file_path) {
455 ResponseType type = (is_file) ? RESPONSE_TYPE_FILE : RESPONSE_TYPE_STRING; 463 ResponseType type = (is_file) ? RESPONSE_TYPE_FILE : RESPONSE_TYPE_STRING;
456 callback_.Run(type, data_str, file_path); 464 callback_.Run(type, data_str, file_path);
457 return true; 465 return true;
458 } 466 }
459 467
460 PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl( 468 PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl(
461 PrivetHTTPClientImpl* privet_client, 469 PrivetHTTPClient* privet_client,
462 PrivetLocalPrintOperation::Delegate* delegate) 470 PrivetLocalPrintOperation::Delegate* delegate)
463 : privet_client_(privet_client), 471 : privet_client_(privet_client),
464 delegate_(delegate), 472 delegate_(delegate),
465 use_pdf_(false), 473 use_pdf_(false),
466 has_extended_workflow_(false), 474 has_extended_workflow_(false),
467 started_(false), 475 started_(false),
468 offline_(false), 476 offline_(false),
469 dpi_(printing::kDefaultPdfDpi), 477 dpi_(printing::kDefaultPdfDpi),
470 invalid_job_retries_(0), 478 invalid_job_retries_(0),
471 weak_factory_(this) { 479 weak_factory_(this) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 826
819 PrivetHTTPClientImpl::PrivetHTTPClientImpl( 827 PrivetHTTPClientImpl::PrivetHTTPClientImpl(
820 const std::string& name, 828 const std::string& name,
821 const net::HostPortPair& host_port, 829 const net::HostPortPair& host_port,
822 net::URLRequestContextGetter* request_context) 830 net::URLRequestContextGetter* request_context)
823 : name_(name), request_context_(request_context), host_port_(host_port) {} 831 : name_(name), request_context_(request_context), host_port_(host_port) {}
824 832
825 PrivetHTTPClientImpl::~PrivetHTTPClientImpl() { 833 PrivetHTTPClientImpl::~PrivetHTTPClientImpl() {
826 } 834 }
827 835
828 scoped_ptr<PrivetRegisterOperation> 836 const std::string& PrivetHTTPClientImpl::GetName() {
829 PrivetHTTPClientImpl::CreateRegisterOperation( 837 return name_;
830 const std::string& user,
831 PrivetRegisterOperation::Delegate* delegate) {
832 return scoped_ptr<PrivetRegisterOperation>(
833 new PrivetRegisterOperationImpl(this, user, delegate));
834 } 838 }
835 839
836 scoped_ptr<PrivetJSONOperation> PrivetHTTPClientImpl::CreateInfoOperation( 840 scoped_ptr<PrivetJSONOperation> PrivetHTTPClientImpl::CreateInfoOperation(
837 const PrivetJSONOperation::ResultCallback& callback) { 841 const PrivetJSONOperation::ResultCallback& callback) {
838 return scoped_ptr<PrivetJSONOperation>( 842 return scoped_ptr<PrivetJSONOperation>(
839 new PrivetInfoOperationImpl(this, callback)); 843 new PrivetInfoOperationImpl(this, callback));
840 } 844 }
841 845
842 scoped_ptr<PrivetJSONOperation>
843 PrivetHTTPClientImpl::CreateCapabilitiesOperation(
844 const PrivetJSONOperation::ResultCallback& callback) {
845 return scoped_ptr<PrivetJSONOperation>(
846 new PrivetJSONOperationImpl(this, kPrivetCapabilitiesPath, "", callback));
847 }
848
849 scoped_ptr<PrivetLocalPrintOperation>
850 PrivetHTTPClientImpl::CreateLocalPrintOperation(
851 PrivetLocalPrintOperation::Delegate* delegate) {
852 return scoped_ptr<PrivetLocalPrintOperation>(
853 new PrivetLocalPrintOperationImpl(this, delegate));
854 }
855
856 scoped_ptr<PrivetJSONOperation>
857 PrivetHTTPClientImpl::CreateStorageListOperation(
858 const std::string& path,
859 const PrivetJSONOperation::ResultCallback& callback) {
860 std::string url_param = base::StringPrintf(kPrivetStorageParamPathFormat,
861 path.c_str());
862 return scoped_ptr<PrivetJSONOperation>(
863 new PrivetJSONOperationImpl(this, kPrivetStorageListPath, url_param,
864 callback));
865 }
866
867
868 scoped_ptr<PrivetDataReadOperation>
869 PrivetHTTPClientImpl::CreateStorageReadOperation(
870 const std::string& path,
871 const PrivetDataReadOperation::ResultCallback& callback) {
872 std::string url_param = base::StringPrintf(kPrivetStorageParamPathFormat,
873 path.c_str());
874 return scoped_ptr<PrivetDataReadOperation>(
875 new PrivetDataReadOperationImpl(this, kPrivetStorageContentPath,
876 url_param, callback));
877 }
878
879 const std::string& PrivetHTTPClientImpl::GetName() {
880 return name_;
881 }
882
883 scoped_ptr<PrivetURLFetcher> PrivetHTTPClientImpl::CreateURLFetcher( 846 scoped_ptr<PrivetURLFetcher> PrivetHTTPClientImpl::CreateURLFetcher(
884 const GURL& url, net::URLFetcher::RequestType request_type, 847 const GURL& url,
885 PrivetURLFetcher::Delegate* delegate) const { 848 net::URLFetcher::RequestType request_type,
849 PrivetURLFetcher::Delegate* delegate) {
886 GURL::Replacements replacements; 850 GURL::Replacements replacements;
887 replacements.SetHostStr(host_port_.host()); 851 replacements.SetHostStr(host_port_.host());
888 std::string port(base::IntToString(host_port_.port())); // Keep string alive. 852 std::string port(base::IntToString(host_port_.port())); // Keep string alive.
889 replacements.SetPortStr(port); 853 replacements.SetPortStr(port);
890 return scoped_ptr<PrivetURLFetcher>( 854 return scoped_ptr<PrivetURLFetcher>(
891 new PrivetURLFetcher(url.ReplaceComponents(replacements), 855 new PrivetURLFetcher(url.ReplaceComponents(replacements),
892 request_type, 856 request_type,
893 request_context_.get(), 857 request_context_.get(),
894 delegate)); 858 delegate));
895 } 859 }
(...skipping 23 matching lines...) Expand all
919 883
920 TokenCallbackVector token_callbacks; 884 TokenCallbackVector token_callbacks;
921 token_callbacks_.swap(token_callbacks); 885 token_callbacks_.swap(token_callbacks);
922 886
923 for (TokenCallbackVector::iterator i = token_callbacks.begin(); 887 for (TokenCallbackVector::iterator i = token_callbacks.begin();
924 i != token_callbacks.end(); i++) { 888 i != token_callbacks.end(); i++) {
925 i->Run(token); 889 i->Run(token);
926 } 890 }
927 } 891 }
928 892
893 PrivetV1HTTPClientImpl::PrivetV1HTTPClientImpl(
894 scoped_ptr<PrivetHTTPClient> info_client)
895 : info_client_(info_client.Pass()) {
896 }
897
898 PrivetV1HTTPClientImpl::~PrivetV1HTTPClientImpl() {
899 }
900
901 const std::string& PrivetV1HTTPClientImpl::GetName() {
902 return info_client()->GetName();
903 }
904
905 scoped_ptr<PrivetJSONOperation> PrivetV1HTTPClientImpl::CreateInfoOperation(
906 const PrivetJSONOperation::ResultCallback& callback) {
907 return info_client()->CreateInfoOperation(callback);
908 }
909
910 scoped_ptr<PrivetRegisterOperation>
911 PrivetV1HTTPClientImpl::CreateRegisterOperation(
912 const std::string& user,
913 PrivetRegisterOperation::Delegate* delegate) {
914 return scoped_ptr<PrivetRegisterOperation>(
915 new PrivetRegisterOperationImpl(info_client(), user, delegate));
916 }
917
918 scoped_ptr<PrivetJSONOperation>
919 PrivetV1HTTPClientImpl::CreateCapabilitiesOperation(
920 const PrivetJSONOperation::ResultCallback& callback) {
921 return scoped_ptr<PrivetJSONOperation>(new PrivetJSONOperationImpl(
922 info_client(), kPrivetCapabilitiesPath, "", callback));
923 }
924
925 scoped_ptr<PrivetLocalPrintOperation>
926 PrivetV1HTTPClientImpl::CreateLocalPrintOperation(
927 PrivetLocalPrintOperation::Delegate* delegate) {
928 return scoped_ptr<PrivetLocalPrintOperation>(
929 new PrivetLocalPrintOperationImpl(info_client(), delegate));
930 }
931
932 scoped_ptr<PrivetJSONOperation>
933 PrivetV1HTTPClientImpl::CreateStorageListOperation(
934 const std::string& path,
935 const PrivetJSONOperation::ResultCallback& callback) {
936 std::string url_param =
937 base::StringPrintf(kPrivetStorageParamPathFormat, path.c_str());
938 return scoped_ptr<PrivetJSONOperation>(new PrivetJSONOperationImpl(
939 info_client(), kPrivetStorageListPath, url_param, callback));
940 }
941
942 scoped_ptr<PrivetDataReadOperation>
943 PrivetV1HTTPClientImpl::CreateStorageReadOperation(
944 const std::string& path,
945 const PrivetDataReadOperation::ResultCallback& callback) {
946 std::string url_param =
947 base::StringPrintf(kPrivetStorageParamPathFormat, path.c_str());
948 return scoped_ptr<PrivetDataReadOperation>(new PrivetDataReadOperationImpl(
949 info_client(), kPrivetStorageContentPath, url_param, callback));
950 }
951
929 } // namespace local_discovery 952 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.h ('k') | chrome/browser/local_discovery/privet_http_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698