| OLD | NEW |
| 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 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/leak_tracker.h" | 7 #include "base/leak_tracker.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 globals_ = new Globals; | 137 globals_ = new Globals; |
| 138 | 138 |
| 139 globals_->net_log.reset(new ChromeNetLog()); | 139 globals_->net_log.reset(new ChromeNetLog()); |
| 140 globals_->network_change_notifier.reset( | 140 globals_->network_change_notifier.reset( |
| 141 net::NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier()); | 141 net::NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier()); |
| 142 globals_->host_resolver = | 142 globals_->host_resolver = |
| 143 CreateGlobalHostResolver(globals_->network_change_notifier.get()); | 143 CreateGlobalHostResolver(globals_->network_change_notifier.get()); |
| 144 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory()); | 144 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void IOThread::CleanUpAfterMessageLoopDestruction() { | 147 void IOThread::CleanUp() { |
| 148 // Not initialized in Init(). May not be initialized. | 148 // Not initialized in Init(). May not be initialized. |
| 149 if (dns_master_) { | 149 if (dns_master_) { |
| 150 DCHECK(prefetch_observer_); | 150 DCHECK(prefetch_observer_); |
| 151 | 151 |
| 152 dns_master_->Shutdown(); | 152 dns_master_->Shutdown(); |
| 153 | 153 |
| 154 // TODO(willchan): Stop reference counting DnsMaster. It's owned by | 154 // TODO(willchan): Stop reference counting DnsMaster. It's owned by |
| 155 // IOThread now. | 155 // IOThread now. |
| 156 dns_master_->Release(); | 156 dns_master_->Release(); |
| 157 dns_master_ = NULL; | 157 dns_master_ = NULL; |
| 158 chrome_browser_net::FreeDnsPrefetchResources(); | 158 chrome_browser_net::FreeDnsPrefetchResources(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Not initialized in Init(). May not be initialized. | 161 // Not initialized in Init(). May not be initialized. |
| 162 if (prefetch_observer_) { | 162 if (prefetch_observer_) { |
| 163 globals_->host_resolver->RemoveObserver(prefetch_observer_); | 163 globals_->host_resolver->RemoveObserver(prefetch_observer_); |
| 164 delete prefetch_observer_; | 164 delete prefetch_observer_; |
| 165 prefetch_observer_ = NULL; | 165 prefetch_observer_ = NULL; |
| 166 } | 166 } |
| 167 | 167 |
| 168 // TODO(eroman): hack for http://crbug.com/15513 | 168 // TODO(eroman): hack for http://crbug.com/15513 |
| 169 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 169 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 170 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); | 170 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // We will delete the NetLog as part of CleanUpAfterMessageLoopDestruction() |
| 174 // in case any of the message loop destruction observers try to access it. |
| 175 deferred_net_log_to_delete_.reset(globals_->net_log.release()); |
| 176 |
| 173 delete globals_; | 177 delete globals_; |
| 174 globals_ = NULL; | 178 globals_ = NULL; |
| 175 | 179 |
| 176 // URLFetcher and URLRequest instances must NOT outlive the IO thread. | 180 // URLFetcher and URLRequest instances must NOT outlive the IO thread. |
| 177 // | 181 // |
| 178 // Strictly speaking, URLFetcher's CheckForLeaks() should be done on the | 182 // Strictly speaking, URLFetcher's CheckForLeaks() should be done on the |
| 179 // UI thread. However, since there _shouldn't_ be any instances left | 183 // UI thread. However, since there _shouldn't_ be any instances left |
| 180 // at this point, it shouldn't be a race. | 184 // at this point, it shouldn't be a race. |
| 181 // | 185 // |
| 182 // We check URLFetcher first, since if it has leaked then an associated | 186 // We check URLFetcher first, since if it has leaked then an associated |
| 183 // URLRequest will also have leaked. However it is more useful to | 187 // URLRequest will also have leaked. However it is more useful to |
| 184 // crash showing the callstack of URLFetcher's allocation than its | 188 // crash showing the callstack of URLFetcher's allocation than its |
| 185 // URLRequest member. | 189 // URLRequest member. |
| 186 base::LeakTracker<URLFetcher>::CheckForLeaks(); | 190 base::LeakTracker<URLFetcher>::CheckForLeaks(); |
| 187 base::LeakTracker<URLRequest>::CheckForLeaks(); | 191 base::LeakTracker<URLRequest>::CheckForLeaks(); |
| 188 | 192 |
| 193 BrowserProcessSubThread::CleanUp(); |
| 194 } |
| 195 |
| 196 void IOThread::CleanUpAfterMessageLoopDestruction() { |
| 197 // TODO(eroman): get rid of this special case for 39723. If we could instead |
| 198 // have a method that runs after the message loop destruction obsevers have |
| 199 // run, but before the message loop itself is destroyed, we could safely |
| 200 // combine the two cleanups. |
| 201 deferred_net_log_to_delete_.reset(); |
| 189 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); | 202 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); |
| 190 } | 203 } |
| 191 | 204 |
| 192 net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory() { | 205 net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory() { |
| 193 net::HttpAuthFilterWhitelist* auth_filter = NULL; | 206 net::HttpAuthFilterWhitelist* auth_filter = NULL; |
| 194 | 207 |
| 195 // Get the whitelist information from the command line, create an | 208 // Get the whitelist information from the command line, create an |
| 196 // HttpAuthFilterWhitelist, and attach it to the HttpAuthHandlerFactory. | 209 // HttpAuthFilterWhitelist, and attach it to the HttpAuthHandlerFactory. |
| 197 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 210 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 198 | 211 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 net::HostCache* host_cache = | 282 net::HostCache* host_cache = |
| 270 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 283 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
| 271 if (host_cache) | 284 if (host_cache) |
| 272 host_cache->clear(); | 285 host_cache->clear(); |
| 273 } | 286 } |
| 274 // Clear all of the passively logged data. | 287 // Clear all of the passively logged data. |
| 275 // TODO(eroman): this is a bit heavy handed, really all we need to do is | 288 // TODO(eroman): this is a bit heavy handed, really all we need to do is |
| 276 // clear the data pertaining to off the record context. | 289 // clear the data pertaining to off the record context. |
| 277 globals_->net_log->passive_collector()->Clear(); | 290 globals_->net_log->passive_collector()->Clear(); |
| 278 } | 291 } |
| OLD | NEW |