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

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

Issue 166373006: Use persistent map of privet tokens for PrivetURLFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 void PrivetInfoOperationImpl::OnError(PrivetURLFetcher* fetcher, 102 void PrivetInfoOperationImpl::OnError(PrivetURLFetcher* fetcher,
103 PrivetURLFetcher::ErrorType error) { 103 PrivetURLFetcher::ErrorType error) {
104 callback_.Run(NULL); 104 callback_.Run(NULL);
105 } 105 }
106 106
107 void PrivetInfoOperationImpl::OnParsedJson(PrivetURLFetcher* fetcher, 107 void PrivetInfoOperationImpl::OnParsedJson(PrivetURLFetcher* fetcher,
108 const base::DictionaryValue* value, 108 const base::DictionaryValue* value,
109 bool has_error) { 109 bool has_error) {
110 if (!has_error)
111 privet_client_->CacheInfo(value);
112 callback_.Run(value); 110 callback_.Run(value);
113 } 111 }
114 112
115 PrivetRegisterOperationImpl::PrivetRegisterOperationImpl( 113 PrivetRegisterOperationImpl::PrivetRegisterOperationImpl(
116 PrivetHTTPClientImpl* privet_client, 114 PrivetHTTPClientImpl* privet_client,
117 const std::string& user, 115 const std::string& user,
118 PrivetRegisterOperation::Delegate* delegate) 116 PrivetRegisterOperation::Delegate* delegate)
119 : user_(user), delegate_(delegate), privet_client_(privet_client), 117 : user_(user), delegate_(delegate), privet_client_(privet_client),
120 ongoing_(false) { 118 ongoing_(false) {
121 } 119 }
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 778
781 void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting( 779 void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting(
782 scoped_ptr<PWGRasterConverter> pwg_raster_converter) { 780 scoped_ptr<PWGRasterConverter> pwg_raster_converter) {
783 pwg_raster_converter_ = pwg_raster_converter.Pass(); 781 pwg_raster_converter_ = pwg_raster_converter.Pass();
784 } 782 }
785 783
786 PrivetHTTPClientImpl::PrivetHTTPClientImpl( 784 PrivetHTTPClientImpl::PrivetHTTPClientImpl(
787 const std::string& name, 785 const std::string& name,
788 const net::HostPortPair& host_port, 786 const net::HostPortPair& host_port,
789 net::URLRequestContextGetter* request_context) 787 net::URLRequestContextGetter* request_context)
790 : name_(name), 788 : name_(name), request_context_(request_context), host_port_(host_port) {}
791 fetcher_factory_(request_context),
792 host_port_(host_port) {
793 }
794 789
795 PrivetHTTPClientImpl::~PrivetHTTPClientImpl() { 790 PrivetHTTPClientImpl::~PrivetHTTPClientImpl() {
796 } 791 }
797 792
798 const base::DictionaryValue* PrivetHTTPClientImpl::GetCachedInfo() const {
799 return cached_info_.get();
800 }
801
802 scoped_ptr<PrivetRegisterOperation> 793 scoped_ptr<PrivetRegisterOperation>
803 PrivetHTTPClientImpl::CreateRegisterOperation( 794 PrivetHTTPClientImpl::CreateRegisterOperation(
804 const std::string& user, 795 const std::string& user,
805 PrivetRegisterOperation::Delegate* delegate) { 796 PrivetRegisterOperation::Delegate* delegate) {
806 return scoped_ptr<PrivetRegisterOperation>( 797 return scoped_ptr<PrivetRegisterOperation>(
807 new PrivetRegisterOperationImpl(this, user, delegate)); 798 new PrivetRegisterOperationImpl(this, user, delegate));
808 } 799 }
809 800
810 scoped_ptr<PrivetJSONOperation> PrivetHTTPClientImpl::CreateInfoOperation( 801 scoped_ptr<PrivetJSONOperation> PrivetHTTPClientImpl::CreateInfoOperation(
811 const PrivetJSONOperation::ResultCallback& callback) { 802 const PrivetJSONOperation::ResultCallback& callback) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 return name_; 845 return name_;
855 } 846 }
856 847
857 scoped_ptr<PrivetURLFetcher> PrivetHTTPClientImpl::CreateURLFetcher( 848 scoped_ptr<PrivetURLFetcher> PrivetHTTPClientImpl::CreateURLFetcher(
858 const GURL& url, net::URLFetcher::RequestType request_type, 849 const GURL& url, net::URLFetcher::RequestType request_type,
859 PrivetURLFetcher::Delegate* delegate) const { 850 PrivetURLFetcher::Delegate* delegate) const {
860 GURL::Replacements replacements; 851 GURL::Replacements replacements;
861 replacements.SetHostStr(host_port_.host()); 852 replacements.SetHostStr(host_port_.host());
862 std::string port(base::IntToString(host_port_.port())); // Keep string alive. 853 std::string port(base::IntToString(host_port_.port())); // Keep string alive.
863 replacements.SetPortStr(port); 854 replacements.SetPortStr(port);
864 return fetcher_factory_.CreateURLFetcher(url.ReplaceComponents(replacements), 855 return scoped_ptr<PrivetURLFetcher>(
865 request_type, delegate); 856 new PrivetURLFetcher(url.ReplaceComponents(replacements),
857 request_type,
858 request_context_.get(),
859 delegate));
866 } 860 }
867 861
868 void PrivetHTTPClientImpl::CacheInfo(const base::DictionaryValue* cached_info) {
869 cached_info_.reset(cached_info->DeepCopy());
870 std::string token;
871 if (cached_info_->GetString(kPrivetInfoKeyToken, &token)) {
872 fetcher_factory_.set_token(token);
873 }
874 }
875
876 bool PrivetHTTPClientImpl::HasToken() const {
877 return fetcher_factory_.get_token() != "";
878 };
879
880 void PrivetHTTPClientImpl::RefreshPrivetToken( 862 void PrivetHTTPClientImpl::RefreshPrivetToken(
881 const PrivetURLFetcher::TokenCallback& callback) { 863 const PrivetURLFetcher::TokenCallback& callback) {
882 token_callbacks_.push_back(callback); 864 token_callbacks_.push_back(callback);
883 865
884 if (!info_operation_) { 866 if (!info_operation_) {
885 info_operation_ = CreateInfoOperation( 867 info_operation_ = CreateInfoOperation(
886 base::Bind(&PrivetHTTPClientImpl::OnPrivetInfoDone, 868 base::Bind(&PrivetHTTPClientImpl::OnPrivetInfoDone,
887 base::Unretained(this))); 869 base::Unretained(this)));
888 info_operation_->Start(); 870 info_operation_->Start();
889 } 871 }
(...skipping 13 matching lines...) Expand all
903 TokenCallbackVector token_callbacks; 885 TokenCallbackVector token_callbacks;
904 token_callbacks_.swap(token_callbacks); 886 token_callbacks_.swap(token_callbacks);
905 887
906 for (TokenCallbackVector::iterator i = token_callbacks.begin(); 888 for (TokenCallbackVector::iterator i = token_callbacks.begin();
907 i != token_callbacks.end(); i++) { 889 i != token_callbacks.end(); i++) {
908 i->Run(token); 890 i->Run(token);
909 } 891 }
910 } 892 }
911 893
912 } // namespace local_discovery 894 } // 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