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

Side by Side Diff: components/cronet/ios/cronet_environment.cc

Issue 2273403003: Moving gRPC support interfaces out of cronet and into a new component. (Closed)
Patch Set: Fix DEPS Created 4 years, 2 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/cronet/ios/cronet_environment.h" 5 #include "components/cronet/ios/cronet_environment.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 base::AtExitManager* g_at_exit_ = nullptr; 61 base::AtExitManager* g_at_exit_ = nullptr;
62 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; 62 net::NetworkChangeNotifier* g_network_change_notifier = nullptr;
63 // MessageLoop on the main thread. 63 // MessageLoop on the main thread.
64 base::MessageLoop* g_main_message_loop = nullptr; 64 base::MessageLoop* g_main_message_loop = nullptr;
65 65
66 } // namespace 66 } // namespace
67 67
68 namespace cronet { 68 namespace cronet {
69 69
70 bool CronetEnvironment::IsOnNetworkThread() {
71 return network_io_thread_->task_runner()->BelongsToCurrentThread();
72 }
73
74 void CronetEnvironment::PostToNetworkThread( 70 void CronetEnvironment::PostToNetworkThread(
75 const tracked_objects::Location& from_here, 71 const tracked_objects::Location& from_here,
76 const base::Closure& task) { 72 const base::Closure& task) {
77 network_io_thread_->task_runner()->PostTask(from_here, task); 73 network_io_thread_->task_runner()->PostTask(from_here, task);
78 } 74 }
79 75
80 void CronetEnvironment::PostToFileUserBlockingThread( 76 void CronetEnvironment::PostToFileUserBlockingThread(
81 const tracked_objects::Location& from_here, 77 const tracked_objects::Location& from_here,
82 const base::Closure& task) { 78 const base::Closure& task) {
83 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); 79 file_user_blocking_thread_->task_runner()->PostTask(from_here, task);
84 } 80 }
85 81
86 net::URLRequestContext* CronetEnvironment::GetURLRequestContext() const { 82 net::URLRequestContextGetter* CronetEnvironment::GetURLRequestContextGetter() {
87 return main_context_.get(); 83 return request_context_getter_.get();
88 } 84 }
89 85
90 // static 86 // static
91 void CronetEnvironment::Initialize() { 87 void CronetEnvironment::Initialize() {
92 // DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); 88 // DCHECK_EQ([NSThread currentThread], [NSThread mainThread]);
93 // This method must be called once from the main thread. 89 // This method must be called once from the main thread.
94 if (!g_at_exit_) 90 if (!g_at_exit_)
95 g_at_exit_ = new base::AtExitManager; 91 g_at_exit_ = new base::AtExitManager;
96 92
97 url::Initialize(); 93 url::Initialize();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file)) 212 if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file))
217 return; 213 return;
218 net::SSLClientSocket::SetSSLKeyLogFile( 214 net::SSLClientSocket::SetSSLKeyLogFile(
219 ssl_key_log_file.Append(ssl_key_log_file_name_), 215 ssl_key_log_file.Append(ssl_key_log_file_name_),
220 file_thread_->task_runner()); 216 file_thread_->task_runner());
221 } 217 }
222 218
223 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( 219 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService(
224 network_io_thread_->task_runner(), nullptr); 220 network_io_thread_->task_runner(), nullptr);
225 221
222 // Create request_context_getter_ here so that it will be availble as soon
mef 2016/10/11 22:09:37 Would it be easier to have custom net::URLRequestC
Garrett Casto 2016/10/12 00:23:36 Yes. If nothing else this doesn't require getting
223 // as this function returns. main_context_ won't actually be setup at that
224 // point, but any usage should happen on the network thread and the
225 // initialization callback will be run before any other posted task.
226 main_context_.reset(new net::URLRequestContext);
227 main_context_->DetachFromThread();
228 request_context_getter_ = new net::TrivialURLRequestContextGetter(
229 main_context_.get(), network_io_thread_->task_runner());
230
226 #if defined(USE_NSS_CERTS) 231 #if defined(USE_NSS_CERTS)
227 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); 232 net::SetURLRequestContextForNSSHttpIO(main_context_.get());
228 #endif 233 #endif
229 base::subtle::MemoryBarrier(); 234 base::subtle::MemoryBarrier();
230 PostToNetworkThread(FROM_HERE, 235 PostToNetworkThread(FROM_HERE,
231 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, 236 base::Bind(&CronetEnvironment::InitializeOnNetworkThread,
232 base::Unretained(this))); 237 base::Unretained(this)));
233 } 238 }
234 239
235 CronetEnvironment::~CronetEnvironment() { 240 CronetEnvironment::~CronetEnvironment() {
236 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); 241 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
237 #if defined(USE_NSS_CERTS) 242 #if defined(USE_NSS_CERTS)
238 net::SetURLRequestContextForNSSHttpIO(nullptr); 243 net::SetURLRequestContextForNSSHttpIO(nullptr);
239 #endif 244 #endif
240 } 245 }
241 246
242 void CronetEnvironment::InitializeOnNetworkThread() { 247 void CronetEnvironment::InitializeOnNetworkThread() {
243 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); 248 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread());
244 base::FeatureList::InitializeInstance(std::string(), std::string()); 249 base::FeatureList::InitializeInstance(std::string(), std::string());
245 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build. 250 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build.
246 main_context_.reset(new net::URLRequestContext);
247 main_context_->set_net_log(net_log_.get()); 251 main_context_->set_net_log(net_log_.get());
248 std::string user_agent(user_agent_product_name_ + 252 std::string user_agent(user_agent_product_name_ +
249 " (iOS); Cronet/" CRONET_VERSION); 253 " (iOS); Cronet/" CRONET_VERSION);
250 main_context_->set_http_user_agent_settings( 254 main_context_->set_http_user_agent_settings(
251 new net::StaticHttpUserAgentSettings("en", user_agent)); 255 new net::StaticHttpUserAgentSettings("en", user_agent));
252 256
253 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults); 257 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
254 main_context_->set_transport_security_state( 258 main_context_->set_transport_security_state(
255 new net::TransportSecurityState()); 259 new net::TransportSecurityState());
256 http_server_properties_.reset(new net::HttpServerPropertiesImpl()); 260 http_server_properties_.reset(new net::HttpServerPropertiesImpl());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 const net::HttpUserAgentSettings* user_agent_settings = 357 const net::HttpUserAgentSettings* user_agent_settings =
354 main_context_->http_user_agent_settings(); 358 main_context_->http_user_agent_settings();
355 if (!user_agent_settings) { 359 if (!user_agent_settings) {
356 return nullptr; 360 return nullptr;
357 } 361 }
358 362
359 return user_agent_settings->GetUserAgent(); 363 return user_agent_settings->GetUserAgent();
360 } 364 }
361 365
362 } // namespace cronet 366 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698