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 #include "chrome/browser/task_manager/task_manager.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 // linking a network notification back to the object that initiated it. | 838 // linking a network notification back to the object that initiated it. |
839 TaskManager::Resource* resource = NULL; | 839 TaskManager::Resource* resource = NULL; |
840 for (ResourceProviderList::iterator iter = providers_.begin(); | 840 for (ResourceProviderList::iterator iter = providers_.begin(); |
841 iter != providers_.end(); ++iter) { | 841 iter != providers_.end(); ++iter) { |
842 resource = (*iter)->GetResource(param.origin_child_id, | 842 resource = (*iter)->GetResource(param.origin_child_id, |
843 param.render_process_host_child_id, | 843 param.render_process_host_child_id, |
844 param.routing_id); | 844 param.routing_id); |
845 if (resource) | 845 if (resource) |
846 break; | 846 break; |
847 } | 847 } |
| 848 |
848 if (resource == NULL) { | 849 if (resource == NULL) { |
849 // We may not have that resource anymore (example: close a tab while a | 850 // We can't match a resource to the notification. That might mean the |
850 // a network resource is being retrieved), in which case we just ignore the | 851 // tab that started a download was closed, or the request may have had |
851 // notification. | 852 // no originating resource associated with it in the first place. |
| 853 // We attribute orphaned/unaccounted activity to the Browser process. |
| 854 int browser_pid = base::GetCurrentProcId(); |
| 855 CHECK(param.origin_child_id != browser_pid); |
| 856 param.origin_child_id = browser_pid; |
| 857 param.render_process_host_child_id = param.routing_id = -1; |
| 858 BytesRead(param); |
852 return; | 859 return; |
853 } | 860 } |
854 | 861 |
855 // We do support network usage, mark the resource as such so it can report 0 | 862 // We do support network usage, mark the resource as such so it can report 0 |
856 // instead of N/A. | 863 // instead of N/A. |
857 if (!resource->SupportNetworkUsage()) | 864 if (!resource->SupportNetworkUsage()) |
858 resource->SetSupportNetworkUsage(); | 865 resource->SetSupportNetworkUsage(); |
859 | 866 |
860 ResourceValueMap::const_iterator iter_res = | 867 ResourceValueMap::const_iterator iter_res = |
861 current_byte_count_map_.find(resource); | 868 current_byte_count_map_.find(resource); |
(...skipping 18 matching lines...) Expand all Loading... |
880 const net::URLRequestStatus& status) { | 887 const net::URLRequestStatus& status) { |
881 } | 888 } |
882 | 889 |
883 void TaskManagerModel::OnJobRedirect(net::URLRequestJob* job, | 890 void TaskManagerModel::OnJobRedirect(net::URLRequestJob* job, |
884 const GURL& location, | 891 const GURL& location, |
885 int status_code) { | 892 int status_code) { |
886 } | 893 } |
887 | 894 |
888 void TaskManagerModel::OnBytesRead(net::URLRequestJob* job, const char* buf, | 895 void TaskManagerModel::OnBytesRead(net::URLRequestJob* job, const char* buf, |
889 int byte_count) { | 896 int byte_count) { |
| 897 // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
| 898 // have a render view associated. All other jobs will have -1 returned for |
| 899 // the render process child and routing ids - the jobs may still match a |
| 900 // resource based on their origin id, otherwise BytesRead() will attribute |
| 901 // the activity to the Browser resource. |
890 int render_process_host_child_id = -1, routing_id = -1; | 902 int render_process_host_child_id = -1, routing_id = -1; |
891 if (!ResourceDispatcherHost::RenderViewForRequest(job->request(), | 903 ResourceDispatcherHost::RenderViewForRequest(job->request(), |
892 &render_process_host_child_id, | 904 &render_process_host_child_id, |
893 &routing_id)) { | 905 &routing_id); |
894 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | |
895 // have a render view associated. Jobs from components such as the | |
896 // SearchProvider for autocomplete, have no associated view, so we can't | |
897 // correctly attribute the bandwidth they consume. | |
898 // TODO(wez): All jobs' resources should ideally be accountable, even if | |
899 // only by contributing to the Browser process' stats. | |
900 return; | |
901 } | |
902 | 906 |
903 // This happens in the IO thread, post it to the UI thread. | 907 // This happens in the IO thread, post it to the UI thread. |
904 int origin_child_id = | 908 int origin_child_id = |
905 chrome_browser_net::GetOriginProcessUniqueIDForRequest(job->request()); | 909 chrome_browser_net::GetOriginProcessUniqueIDForRequest(job->request()); |
906 BrowserThread::PostTask( | 910 BrowserThread::PostTask( |
907 BrowserThread::UI, FROM_HERE, | 911 BrowserThread::UI, FROM_HERE, |
908 NewRunnableMethod( | 912 NewRunnableMethod( |
909 this, | 913 this, |
910 &TaskManagerModel::BytesRead, | 914 &TaskManagerModel::BytesRead, |
911 BytesReadParam(origin_child_id, | 915 BytesReadParam(origin_child_id, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 1038 MetricsMap::const_iterator iter = metrics_map_.find(handle); |
1035 if (iter == metrics_map_.end()) | 1039 if (iter == metrics_map_.end()) |
1036 return false; | 1040 return false; |
1037 | 1041 |
1038 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) | 1042 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) |
1039 return false; | 1043 return false; |
1040 | 1044 |
1041 memory_usage_map_.insert(std::make_pair(handle, *usage)); | 1045 memory_usage_map_.insert(std::make_pair(handle, *usage)); |
1042 return true; | 1046 return true; |
1043 } | 1047 } |
OLD | NEW |