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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 4118004: Update NetLog to be thread safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final sync with trunk Created 10 years 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 | « chrome/browser/io_thread.h ('k') | chrome/browser/net/chrome_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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/leak_tracker.h" 10 #include "base/debug/leak_tracker.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // The IOThread object must outlive any tasks posted to the IO thread before the 207 // The IOThread object must outlive any tasks posted to the IO thread before the
208 // Quit task. 208 // Quit task.
209 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); 209 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);
210 210
211 IOThread::Globals::Globals() {} 211 IOThread::Globals::Globals() {}
212 212
213 IOThread::Globals::~Globals() {} 213 IOThread::Globals::~Globals() {}
214 214
215 // |local_state| is passed in explicitly in order to (1) reduce implicit 215 // |local_state| is passed in explicitly in order to (1) reduce implicit
216 // dependencies and (2) make IOThread more flexible for testing. 216 // dependencies and (2) make IOThread more flexible for testing.
217 IOThread::IOThread(PrefService* local_state) 217 IOThread::IOThread(PrefService* local_state, ChromeNetLog* net_log)
218 : BrowserProcessSubThread(BrowserThread::IO), 218 : BrowserProcessSubThread(BrowserThread::IO),
219 net_log_(net_log),
219 globals_(NULL), 220 globals_(NULL),
220 speculative_interceptor_(NULL), 221 speculative_interceptor_(NULL),
221 predictor_(NULL) { 222 predictor_(NULL) {
222 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make 223 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make
223 // sure that everything is initialized in the right order. 224 // sure that everything is initialized in the right order.
224 RegisterPrefs(local_state); 225 RegisterPrefs(local_state);
225 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); 226 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
226 negotiate_disable_cname_lookup_ = local_state->GetBoolean( 227 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
227 prefs::kDisableAuthNegotiateCnameLookup); 228 prefs::kDisableAuthNegotiateCnameLookup);
228 negotiate_enable_port_ = local_state->GetBoolean( 229 negotiate_enable_port_ = local_state->GetBoolean(
229 prefs::kEnableAuthNegotiatePort); 230 prefs::kEnableAuthNegotiatePort);
230 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); 231 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
231 auth_delegate_whitelist_ = local_state->GetString( 232 auth_delegate_whitelist_ = local_state->GetString(
232 prefs::kAuthNegotiateDelegateWhitelist); 233 prefs::kAuthNegotiateDelegateWhitelist);
233 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 234 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
234 } 235 }
235 236
236 IOThread::~IOThread() { 237 IOThread::~IOThread() {
237 // We cannot rely on our base class to stop the thread since we want our 238 // We cannot rely on our base class to stop the thread since we want our
238 // CleanUp function to run. 239 // CleanUp function to run.
239 Stop(); 240 Stop();
240 DCHECK(!globals_); 241 DCHECK(!globals_);
241 } 242 }
242 243
243 IOThread::Globals* IOThread::globals() { 244 IOThread::Globals* IOThread::globals() {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
245 return globals_; 246 return globals_;
246 } 247 }
247 248
249 ChromeNetLog* IOThread::net_log() {
250 return net_log_;
251 }
252
248 void IOThread::InitNetworkPredictor( 253 void IOThread::InitNetworkPredictor(
249 bool prefetching_enabled, 254 bool prefetching_enabled,
250 base::TimeDelta max_dns_queue_delay, 255 base::TimeDelta max_dns_queue_delay,
251 size_t max_speculative_parallel_resolves, 256 size_t max_speculative_parallel_resolves,
252 const chrome_common_net::UrlList& startup_urls, 257 const chrome_common_net::UrlList& startup_urls,
253 ListValue* referral_list, 258 ListValue* referral_list,
254 bool preconnect_enabled) { 259 bool preconnect_enabled) {
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
256 message_loop()->PostTask( 261 message_loop()->PostTask(
257 FROM_HERE, 262 FROM_HERE,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 318
314 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); 319 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
315 320
316 #if defined(USE_NSS) 321 #if defined(USE_NSS)
317 net::SetMessageLoopForOCSP(); 322 net::SetMessageLoopForOCSP();
318 #endif // defined(USE_NSS) 323 #endif // defined(USE_NSS)
319 324
320 DCHECK(!globals_); 325 DCHECK(!globals_);
321 globals_ = new Globals; 326 globals_ = new Globals;
322 327
323 globals_->net_log.reset(new ChromeNetLog());
324
325 // Add an observer that will emit network change events to the ChromeNetLog. 328 // Add an observer that will emit network change events to the ChromeNetLog.
326 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 329 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
327 // logging the network change before other IO thread consumers respond to it. 330 // logging the network change before other IO thread consumers respond to it.
328 network_change_observer_.reset( 331 network_change_observer_.reset(
329 new LoggingNetworkChangeObserver(globals_->net_log.get())); 332 new LoggingNetworkChangeObserver(net_log_));
330 333
331 globals_->host_resolver.reset( 334 globals_->host_resolver.reset(
332 CreateGlobalHostResolver(globals_->net_log.get())); 335 CreateGlobalHostResolver(net_log_));
333 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); 336 globals_->dnsrr_resolver.reset(new net::DnsRRResolver);
334 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 337 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
335 globals_->host_resolver.get())); 338 globals_->host_resolver.get()));
336 339
337 if (CommandLine::ForCurrentProcess()->HasSwitch( 340 if (CommandLine::ForCurrentProcess()->HasSwitch(
338 switches::kEnablePagePrerender)) { 341 switches::kEnablePagePrerender)) {
339 prerender_interceptor_.reset( 342 prerender_interceptor_.reset(
340 new chrome_browser_net::PrerenderInterceptor()); 343 new chrome_browser_net::PrerenderInterceptor());
341 } 344 }
342 } 345 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 delete speculative_interceptor_; 412 delete speculative_interceptor_;
410 speculative_interceptor_ = NULL; 413 speculative_interceptor_ = NULL;
411 414
412 prerender_interceptor_.reset(); 415 prerender_interceptor_.reset();
413 416
414 // TODO(eroman): hack for http://crbug.com/15513 417 // TODO(eroman): hack for http://crbug.com/15513
415 if (globals_->host_resolver->GetAsHostResolverImpl()) { 418 if (globals_->host_resolver->GetAsHostResolverImpl()) {
416 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); 419 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown();
417 } 420 }
418 421
419 // We will delete the NetLog as part of CleanUpAfterMessageLoopDestruction()
420 // in case any of the message loop destruction observers try to access it.
421 deferred_net_log_to_delete_.reset(globals_->net_log.release());
422
423 delete globals_; 422 delete globals_;
424 globals_ = NULL; 423 globals_ = NULL;
425 424
426 BrowserProcessSubThread::CleanUp(); 425 BrowserProcessSubThread::CleanUp();
427 } 426 }
428 427
429 void IOThread::CleanUpAfterMessageLoopDestruction() { 428 void IOThread::CleanUpAfterMessageLoopDestruction() {
430 // TODO(eroman): get rid of this special case for 39723. If we could instead
431 // have a method that runs after the message loop destruction observers have
432 // run, but before the message loop itself is destroyed, we could safely
433 // combine the two cleanups.
434 deferred_net_log_to_delete_.reset();
435
436 // This will delete the |notification_service_|. Make sure it's done after 429 // This will delete the |notification_service_|. Make sure it's done after
437 // anything else can reference it. 430 // anything else can reference it.
438 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); 431 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction();
439 432
440 // net::URLRequest instances must NOT outlive the IO thread. 433 // net::URLRequest instances must NOT outlive the IO thread.
441 // 434 //
442 // To allow for URLRequests to be deleted from 435 // To allow for URLRequests to be deleted from
443 // MessageLoop::DestructionObserver this check has to happen after CleanUp 436 // MessageLoop::DestructionObserver this check has to happen after CleanUp
444 // (which runs before DestructionObservers). 437 // (which runs before DestructionObservers).
445 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); 438 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // in about:net-internals. 515 // in about:net-internals.
523 if (globals_->host_resolver->GetAsHostResolverImpl()) { 516 if (globals_->host_resolver->GetAsHostResolverImpl()) {
524 net::HostCache* host_cache = 517 net::HostCache* host_cache =
525 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); 518 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache();
526 if (host_cache) 519 if (host_cache)
527 host_cache->clear(); 520 host_cache->clear();
528 } 521 }
529 // Clear all of the passively logged data. 522 // Clear all of the passively logged data.
530 // TODO(eroman): this is a bit heavy handed, really all we need to do is 523 // TODO(eroman): this is a bit heavy handed, really all we need to do is
531 // clear the data pertaining to off the record context. 524 // clear the data pertaining to off the record context.
532 globals_->net_log->passive_collector()->Clear(); 525 net_log_->ClearAllPassivelyCapturedEvents();
533 } 526 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.h ('k') | chrome/browser/net/chrome_net_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698