OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 using content::GlobalRequestID; | 88 using content::GlobalRequestID; |
89 using content::ResourceResponse; | 89 using content::ResourceResponse; |
90 using content::WebContents; | 90 using content::WebContents; |
91 using content::WorkerServiceImpl; | 91 using content::WorkerServiceImpl; |
92 using webkit_blob::DeletableFileReference; | 92 using webkit_blob::DeletableFileReference; |
93 | 93 |
94 // ---------------------------------------------------------------------------- | 94 // ---------------------------------------------------------------------------- |
95 | 95 |
96 namespace { | 96 namespace { |
97 | 97 |
| 98 static ResourceDispatcherHost* g_resource_dispatcher_host; |
| 99 |
98 // The interval for calls to ResourceDispatcherHost::UpdateLoadStates | 100 // The interval for calls to ResourceDispatcherHost::UpdateLoadStates |
99 const int kUpdateLoadStatesIntervalMsec = 100; | 101 const int kUpdateLoadStatesIntervalMsec = 100; |
100 | 102 |
101 // Maximum number of pending data messages sent to the renderer at any | 103 // Maximum number of pending data messages sent to the renderer at any |
102 // given time for a given request. | 104 // given time for a given request. |
103 const int kMaxPendingDataMessages = 20; | 105 const int kMaxPendingDataMessages = 20; |
104 | 106 |
105 // Maximum byte "cost" of all the outstanding requests for a renderer. | 107 // Maximum byte "cost" of all the outstanding requests for a renderer. |
106 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. | 108 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. |
107 // This bound is 25MB, which allows for around 6000 outstanding requests. | 109 // This bound is 25MB, which allows for around 6000 outstanding requests. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 289 |
288 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { | 290 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { |
289 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, | 291 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, |
290 render_view_id); | 292 render_view_id); |
291 if (rvh) | 293 if (rvh) |
292 rvh->OnSwapOutACK(); | 294 rvh->OnSwapOutACK(); |
293 } | 295 } |
294 | 296 |
295 } // namespace | 297 } // namespace |
296 | 298 |
297 ResourceDispatcherHost::ResourceDispatcherHost( | 299 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
298 const ResourceQueue::DelegateSet& resource_queue_delegates) | 300 return g_resource_dispatcher_host; |
299 : ALLOW_THIS_IN_INITIALIZER_LIST( | 301 } |
| 302 |
| 303 ResourceDispatcherHost::ResourceDispatcherHost() |
| 304 : temporarily_delegate_set_(NULL), |
| 305 ALLOW_THIS_IN_INITIALIZER_LIST( |
300 download_file_manager_(new DownloadFileManager(this, NULL))), | 306 download_file_manager_(new DownloadFileManager(this, NULL))), |
301 ALLOW_THIS_IN_INITIALIZER_LIST( | 307 ALLOW_THIS_IN_INITIALIZER_LIST( |
302 save_file_manager_(new SaveFileManager(this))), | 308 save_file_manager_(new SaveFileManager(this))), |
303 request_id_(-1), | 309 request_id_(-1), |
304 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 310 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
305 is_shutdown_(false), | 311 is_shutdown_(false), |
306 max_outstanding_requests_cost_per_process_( | 312 max_outstanding_requests_cost_per_process_( |
307 kMaxOutstandingRequestsCostPerProcess), | 313 kMaxOutstandingRequestsCostPerProcess), |
308 filter_(NULL), | 314 filter_(NULL), |
309 delegate_(NULL), | 315 delegate_(NULL), |
310 allow_cross_origin_auth_prompt_(false) { | 316 allow_cross_origin_auth_prompt_(false) { |
| 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 318 DCHECK(!g_resource_dispatcher_host); |
| 319 g_resource_dispatcher_host = this; |
| 320 |
| 321 ResourceQueue::DelegateSet resource_queue_delegates; |
| 322 temporarily_delegate_set_ = &resource_queue_delegates; |
| 323 content::GetContentClient()->browser()->ResourceDispatcherHostCreated(); |
311 resource_queue_.Initialize(resource_queue_delegates); | 324 resource_queue_.Initialize(resource_queue_delegates); |
| 325 temporarily_delegate_set_ = NULL; |
312 | 326 |
313 ANNOTATE_BENIGN_RACE( | 327 ANNOTATE_BENIGN_RACE( |
314 &last_user_gesture_time_, | 328 &last_user_gesture_time_, |
315 "We don't care about the precise value, see http://crbug.com/92889"); | 329 "We don't care about the precise value, see http://crbug.com/92889"); |
| 330 |
| 331 BrowserThread::PostTask( |
| 332 BrowserThread::IO, FROM_HERE, |
| 333 base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); |
316 } | 334 } |
317 | 335 |
318 ResourceDispatcherHost::~ResourceDispatcherHost() { | 336 ResourceDispatcherHost::~ResourceDispatcherHost() { |
| 337 DCHECK(g_resource_dispatcher_host); |
| 338 g_resource_dispatcher_host = NULL; |
319 AsyncResourceHandler::GlobalCleanup(); | 339 AsyncResourceHandler::GlobalCleanup(); |
320 for (PendingRequestList::const_iterator i = pending_requests_.begin(); | 340 for (PendingRequestList::const_iterator i = pending_requests_.begin(); |
321 i != pending_requests_.end(); ++i) { | 341 i != pending_requests_.end(); ++i) { |
322 transferred_navigations_.erase(i->first); | 342 transferred_navigations_.erase(i->first); |
323 } | 343 } |
324 STLDeleteValues(&pending_requests_); | 344 STLDeleteValues(&pending_requests_); |
325 DCHECK(transferred_navigations_.empty()); | 345 DCHECK(transferred_navigations_.empty()); |
326 } | 346 } |
327 | 347 |
328 void ResourceDispatcherHost::Initialize() { | |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
330 BrowserThread::PostTask( | |
331 BrowserThread::IO, FROM_HERE, | |
332 base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); | |
333 } | |
334 | |
335 void ResourceDispatcherHost::Shutdown() { | 348 void ResourceDispatcherHost::Shutdown() { |
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
337 BrowserThread::PostTask(BrowserThread::IO, | 350 BrowserThread::PostTask(BrowserThread::IO, |
338 FROM_HERE, | 351 FROM_HERE, |
339 base::Bind(&ResourceDispatcherHost::OnShutdown, | 352 base::Bind(&ResourceDispatcherHost::OnShutdown, |
340 base::Unretained(this))); | 353 base::Unretained(this))); |
341 } | 354 } |
342 | 355 |
| 356 void ResourceDispatcherHost::AddResourceQueueDelegate( |
| 357 ResourceQueueDelegate* delegate) { |
| 358 temporarily_delegate_set_->insert(delegate); |
| 359 } |
| 360 |
343 void ResourceDispatcherHost::SetRequestInfo( | 361 void ResourceDispatcherHost::SetRequestInfo( |
344 net::URLRequest* request, | 362 net::URLRequest* request, |
345 ResourceDispatcherHostRequestInfo* info) { | 363 ResourceDispatcherHostRequestInfo* info) { |
346 request->SetUserData(NULL, info); | 364 request->SetUserData(NULL, info); |
347 } | 365 } |
348 | 366 |
349 void ResourceDispatcherHost::OnShutdown() { | 367 void ResourceDispatcherHost::OnShutdown() { |
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
351 is_shutdown_ = true; | 369 is_shutdown_ = true; |
352 resource_queue_.Shutdown(); | 370 resource_queue_.Shutdown(); |
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 const GlobalRequestID& transferred_request_id, | 2274 const GlobalRequestID& transferred_request_id, |
2257 net::URLRequest* ransferred_request) { | 2275 net::URLRequest* ransferred_request) { |
2258 transferred_navigations_[transferred_request_id] = ransferred_request; | 2276 transferred_navigations_[transferred_request_id] = ransferred_request; |
2259 } | 2277 } |
2260 | 2278 |
2261 bool ResourceDispatcherHost::IsTransferredNavigation( | 2279 bool ResourceDispatcherHost::IsTransferredNavigation( |
2262 const content::GlobalRequestID& transferred_request_id) const { | 2280 const content::GlobalRequestID& transferred_request_id) const { |
2263 return transferred_navigations_.find(transferred_request_id) != | 2281 return transferred_navigations_.find(transferred_request_id) != |
2264 transferred_navigations_.end(); | 2282 transferred_navigations_.end(); |
2265 } | 2283 } |
OLD | NEW |