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

Side by Side Diff: remoting/protocol/chromium_port_allocator.cc

Issue 1681393006: Use UrlRequest in PortAllocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/chromium_port_allocator.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/macros.h"
11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "net/http/http_status_code.h"
14 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_request_context_getter.h"
17 #include "remoting/protocol/chromium_socket_factory.h"
18 #include "remoting/protocol/transport_context.h"
19 #include "url/gurl.h"
20
21 namespace remoting {
22 namespace protocol {
23
24 namespace {
25
26 class ChromiumPortAllocatorSession : public PortAllocatorSessionBase,
27 public net::URLFetcherDelegate {
28 public:
29 ChromiumPortAllocatorSession(ChromiumPortAllocator* allocator,
30 const std::string& content_name,
31 int component,
32 const std::string& ice_username_fragment,
33 const std::string& ice_password);
34 ~ChromiumPortAllocatorSession() override;
35
36 // PortAllocatorBase overrides.
37 void SendSessionRequest(const std::string& host) override;
38
39 // net::URLFetcherDelegate interface.
40 void OnURLFetchComplete(const net::URLFetcher* url_fetcher) override;
41
42 private:
43 scoped_refptr<net::URLRequestContextGetter> url_context_;
44 std::set<const net::URLFetcher*> url_fetchers_;
45
46 DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorSession);
47 };
48
49 ChromiumPortAllocatorSession::ChromiumPortAllocatorSession(
50 ChromiumPortAllocator* allocator,
51 const std::string& content_name,
52 int component,
53 const std::string& ice_username_fragment,
54 const std::string& ice_password)
55 : PortAllocatorSessionBase(allocator,
56 content_name,
57 component,
58 ice_username_fragment,
59 ice_password),
60 url_context_(allocator->url_context()) {}
61
62 ChromiumPortAllocatorSession::~ChromiumPortAllocatorSession() {
63 STLDeleteElements(&url_fetchers_);
64 }
65
66 void ChromiumPortAllocatorSession::SendSessionRequest(const std::string& host) {
67 GURL url("https://" + host + GetSessionRequestUrl() + "&sn=1");
68 scoped_ptr<net::URLFetcher> url_fetcher =
69 net::URLFetcher::Create(url, net::URLFetcher::GET, this);
70 url_fetcher->SetRequestContext(url_context_.get());
71 url_fetcher->AddExtraRequestHeader("X-Talk-Google-Relay-Auth: " +
72 relay_token());
73 url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token());
74 url_fetcher->AddExtraRequestHeader("X-Stream-Type: chromoting");
75 url_fetcher->Start();
76 url_fetchers_.insert(url_fetcher.release());
77 }
78
79 void ChromiumPortAllocatorSession::OnURLFetchComplete(
80 const net::URLFetcher* source) {
81 int response_code = source->GetResponseCode();
82 std::string response;
83 source->GetResponseAsString(&response);
84
85 url_fetchers_.erase(source);
86 delete source;
87
88 if (response_code != net::HTTP_OK) {
89 LOG(WARNING) << "Received error when allocating relay session: "
90 << response_code;
91 TryCreateRelaySession();
92 return;
93 }
94
95 ReceiveSessionResponse(response);
96 }
97
98 } // namespace
99
100 ChromiumPortAllocator::ChromiumPortAllocator(
101 scoped_ptr<rtc::NetworkManager> network_manager,
102 scoped_ptr<rtc::PacketSocketFactory> socket_factory,
103 scoped_refptr<TransportContext> transport_context,
104 scoped_refptr<net::URLRequestContextGetter> url_context)
105 : PortAllocatorBase(std::move(network_manager),
106 std::move(socket_factory),
107 transport_context),
108 url_context_(url_context) {}
109
110 ChromiumPortAllocator::~ChromiumPortAllocator() {}
111
112 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal(
113 const std::string& content_name,
114 int component,
115 const std::string& ice_username_fragment,
116 const std::string& ice_password) {
117 return new ChromiumPortAllocatorSession(this, content_name, component,
118 ice_username_fragment, ice_password);
119 }
120
121 ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory(
122 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
123 : url_request_context_getter_(url_request_context_getter) {}
124
125 ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {}
126
127 scoped_ptr<cricket::PortAllocator>
128 ChromiumPortAllocatorFactory::CreatePortAllocator(
129 scoped_refptr<TransportContext> transport_context) {
130 scoped_ptr<rtc::NetworkManager> network_manager(
131 new rtc::BasicNetworkManager());
132 scoped_ptr<rtc::PacketSocketFactory> socket_factory(
133 new ChromiumPacketSocketFactory());
134 return make_scoped_ptr(new ChromiumPortAllocator(
135 std::move(network_manager), std::move(socket_factory), transport_context,
136 url_request_context_getter_));
137 }
138
139 } // namespace protocol
140 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/chromium_port_allocator.h ('k') | remoting/protocol/chromium_port_allocator_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698