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

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: Add short test description 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
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // The IOThread object must outlive any tasks posted to the IO thread before the 206 // The IOThread object must outlive any tasks posted to the IO thread before the
207 // Quit task. 207 // Quit task.
208 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); 208 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);
209 209
210 IOThread::Globals::Globals() {} 210 IOThread::Globals::Globals() {}
211 211
212 IOThread::Globals::~Globals() {} 212 IOThread::Globals::~Globals() {}
213 213
214 // |local_state| is passed in explicitly in order to (1) reduce implicit 214 // |local_state| is passed in explicitly in order to (1) reduce implicit
215 // dependencies and (2) make IOThread more flexible for testing. 215 // dependencies and (2) make IOThread more flexible for testing.
216 IOThread::IOThread(PrefService* local_state) 216 IOThread::IOThread(PrefService* local_state, ChromeNetLog* net_log)
217 : BrowserProcessSubThread(BrowserThread::IO), 217 : BrowserProcessSubThread(BrowserThread::IO),
218 net_log_(net_log),
218 globals_(NULL), 219 globals_(NULL),
219 speculative_interceptor_(NULL), 220 speculative_interceptor_(NULL),
220 predictor_(NULL) { 221 predictor_(NULL) {
221 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make 222 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make
222 // sure that everything is initialized in the right order. 223 // sure that everything is initialized in the right order.
223 RegisterPrefs(local_state); 224 RegisterPrefs(local_state);
224 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); 225 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
225 negotiate_disable_cname_lookup_ = local_state->GetBoolean( 226 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
226 prefs::kDisableAuthNegotiateCnameLookup); 227 prefs::kDisableAuthNegotiateCnameLookup);
227 negotiate_enable_port_ = local_state->GetBoolean( 228 negotiate_enable_port_ = local_state->GetBoolean(
228 prefs::kEnableAuthNegotiatePort); 229 prefs::kEnableAuthNegotiatePort);
229 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); 230 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
230 auth_delegate_whitelist_ = local_state->GetString( 231 auth_delegate_whitelist_ = local_state->GetString(
231 prefs::kAuthNegotiateDelegateWhitelist); 232 prefs::kAuthNegotiateDelegateWhitelist);
232 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 233 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
233 } 234 }
234 235
235 IOThread::~IOThread() { 236 IOThread::~IOThread() {
236 // We cannot rely on our base class to stop the thread since we want our 237 // We cannot rely on our base class to stop the thread since we want our
237 // CleanUp function to run. 238 // CleanUp function to run.
238 Stop(); 239 Stop();
239 DCHECK(!globals_); 240 DCHECK(!globals_);
240 } 241 }
241 242
242 IOThread::Globals* IOThread::globals() { 243 IOThread::Globals* IOThread::globals() {
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
244 return globals_; 245 return globals_;
245 } 246 }
246 247
248 ChromeNetLog* IOThread::net_log() {
249 return net_log_;
250 }
251
247 void IOThread::InitNetworkPredictor( 252 void IOThread::InitNetworkPredictor(
248 bool prefetching_enabled, 253 bool prefetching_enabled,
249 base::TimeDelta max_dns_queue_delay, 254 base::TimeDelta max_dns_queue_delay,
250 size_t max_speculative_parallel_resolves, 255 size_t max_speculative_parallel_resolves,
251 const chrome_common_net::UrlList& startup_urls, 256 const chrome_common_net::UrlList& startup_urls,
252 ListValue* referral_list, 257 ListValue* referral_list,
253 bool preconnect_enabled) { 258 bool preconnect_enabled) {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
255 message_loop()->PostTask( 260 message_loop()->PostTask(
256 FROM_HERE, 261 FROM_HERE,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 317
313 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); 318 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
314 319
315 #if defined(USE_NSS) 320 #if defined(USE_NSS)
316 net::SetMessageLoopForOCSP(); 321 net::SetMessageLoopForOCSP();
317 #endif // defined(USE_NSS) 322 #endif // defined(USE_NSS)
318 323
319 DCHECK(!globals_); 324 DCHECK(!globals_);
320 globals_ = new Globals; 325 globals_ = new Globals;
321 326
322 globals_->net_log.reset(new ChromeNetLog());
323
324 // Add an observer that will emit network change events to the ChromeNetLog. 327 // Add an observer that will emit network change events to the ChromeNetLog.
325 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 328 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
326 // logging the network change before other IO thread consumers respond to it. 329 // logging the network change before other IO thread consumers respond to it.
327 network_change_observer_.reset( 330 network_change_observer_.reset(
328 new LoggingNetworkChangeObserver(globals_->net_log.get())); 331 new LoggingNetworkChangeObserver(net_log_));
329 332
330 globals_->host_resolver.reset( 333 globals_->host_resolver.reset(
331 CreateGlobalHostResolver(globals_->net_log.get())); 334 CreateGlobalHostResolver(net_log_));
332 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); 335 globals_->dnsrr_resolver.reset(new net::DnsRRResolver);
333 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 336 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
334 globals_->host_resolver.get())); 337 globals_->host_resolver.get()));
335 } 338 }
336 339
337 void IOThread::CleanUp() { 340 void IOThread::CleanUp() {
338 // Step 1: Kill all things that might be holding onto 341 // Step 1: Kill all things that might be holding onto
339 // URLRequest/URLRequestContexts. 342 // URLRequest/URLRequestContexts.
340 343
341 #if defined(USE_NSS) 344 #if defined(USE_NSS)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 387
385 // Deletion will unregister this interceptor. 388 // Deletion will unregister this interceptor.
386 delete speculative_interceptor_; 389 delete speculative_interceptor_;
387 speculative_interceptor_ = NULL; 390 speculative_interceptor_ = NULL;
388 391
389 // TODO(eroman): hack for http://crbug.com/15513 392 // TODO(eroman): hack for http://crbug.com/15513
390 if (globals_->host_resolver->GetAsHostResolverImpl()) { 393 if (globals_->host_resolver->GetAsHostResolverImpl()) {
391 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); 394 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown();
392 } 395 }
393 396
394 // We will delete the NetLog as part of CleanUpAfterMessageLoopDestruction()
395 // in case any of the message loop destruction observers try to access it.
396 deferred_net_log_to_delete_.reset(globals_->net_log.release());
397
398 delete globals_; 397 delete globals_;
399 globals_ = NULL; 398 globals_ = NULL;
400 399
401 BrowserProcessSubThread::CleanUp(); 400 BrowserProcessSubThread::CleanUp();
402 } 401 }
403 402
404 void IOThread::CleanUpAfterMessageLoopDestruction() { 403 void IOThread::CleanUpAfterMessageLoopDestruction() {
405 // TODO(eroman): get rid of this special case for 39723. If we could instead
406 // have a method that runs after the message loop destruction observers have
407 // run, but before the message loop itself is destroyed, we could safely
408 // combine the two cleanups.
409 deferred_net_log_to_delete_.reset();
410
411 // This will delete the |notification_service_|. Make sure it's done after 404 // This will delete the |notification_service_|. Make sure it's done after
412 // anything else can reference it. 405 // anything else can reference it.
413 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); 406 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction();
414 407
415 // URLRequest instances must NOT outlive the IO thread. 408 // URLRequest instances must NOT outlive the IO thread.
416 // 409 //
417 // To allow for URLRequests to be deleted from 410 // To allow for URLRequests to be deleted from
418 // MessageLoop::DestructionObserver this check has to happen after CleanUp 411 // MessageLoop::DestructionObserver this check has to happen after CleanUp
419 // (which runs before DestructionObservers). 412 // (which runs before DestructionObservers).
420 base::debug::LeakTracker<URLRequest>::CheckForLeaks(); 413 base::debug::LeakTracker<URLRequest>::CheckForLeaks();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // in about:net-internals. 485 // in about:net-internals.
493 if (globals_->host_resolver->GetAsHostResolverImpl()) { 486 if (globals_->host_resolver->GetAsHostResolverImpl()) {
494 net::HostCache* host_cache = 487 net::HostCache* host_cache =
495 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); 488 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache();
496 if (host_cache) 489 if (host_cache)
497 host_cache->clear(); 490 host_cache->clear();
498 } 491 }
499 // Clear all of the passively logged data. 492 // Clear all of the passively logged data.
500 // TODO(eroman): this is a bit heavy handed, really all we need to do is 493 // TODO(eroman): this is a bit heavy handed, really all we need to do is
501 // clear the data pertaining to off the record context. 494 // clear the data pertaining to off the record context.
502 globals_->net_log->passive_collector()->Clear(); 495 net_log_->ClearAllPassivelyCapturedEvents();
503 } 496 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698