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

Side by Side Diff: remoting/host/host_port_allocator.cc

Issue 10637008: Remove UrlFetcher from remoting and use the one in net instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use enum instead of bool to distinguish fetchers. Created 8 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
« no previous file with comments | « remoting/host/host_port_allocator.h ('k') | remoting/host/url_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "remoting/host/host_port_allocator.h" 5 #include "remoting/host/host_port_allocator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "net/http/http_status_code.h" 11 #include "net/http/http_status_code.h"
12 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_fetcher_delegate.h"
12 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
13 #include "remoting/host/network_settings.h" 15 #include "remoting/host/network_settings.h"
14 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" 16 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h"
15 17
16 namespace remoting { 18 namespace remoting {
17 19
18 namespace { 20 namespace {
19 21
20 class HostPortAllocatorSession 22 class HostPortAllocatorSession
21 : public cricket::HttpPortAllocatorSessionBase { 23 : public cricket::HttpPortAllocatorSessionBase,
24 public net::URLFetcherDelegate {
22 public: 25 public:
23 HostPortAllocatorSession( 26 HostPortAllocatorSession(
24 cricket::HttpPortAllocatorBase* allocator, 27 cricket::HttpPortAllocatorBase* allocator,
25 int component, 28 int component,
26 const std::string& ice_username_fragment, 29 const std::string& ice_username_fragment,
27 const std::string& ice_password, 30 const std::string& ice_password,
28 const std::vector<talk_base::SocketAddress>& stun_hosts, 31 const std::vector<talk_base::SocketAddress>& stun_hosts,
29 const std::vector<std::string>& relay_hosts, 32 const std::vector<std::string>& relay_hosts,
30 const std::string& relay, 33 const std::string& relay,
31 const scoped_refptr<net::URLRequestContextGetter>& url_context); 34 const scoped_refptr<net::URLRequestContextGetter>& url_context);
32 virtual ~HostPortAllocatorSession(); 35 virtual ~HostPortAllocatorSession();
33 36
34 // cricket::HttpPortAllocatorBase overrides. 37 // cricket::HttpPortAllocatorBase overrides.
35 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; 38 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE;
36 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; 39 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE;
37 40
41 // net::URLFetcherDelegate interface.
42 virtual void OnURLFetchComplete(const net::URLFetcher* url_fetcher) OVERRIDE;
43
38 private: 44 private:
39 void OnSessionRequestDone(UrlFetcher* url_fetcher,
40 const net::URLRequestStatus& status,
41 int response_code,
42 const std::string& response);
43
44 scoped_refptr<net::URLRequestContextGetter> url_context_; 45 scoped_refptr<net::URLRequestContextGetter> url_context_;
45 std::set<UrlFetcher*> url_fetchers_; 46 std::set<const net::URLFetcher*> url_fetchers_;
46 47
47 DISALLOW_COPY_AND_ASSIGN(HostPortAllocatorSession); 48 DISALLOW_COPY_AND_ASSIGN(HostPortAllocatorSession);
48 }; 49 };
49 50
50 HostPortAllocatorSession::HostPortAllocatorSession( 51 HostPortAllocatorSession::HostPortAllocatorSession(
51 cricket::HttpPortAllocatorBase* allocator, 52 cricket::HttpPortAllocatorBase* allocator,
52 int component, 53 int component,
53 const std::string& ice_username_fragment, 54 const std::string& ice_username_fragment,
54 const std::string& ice_password, 55 const std::string& ice_password,
55 const std::vector<talk_base::SocketAddress>& stun_hosts, 56 const std::vector<talk_base::SocketAddress>& stun_hosts,
(...skipping 23 matching lines...) Expand all
79 } 80 }
80 relay->ports = filtered_ports; 81 relay->ports = filtered_ports;
81 } 82 }
82 cricket::BasicPortAllocatorSession::ConfigReady(config); 83 cricket::BasicPortAllocatorSession::ConfigReady(config);
83 } 84 }
84 85
85 void HostPortAllocatorSession::SendSessionRequest(const std::string& host, 86 void HostPortAllocatorSession::SendSessionRequest(const std::string& host,
86 int port) { 87 int port) {
87 GURL url("https://" + host + ":" + base::IntToString(port) + 88 GURL url("https://" + host + ":" + base::IntToString(port) +
88 GetSessionRequestUrl() + "&sn=1"); 89 GetSessionRequestUrl() + "&sn=1");
89 scoped_ptr<UrlFetcher> url_fetcher(new UrlFetcher(url, UrlFetcher::GET)); 90 scoped_ptr<net::URLFetcher> url_fetcher(
91 net::URLFetcher::Create(url, net::URLFetcher::GET, this));
90 url_fetcher->SetRequestContext(url_context_); 92 url_fetcher->SetRequestContext(url_context_);
91 url_fetcher->SetHeader("X-Talk-Google-Relay-Auth", relay_token()); 93 url_fetcher->AddExtraRequestHeader(
92 url_fetcher->SetHeader("X-Google-Relay-Auth", relay_token()); 94 "X-Talk-Google-Relay-Auth: " + relay_token());
93 url_fetcher->SetHeader("X-Stream-Type", "chromoting"); 95 url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token());
94 url_fetcher->Start(base::Bind(&HostPortAllocatorSession::OnSessionRequestDone, 96 url_fetcher->AddExtraRequestHeader("X-Stream-Type: chromoting");
95 base::Unretained(this), url_fetcher.get())); 97 url_fetcher->Start();
96 url_fetchers_.insert(url_fetcher.release()); 98 url_fetchers_.insert(url_fetcher.release());
97 } 99 }
98 100
99 void HostPortAllocatorSession::OnSessionRequestDone( 101 void HostPortAllocatorSession::OnURLFetchComplete(
100 UrlFetcher* url_fetcher, 102 const net::URLFetcher* source) {
101 const net::URLRequestStatus& status, 103 url_fetchers_.erase(source);
102 int response_code, 104 delete source;
103 const std::string& response) {
104 url_fetchers_.erase(url_fetcher);
105 delete url_fetcher;
106 105
107 if (response_code != net::HTTP_OK) { 106 if (source->GetResponseCode() != net::HTTP_OK) {
108 LOG(WARNING) << "Received error when allocating relay session: " 107 LOG(WARNING) << "Received error when allocating relay session: "
109 << response_code; 108 << source->GetResponseCode();
110 TryCreateRelaySession(); 109 TryCreateRelaySession();
111 return; 110 return;
112 } 111 }
113 112
113 std::string response;
114 source->GetResponseAsString(&response);
114 ReceiveSessionResponse(response); 115 ReceiveSessionResponse(response);
115 } 116 }
116 117
117 } // namespace 118 } // namespace
118 119
119 // static 120 // static
120 scoped_ptr<HostPortAllocator> HostPortAllocator::Create( 121 scoped_ptr<HostPortAllocator> HostPortAllocator::Create(
121 const scoped_refptr<net::URLRequestContextGetter>& url_context, 122 const scoped_refptr<net::URLRequestContextGetter>& url_context,
122 const NetworkSettings& network_settings) { 123 const NetworkSettings& network_settings) {
123 scoped_ptr<talk_base::NetworkManager> network_manager( 124 scoped_ptr<talk_base::NetworkManager> network_manager(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 cricket::PortAllocatorSession* HostPortAllocator::CreateSessionInternal( 161 cricket::PortAllocatorSession* HostPortAllocator::CreateSessionInternal(
161 int component, 162 int component,
162 const std::string& ice_username_fragment, 163 const std::string& ice_username_fragment,
163 const std::string& ice_password) { 164 const std::string& ice_password) {
164 return new HostPortAllocatorSession( 165 return new HostPortAllocatorSession(
165 this, component, ice_username_fragment, ice_password, 166 this, component, ice_username_fragment, ice_password,
166 stun_hosts(), relay_hosts(), relay_token(), url_context_); 167 stun_hosts(), relay_hosts(), relay_token(), url_context_);
167 } 168 }
168 169
169 } // namespace remoting 170 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_port_allocator.h ('k') | remoting/host/url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698