OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } // namespace | 299 } // namespace |
300 | 300 |
301 ResourceDispatcherHost::ResourceDispatcherHost( | 301 ResourceDispatcherHost::ResourceDispatcherHost( |
302 const ResourceQueue::DelegateSet& resource_queue_delegates) | 302 const ResourceQueue::DelegateSet& resource_queue_delegates) |
303 : ALLOW_THIS_IN_INITIALIZER_LIST( | 303 : ALLOW_THIS_IN_INITIALIZER_LIST( |
304 download_file_manager_(new DownloadFileManager(this))), | 304 download_file_manager_(new DownloadFileManager(this))), |
305 ALLOW_THIS_IN_INITIALIZER_LIST( | 305 ALLOW_THIS_IN_INITIALIZER_LIST( |
306 save_file_manager_(new SaveFileManager(this))), | 306 save_file_manager_(new SaveFileManager(this))), |
307 webkit_thread_(new WebKitThread), | 307 webkit_thread_(new WebKitThread), |
308 request_id_(-1), | 308 request_id_(-1), |
309 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), | 309 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
310 is_shutdown_(false), | 310 is_shutdown_(false), |
311 max_outstanding_requests_cost_per_process_( | 311 max_outstanding_requests_cost_per_process_( |
312 kMaxOutstandingRequestsCostPerProcess), | 312 kMaxOutstandingRequestsCostPerProcess), |
313 filter_(NULL), | 313 filter_(NULL), |
314 delegate_(NULL), | 314 delegate_(NULL), |
315 allow_cross_origin_auth_prompt_(false) { | 315 allow_cross_origin_auth_prompt_(false) { |
316 resource_queue_.Initialize(resource_queue_delegates); | 316 resource_queue_.Initialize(resource_queue_delegates); |
317 | 317 |
318 ANNOTATE_BENIGN_RACE( | 318 ANNOTATE_BENIGN_RACE( |
319 &last_user_gesture_time_, | 319 &last_user_gesture_time_, |
320 "We don't care about the precise value, see http://crbug.com/92889"); | 320 "We don't care about the precise value, see http://crbug.com/92889"); |
321 } | 321 } |
322 | 322 |
323 ResourceDispatcherHost::~ResourceDispatcherHost() { | 323 ResourceDispatcherHost::~ResourceDispatcherHost() { |
324 AsyncResourceHandler::GlobalCleanup(); | 324 AsyncResourceHandler::GlobalCleanup(); |
325 STLDeleteValues(&pending_requests_); | 325 STLDeleteValues(&pending_requests_); |
326 } | 326 } |
327 | 327 |
328 void ResourceDispatcherHost::Initialize() { | 328 void ResourceDispatcherHost::Initialize() { |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
330 webkit_thread_->Initialize(); | 330 webkit_thread_->Initialize(); |
331 BrowserThread::PostTask( | 331 BrowserThread::PostTask( |
332 BrowserThread::IO, FROM_HERE, | 332 BrowserThread::IO, FROM_HERE, |
333 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); | 333 base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); |
334 } | 334 } |
335 | 335 |
336 void ResourceDispatcherHost::Shutdown() { | 336 void ResourceDispatcherHost::Shutdown() { |
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
338 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, new ShutdownTask(this)); | 338 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, new ShutdownTask(this)); |
339 } | 339 } |
340 | 340 |
341 void ResourceDispatcherHost::SetRequestInfo( | 341 void ResourceDispatcherHost::SetRequestInfo( |
342 net::URLRequest* request, | 342 net::URLRequest* request, |
343 ResourceDispatcherHostRequestInfo* info) { | 343 ResourceDispatcherHostRequestInfo* info) { |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 return; | 992 return; |
993 } | 993 } |
994 info->set_pause_count(pause_count); | 994 info->set_pause_count(pause_count); |
995 | 995 |
996 VLOG(1) << "To pause (" << pause << "): " << i->second->url().spec(); | 996 VLOG(1) << "To pause (" << pause << "): " << i->second->url().spec(); |
997 | 997 |
998 // If we're resuming, kick the request to start reading again. Run the read | 998 // If we're resuming, kick the request to start reading again. Run the read |
999 // asynchronously to avoid recursion problems. | 999 // asynchronously to avoid recursion problems. |
1000 if (info->pause_count() == 0) { | 1000 if (info->pause_count() == 0) { |
1001 MessageLoop::current()->PostTask(FROM_HERE, | 1001 MessageLoop::current()->PostTask(FROM_HERE, |
1002 method_runner_.NewRunnableMethod( | 1002 base::Bind( |
1003 &ResourceDispatcherHost::ResumeRequest, global_id)); | 1003 &ResourceDispatcherHost::ResumeRequest, weak_factory_.GetWeakPtr(), |
| 1004 global_id)); |
1004 } | 1005 } |
1005 } | 1006 } |
1006 | 1007 |
1007 int ResourceDispatcherHost::GetOutstandingRequestsMemoryCost( | 1008 int ResourceDispatcherHost::GetOutstandingRequestsMemoryCost( |
1008 int child_id) const { | 1009 int child_id) const { |
1009 OutstandingRequestsMemoryCostMap::const_iterator entry = | 1010 OutstandingRequestsMemoryCostMap::const_iterator entry = |
1010 outstanding_requests_memory_cost_map_.find(child_id); | 1011 outstanding_requests_memory_cost_map_.find(child_id); |
1011 return (entry == outstanding_requests_memory_cost_map_.end()) ? | 1012 return (entry == outstanding_requests_memory_cost_map_.end()) ? |
1012 0 : entry->second; | 1013 0 : entry->second; |
1013 } | 1014 } |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 // This avoids a fast, large network request from monopolizing the IO | 1710 // This avoids a fast, large network request from monopolizing the IO |
1710 // thread and starving other IO operations from running. | 1711 // thread and starving other IO operations from running. |
1711 VLOG(1) << "OnReadCompleted postponing: \"" | 1712 VLOG(1) << "OnReadCompleted postponing: \"" |
1712 << request->url().spec() << "\"" | 1713 << request->url().spec() << "\"" |
1713 << " bytes_read = " << bytes_read; | 1714 << " bytes_read = " << bytes_read; |
1714 info->set_paused_read_bytes(bytes_read); | 1715 info->set_paused_read_bytes(bytes_read); |
1715 info->set_is_paused(true); | 1716 info->set_is_paused(true); |
1716 GlobalRequestID id(info->child_id(), info->request_id()); | 1717 GlobalRequestID id(info->child_id(), info->request_id()); |
1717 MessageLoop::current()->PostTask( | 1718 MessageLoop::current()->PostTask( |
1718 FROM_HERE, | 1719 FROM_HERE, |
1719 method_runner_.NewRunnableMethod( | 1720 base::Bind( |
1720 &ResourceDispatcherHost::ResumeRequest, id)); | 1721 &ResourceDispatcherHost::ResumeRequest, |
| 1722 weak_factory_.GetWeakPtr(), id)); |
1721 return; | 1723 return; |
1722 } | 1724 } |
1723 } | 1725 } |
1724 } | 1726 } |
1725 | 1727 |
1726 if (PauseRequestIfNeeded(info)) { | 1728 if (PauseRequestIfNeeded(info)) { |
1727 info->set_paused_read_bytes(bytes_read); | 1729 info->set_paused_read_bytes(bytes_read); |
1728 VLOG(1) << "OnReadCompleted (CompleteRead) pausing: \"" | 1730 VLOG(1) << "OnReadCompleted (CompleteRead) pausing: \"" |
1729 << request->url().spec() << "\"" | 1731 << request->url().spec() << "\"" |
1730 << " bytes_read = " << bytes_read; | 1732 << " bytes_read = " << bytes_read; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 | 1873 |
1872 int render_process_id, render_view_id; | 1874 int render_process_id, render_view_id; |
1873 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) | 1875 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) |
1874 return; | 1876 return; |
1875 | 1877 |
1876 // Notify the observers on the UI thread. | 1878 // Notify the observers on the UI thread. |
1877 ResourceRequestDetails* detail = new ResourceRequestDetails( | 1879 ResourceRequestDetails* detail = new ResourceRequestDetails( |
1878 request, GetCertID(request, child_id)); | 1880 request, GetCertID(request, child_id)); |
1879 BrowserThread::PostTask( | 1881 BrowserThread::PostTask( |
1880 BrowserThread::UI, FROM_HERE, | 1882 BrowserThread::UI, FROM_HERE, |
1881 NewRunnableFunction( | 1883 base::Bind( |
1882 &ResourceDispatcherHost::NotifyOnUI<ResourceRequestDetails>, | 1884 &ResourceDispatcherHost::NotifyOnUI<ResourceRequestDetails>, |
1883 static_cast<int>(content::NOTIFICATION_RESOURCE_RESPONSE_STARTED), | 1885 static_cast<int>(content::NOTIFICATION_RESOURCE_RESPONSE_STARTED), |
1884 render_process_id, render_view_id, detail)); | 1886 render_process_id, render_view_id, detail)); |
1885 } | 1887 } |
1886 | 1888 |
1887 void ResourceDispatcherHost::NotifyReceivedRedirect(net::URLRequest* request, | 1889 void ResourceDispatcherHost::NotifyReceivedRedirect(net::URLRequest* request, |
1888 int child_id, | 1890 int child_id, |
1889 const GURL& new_url) { | 1891 const GURL& new_url) { |
1890 int render_process_id, render_view_id; | 1892 int render_process_id, render_view_id; |
1891 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) | 1893 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) |
1892 return; | 1894 return; |
1893 | 1895 |
1894 // Notify the observers on the UI thread. | 1896 // Notify the observers on the UI thread. |
1895 ResourceRedirectDetails* detail = new ResourceRedirectDetails( | 1897 ResourceRedirectDetails* detail = new ResourceRedirectDetails( |
1896 request, GetCertID(request, child_id), new_url); | 1898 request, GetCertID(request, child_id), new_url); |
1897 BrowserThread::PostTask( | 1899 BrowserThread::PostTask( |
1898 BrowserThread::UI, FROM_HERE, | 1900 BrowserThread::UI, FROM_HERE, |
1899 NewRunnableFunction( | 1901 base::Bind( |
1900 &ResourceDispatcherHost::NotifyOnUI<ResourceRedirectDetails>, | 1902 &ResourceDispatcherHost::NotifyOnUI<ResourceRedirectDetails>, |
1901 static_cast<int>(content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT), | 1903 static_cast<int>(content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT), |
1902 render_process_id, render_view_id, detail)); | 1904 render_process_id, render_view_id, detail)); |
1903 } | 1905 } |
1904 | 1906 |
1905 template <class T> | 1907 template <class T> |
1906 void ResourceDispatcherHost::NotifyOnUI(int type, | 1908 void ResourceDispatcherHost::NotifyOnUI(int type, |
1907 int render_process_id, | 1909 int render_process_id, |
1908 int render_view_id, | 1910 int render_view_id, |
1909 T* detail) { | 1911 T* detail) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; | 2158 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; |
2157 } | 2159 } |
2158 | 2160 |
2159 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { | 2161 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { |
2160 return allow_cross_origin_auth_prompt_; | 2162 return allow_cross_origin_auth_prompt_; |
2161 } | 2163 } |
2162 | 2164 |
2163 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { | 2165 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { |
2164 allow_cross_origin_auth_prompt_ = value; | 2166 allow_cross_origin_auth_prompt_ = value; |
2165 } | 2167 } |
OLD | NEW |