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 if (!g_resource_dispatcher_host) |
299 : ALLOW_THIS_IN_INITIALIZER_LIST( | 301 g_resource_dispatcher_host = new ResourceDispatcherHost(); |
Jói
2012/01/10 10:58:57
The assignment is not needed, since the ResourceDi
jam
2012/01/10 17:34:08
Done.
| |
302 return g_resource_dispatcher_host; | |
303 } | |
304 | |
305 bool ResourceDispatcherHost::IsCreated() { | |
306 return !!g_resource_dispatcher_host; | |
307 } | |
308 | |
309 ResourceDispatcherHost::ResourceDispatcherHost() | |
310 : temporarily_delegate_set_(NULL), | |
311 ALLOW_THIS_IN_INITIALIZER_LIST( | |
300 download_file_manager_(new DownloadFileManager(this, NULL))), | 312 download_file_manager_(new DownloadFileManager(this, NULL))), |
301 ALLOW_THIS_IN_INITIALIZER_LIST( | 313 ALLOW_THIS_IN_INITIALIZER_LIST( |
302 save_file_manager_(new SaveFileManager(this))), | 314 save_file_manager_(new SaveFileManager(this))), |
303 request_id_(-1), | 315 request_id_(-1), |
304 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 316 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
305 is_shutdown_(false), | 317 is_shutdown_(false), |
306 max_outstanding_requests_cost_per_process_( | 318 max_outstanding_requests_cost_per_process_( |
307 kMaxOutstandingRequestsCostPerProcess), | 319 kMaxOutstandingRequestsCostPerProcess), |
308 filter_(NULL), | 320 filter_(NULL), |
309 delegate_(NULL), | 321 delegate_(NULL), |
310 allow_cross_origin_auth_prompt_(false) { | 322 allow_cross_origin_auth_prompt_(false) { |
323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
324 DCHECK(!g_resource_dispatcher_host); | |
325 g_resource_dispatcher_host = this; | |
326 | |
327 ResourceQueue::DelegateSet resource_queue_delegates; | |
328 temporarily_delegate_set_ = &resource_queue_delegates; | |
329 content::GetContentClient()->browser()->ResourceDispatcherHostCreated(); | |
311 resource_queue_.Initialize(resource_queue_delegates); | 330 resource_queue_.Initialize(resource_queue_delegates); |
331 temporarily_delegate_set_ = NULL; | |
312 | 332 |
313 ANNOTATE_BENIGN_RACE( | 333 ANNOTATE_BENIGN_RACE( |
314 &last_user_gesture_time_, | 334 &last_user_gesture_time_, |
315 "We don't care about the precise value, see http://crbug.com/92889"); | 335 "We don't care about the precise value, see http://crbug.com/92889"); |
336 | |
337 BrowserThread::PostTask( | |
338 BrowserThread::IO, FROM_HERE, | |
339 base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); | |
316 } | 340 } |
317 | 341 |
318 ResourceDispatcherHost::~ResourceDispatcherHost() { | 342 ResourceDispatcherHost::~ResourceDispatcherHost() { |
343 DCHECK(g_resource_dispatcher_host); | |
344 g_resource_dispatcher_host = NULL; | |
319 AsyncResourceHandler::GlobalCleanup(); | 345 AsyncResourceHandler::GlobalCleanup(); |
320 for (PendingRequestList::const_iterator i = pending_requests_.begin(); | 346 for (PendingRequestList::const_iterator i = pending_requests_.begin(); |
321 i != pending_requests_.end(); ++i) { | 347 i != pending_requests_.end(); ++i) { |
322 transferred_navigations_.erase(i->first); | 348 transferred_navigations_.erase(i->first); |
323 } | 349 } |
324 STLDeleteValues(&pending_requests_); | 350 STLDeleteValues(&pending_requests_); |
325 DCHECK(transferred_navigations_.empty()); | 351 DCHECK(transferred_navigations_.empty()); |
326 } | 352 } |
327 | 353 |
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() { | 354 void ResourceDispatcherHost::Shutdown() { |
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
337 BrowserThread::PostTask(BrowserThread::IO, | 356 BrowserThread::PostTask(BrowserThread::IO, |
338 FROM_HERE, | 357 FROM_HERE, |
339 base::Bind(&ResourceDispatcherHost::OnShutdown, | 358 base::Bind(&ResourceDispatcherHost::OnShutdown, |
340 base::Unretained(this))); | 359 base::Unretained(this))); |
341 } | 360 } |
342 | 361 |
362 void ResourceDispatcherHost::AddResourceQueueDelegate( | |
363 ResourceQueueDelegate* delegate) { | |
364 temporarily_delegate_set_->insert(delegate); | |
365 } | |
366 | |
343 void ResourceDispatcherHost::SetRequestInfo( | 367 void ResourceDispatcherHost::SetRequestInfo( |
344 net::URLRequest* request, | 368 net::URLRequest* request, |
345 ResourceDispatcherHostRequestInfo* info) { | 369 ResourceDispatcherHostRequestInfo* info) { |
346 request->SetUserData(NULL, info); | 370 request->SetUserData(NULL, info); |
347 } | 371 } |
348 | 372 |
349 void ResourceDispatcherHost::OnShutdown() { | 373 void ResourceDispatcherHost::OnShutdown() { |
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
351 is_shutdown_ = true; | 375 is_shutdown_ = true; |
352 resource_queue_.Shutdown(); | 376 resource_queue_.Shutdown(); |
(...skipping 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2248 const GlobalRequestID& transferred_request_id, | 2272 const GlobalRequestID& transferred_request_id, |
2249 net::URLRequest* ransferred_request) { | 2273 net::URLRequest* ransferred_request) { |
2250 transferred_navigations_[transferred_request_id] = ransferred_request; | 2274 transferred_navigations_[transferred_request_id] = ransferred_request; |
2251 } | 2275 } |
2252 | 2276 |
2253 bool ResourceDispatcherHost::IsTransferredNavigation( | 2277 bool ResourceDispatcherHost::IsTransferredNavigation( |
2254 const content::GlobalRequestID& transferred_request_id) const { | 2278 const content::GlobalRequestID& transferred_request_id) const { |
2255 return transferred_navigations_.find(transferred_request_id) != | 2279 return transferred_navigations_.find(transferred_request_id) != |
2256 transferred_navigations_.end(); | 2280 transferred_navigations_.end(); |
2257 } | 2281 } |
OLD | NEW |