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

Side by Side Diff: ios/crnet/crnet_environment.mm

Issue 1158033010: [CrNet] Properly setup net log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « ios/crnet/crnet_environment.h ('k') | ios/crnet/crnet_net_log.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 2014 The Chromium Authors. All rights reserved. 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 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 "ios/crnet/crnet_environment.h" 5 #include "ios/crnet/crnet_environment.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h"
13 #include "base/files/scoped_file.h"
11 #include "base/i18n/icu_util.h" 14 #include "base/i18n/icu_util.h"
12 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
13 #include "base/mac/bind_objc_block.h" 16 #include "base/mac/bind_objc_block.h"
14 #include "base/mac/foundation_util.h" 17 #include "base/mac/foundation_util.h"
15 #include "base/mac/scoped_block.h" 18 #include "base/mac/scoped_block.h"
16 #include "base/path_service.h" 19 #include "base/path_service.h"
17 #include "base/threading/worker_pool.h" 20 #include "base/threading/worker_pool.h"
21 #include "base/values.h"
18 #import "components/webp_transcode/webp_network_client_factory.h" 22 #import "components/webp_transcode/webp_network_client_factory.h"
19 #include "crypto/nss_util.h" 23 #include "crypto/nss_util.h"
20 #include "ios/net/cookies/cookie_store_ios.h" 24 #include "ios/net/cookies/cookie_store_ios.h"
21 #include "ios/net/crn_http_protocol_handler.h" 25 #include "ios/net/crn_http_protocol_handler.h"
22 #include "ios/net/request_tracker.h" 26 #include "ios/net/request_tracker.h"
23 #include "ios/web/public/user_agent.h" 27 #include "ios/web/public/user_agent.h"
24 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
25 #include "net/base/network_change_notifier.h" 29 #include "net/base/network_change_notifier.h"
26 #include "net/base/sdch_manager.h" 30 #include "net/base/sdch_manager.h"
27 #include "net/cert/cert_verifier.h" 31 #include "net/cert/cert_verifier.h"
28 #include "net/cert_net/nss_ocsp.h" 32 #include "net/cert_net/nss_ocsp.h"
29 #include "net/disk_cache/disk_cache.h" 33 #include "net/disk_cache/disk_cache.h"
30 #include "net/http/http_auth_handler_factory.h" 34 #include "net/http/http_auth_handler_factory.h"
31 #include "net/http/http_cache.h" 35 #include "net/http/http_cache.h"
32 #include "net/http/http_server_properties_impl.h" 36 #include "net/http/http_server_properties_impl.h"
33 #include "net/http/http_stream_factory.h" 37 #include "net/http/http_stream_factory.h"
34 #include "net/http/http_util.h" 38 #include "net/http/http_util.h"
39 #include "net/log/net_log.h"
40 #include "net/log/net_log_util.h"
41 #include "net/log/write_to_file_net_log_observer.h"
35 #include "net/proxy/proxy_service.h" 42 #include "net/proxy/proxy_service.h"
36 #include "net/socket/next_proto.h" 43 #include "net/socket/next_proto.h"
37 #include "net/ssl/channel_id_service.h" 44 #include "net/ssl/channel_id_service.h"
38 #include "net/ssl/default_channel_id_store.h" 45 #include "net/ssl/default_channel_id_store.h"
39 #include "net/ssl/ssl_config_service_defaults.h" 46 #include "net/ssl/ssl_config_service_defaults.h"
40 #include "net/url_request/data_protocol_handler.h" 47 #include "net/url_request/data_protocol_handler.h"
41 #include "net/url_request/file_protocol_handler.h" 48 #include "net/url_request/file_protocol_handler.h"
42 #include "net/url_request/sdch_dictionary_fetcher.h" 49 #include "net/url_request/sdch_dictionary_fetcher.h"
43 #include "net/url_request/static_http_user_agent_settings.h" 50 #include "net/url_request/static_http_user_agent_settings.h"
44 #include "net/url_request/url_request_context_getter.h" 51 #include "net/url_request/url_request_context_getter.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Create a message loop on the UI thread. 154 // Create a message loop on the UI thread.
148 base::MessageLoop* main_message_loop = 155 base::MessageLoop* main_message_loop =
149 new base::MessageLoop(base::MessageLoop::TYPE_UI); 156 new base::MessageLoop(base::MessageLoop::TYPE_UI);
150 #pragma unused(main_message_loop) 157 #pragma unused(main_message_loop)
151 base::MessageLoopForUI::current()->Attach(); 158 base::MessageLoopForUI::current()->Attach();
152 } 159 }
153 160
154 void CrNetEnvironment::StartNetLog(base::FilePath::StringType file_name, 161 void CrNetEnvironment::StartNetLog(base::FilePath::StringType file_name,
155 bool log_bytes) { 162 bool log_bytes) {
156 DCHECK(file_name.length()); 163 DCHECK(file_name.length());
157 base::AutoLock lock(net_log_lock_);
158 if (net_log_started_) {
159 return;
160 }
161 net_log_started_ = true;
162 PostToFileUserBlockingThread(FROM_HERE, 164 PostToFileUserBlockingThread(FROM_HERE,
163 base::Bind(&CrNetEnvironment::StartNetLogInternal, 165 base::Bind(&CrNetEnvironment::StartNetLogInternal,
164 base::Unretained(this), file_name, log_bytes)); 166 base::Unretained(this), file_name, log_bytes));
165 } 167 }
166 168
167 void CrNetEnvironment::StartNetLogInternal( 169 void CrNetEnvironment::StartNetLogInternal(
168 base::FilePath::StringType file_name, bool log_bytes) { 170 base::FilePath::StringType file_name, bool log_bytes) {
169 DCHECK(base::MessageLoop::current() == 171 DCHECK(base::MessageLoop::current() ==
170 file_user_blocking_thread_->message_loop()); 172 file_user_blocking_thread_->message_loop());
171 DCHECK(file_name.length()); 173 DCHECK(file_name.length());
172 if (!net_log_.get()) { 174 DCHECK(net_log_.get());
mmenke 2015/06/05 18:56:49 nit: get not needed.
mef 2015/06/05 19:52:06 Done.
173 net_log_.reset(new CrNetNetLog()); 175
174 main_context_.get()->set_net_log(net_log_.get()); 176 if (net_log_observer_.get())
mmenke 2015/06/05 18:56:49 nit: get not needed.
mef 2015/06/05 19:52:06 Done.
175 } 177 return;
176 CrNetNetLog::Mode mode = log_bytes ? CrNetNetLog::LOG_ALL_BYTES : 178
177 CrNetNetLog::LOG_STRIP_PRIVATE_DATA; 179 base::FilePath temp_dir;
178 net_log_->Start(base::FilePath(file_name), mode); 180 if (!base::GetTempDir(&temp_dir))
181 return;
182
183 base::FilePath full_path = temp_dir.Append(file_name);
184 base::ScopedFILE file(base::OpenFile(full_path, "w"));
185 if (!file)
186 return;
187
188 scoped_ptr<base::Value> constants(net::GetNetConstants().Pass());
mmenke 2015/06/05 18:56:49 This isn't needed - can just pass in a null pointe
mef 2015/06/05 19:52:06 Done.
189 net::NetLogCaptureMode capture_mode = log_bytes ?
190 net::NetLogCaptureMode::IncludeSocketBytes() :
191 net::NetLogCaptureMode::Default();
192
193 net_log_observer_.reset(new net::WriteToFileNetLogObserver());
194 net_log_observer_->set_capture_mode(capture_mode);
195 net_log_observer_->StartObserving(net_log_.get(), file.Pass(),
196 constants.get(), nullptr);
179 } 197 }
180 198
181 void CrNetEnvironment::StopNetLog() { 199 void CrNetEnvironment::StopNetLog() {
182 base::AutoLock lock(net_log_lock_);
183 if (!net_log_started_) {
184 return;
185 }
186 net_log_started_ = false;
187 PostToFileUserBlockingThread(FROM_HERE, 200 PostToFileUserBlockingThread(FROM_HERE,
188 base::Bind(&CrNetEnvironment::StopNetLogInternal, 201 base::Bind(&CrNetEnvironment::StopNetLogInternal,
189 base::Unretained(this))); 202 base::Unretained(this)));
190 } 203 }
191 204
192 void CrNetEnvironment::StopNetLogInternal() { 205 void CrNetEnvironment::StopNetLogInternal() {
193 DCHECK(base::MessageLoop::current() == 206 DCHECK(base::MessageLoop::current() ==
194 file_user_blocking_thread_->message_loop()); 207 file_user_blocking_thread_->message_loop());
195 if (net_log_.get()) { 208 if (net_log_observer_.get()) {
196 net_log_->Stop(); 209 net_log_observer_->StopObserving(nullptr);
210 net_log_observer_.reset();
197 } 211 }
198 } 212 }
199 213
200 void CrNetEnvironment::CloseAllSpdySessions() { 214 void CrNetEnvironment::CloseAllSpdySessions() {
201 PostToNetworkThread(FROM_HERE, 215 PostToNetworkThread(FROM_HERE,
202 base::Bind(&CrNetEnvironment::CloseAllSpdySessionsInternal, 216 base::Bind(&CrNetEnvironment::CloseAllSpdySessionsInternal,
203 base::Unretained(this))); 217 base::Unretained(this)));
204 } 218 }
205 219
206 void CrNetEnvironment::SetRequestFilterBlock(RequestFilterBlock block) { 220 void CrNetEnvironment::SetRequestFilterBlock(RequestFilterBlock block) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 network_io_thread_->message_loop_proxy(), nullptr)); 277 network_io_thread_->message_loop_proxy(), nullptr));
264 278
265 PostToNetworkThread(FROM_HERE, 279 PostToNetworkThread(FROM_HERE,
266 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, 280 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread,
267 base::Unretained(this))); 281 base::Unretained(this)));
268 282
269 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); 283 net::SetURLRequestContextForNSSHttpIO(main_context_.get());
270 main_context_getter_ = new CrNetURLRequestContextGetter( 284 main_context_getter_ = new CrNetURLRequestContextGetter(
271 main_context_.get(), network_io_thread_->message_loop_proxy()); 285 main_context_.get(), network_io_thread_->message_loop_proxy());
272 SetRequestFilterBlock(nil); 286 SetRequestFilterBlock(nil);
273 net_log_started_ = false;
274 } 287 }
275 288
276 void CrNetEnvironment::InstallIntoSessionConfiguration( 289 void CrNetEnvironment::InstallIntoSessionConfiguration(
277 NSURLSessionConfiguration* config) { 290 NSURLSessionConfiguration* config) {
278 config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ]; 291 config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ];
279 } 292 }
280 293
281 CrNetEnvironment::~CrNetEnvironment() { 294 CrNetEnvironment::~CrNetEnvironment() {
282 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); 295 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
283 net::SetURLRequestContextForNSSHttpIO(nullptr); 296 net::SetURLRequestContextForNSSHttpIO(nullptr);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 scoped_refptr<net::CookieStore> cookie_store = 429 scoped_refptr<net::CookieStore> cookie_store =
417 net::CookieStoreIOS::CreateCookieStoreFromNSHTTPCookieStorage(); 430 net::CookieStoreIOS::CreateCookieStoreFromNSHTTPCookieStorage();
418 main_context_->set_cookie_store(cookie_store.get()); 431 main_context_->set_cookie_store(cookie_store.get());
419 432
420 net::URLRequestJobFactoryImpl* job_factory = 433 net::URLRequestJobFactoryImpl* job_factory =
421 new net::URLRequestJobFactoryImpl; 434 new net::URLRequestJobFactoryImpl;
422 job_factory->SetProtocolHandler("data", new net::DataProtocolHandler); 435 job_factory->SetProtocolHandler("data", new net::DataProtocolHandler);
423 job_factory->SetProtocolHandler( 436 job_factory->SetProtocolHandler(
424 "file", new net::FileProtocolHandler(file_thread_->message_loop_proxy())); 437 "file", new net::FileProtocolHandler(file_thread_->message_loop_proxy()));
425 main_context_->set_job_factory(job_factory); 438 main_context_->set_job_factory(job_factory);
439
440 net_log_.reset(new net::NetLog());
441 main_context_->set_net_log(net_log_.get());
426 } 442 }
427 443
428 std::string CrNetEnvironment::user_agent() { 444 std::string CrNetEnvironment::user_agent() {
429 const net::HttpUserAgentSettings* user_agent_settings = 445 const net::HttpUserAgentSettings* user_agent_settings =
430 main_context_->http_user_agent_settings(); 446 main_context_->http_user_agent_settings();
431 if (!user_agent_settings) { 447 if (!user_agent_settings) {
432 return nullptr; 448 return nullptr;
433 } 449 }
434 450
435 return user_agent_settings->GetUserAgent(); 451 return user_agent_settings->GetUserAgent();
(...skipping 19 matching lines...) Expand all
455 if (backend) 471 if (backend)
456 backend->DoomAllEntries(client_callback); 472 backend->DoomAllEntries(client_callback);
457 }); 473 });
458 int rc = cache->GetBackend(&backend, doom_callback); 474 int rc = cache->GetBackend(&backend, doom_callback);
459 if (rc != net::ERR_IO_PENDING) { 475 if (rc != net::ERR_IO_PENDING) {
460 // GetBackend doesn't call the callback if it completes synchronously, so 476 // GetBackend doesn't call the callback if it completes synchronously, so
461 // call it directly here. 477 // call it directly here.
462 doom_callback.Run(rc); 478 doom_callback.Run(rc);
463 } 479 }
464 } 480 }
OLDNEW
« no previous file with comments | « ios/crnet/crnet_environment.h ('k') | ios/crnet/crnet_net_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698