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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/i18n/number_formatting.h" | 8 #include "base/i18n/number_formatting.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 if (param.byte_count == 0) { | 832 if (param.byte_count == 0) { |
833 // Nothing to do if no bytes were actually read. | 833 // Nothing to do if no bytes were actually read. |
834 return; | 834 return; |
835 } | 835 } |
836 | 836 |
837 // TODO(jcampan): this should be improved once we have a better way of | 837 // TODO(jcampan): this should be improved once we have a better way of |
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_pid, |
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 |
849 if (resource == NULL) { | 849 if (resource == NULL) { |
850 // We can't match a resource to the notification. That might mean the | 850 // We can't match a resource to the notification. That might mean the |
851 // tab that started a download was closed, or the request may have had | 851 // tab that started a download was closed, or the request may have had |
852 // no originating resource associated with it in the first place. | 852 // no originating resource associated with it in the first place. |
853 // We attribute orphaned/unaccounted activity to the Browser process. | 853 // We attribute orphaned/unaccounted activity to the Browser process. |
854 int browser_pid = base::GetCurrentProcId(); | 854 CHECK(param.origin_pid || (param.render_process_host_child_id != -1)); |
855 CHECK(param.origin_child_id != browser_pid); | 855 param.origin_pid = 0; |
856 param.origin_child_id = browser_pid; | |
857 param.render_process_host_child_id = param.routing_id = -1; | 856 param.render_process_host_child_id = param.routing_id = -1; |
858 BytesRead(param); | 857 BytesRead(param); |
859 return; | 858 return; |
860 } | 859 } |
861 | 860 |
862 // We do support network usage, mark the resource as such so it can report 0 | 861 // We do support network usage, mark the resource as such so it can report 0 |
863 // instead of N/A. | 862 // instead of N/A. |
864 if (!resource->SupportNetworkUsage()) | 863 if (!resource->SupportNetworkUsage()) |
865 resource->SetSupportNetworkUsage(); | 864 resource->SetSupportNetworkUsage(); |
866 | 865 |
(...skipping 30 matching lines...) Expand all Loading... |
897 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | 896 // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
898 // have a render view associated. All other jobs will have -1 returned for | 897 // 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 | 898 // the render process child and routing ids - the jobs may still match a |
900 // resource based on their origin id, otherwise BytesRead() will attribute | 899 // resource based on their origin id, otherwise BytesRead() will attribute |
901 // the activity to the Browser resource. | 900 // the activity to the Browser resource. |
902 int render_process_host_child_id = -1, routing_id = -1; | 901 int render_process_host_child_id = -1, routing_id = -1; |
903 ResourceDispatcherHost::RenderViewForRequest(job->request(), | 902 ResourceDispatcherHost::RenderViewForRequest(job->request(), |
904 &render_process_host_child_id, | 903 &render_process_host_child_id, |
905 &routing_id); | 904 &routing_id); |
906 | 905 |
| 906 // Get the origin PID of the request's originator. This will only be set for |
| 907 // plugins - for renderer or browser initiated requests it will be zero. |
| 908 int origin_pid = |
| 909 chrome_browser_net::GetOriginPIDForRequest(job->request()); |
| 910 |
907 // This happens in the IO thread, post it to the UI thread. | 911 // This happens in the IO thread, post it to the UI thread. |
908 int origin_child_id = | |
909 chrome_browser_net::GetOriginProcessUniqueIDForRequest(job->request()); | |
910 BrowserThread::PostTask( | 912 BrowserThread::PostTask( |
911 BrowserThread::UI, FROM_HERE, | 913 BrowserThread::UI, FROM_HERE, |
912 NewRunnableMethod( | 914 NewRunnableMethod( |
913 this, | 915 this, |
914 &TaskManagerModel::BytesRead, | 916 &TaskManagerModel::BytesRead, |
915 BytesReadParam(origin_child_id, | 917 BytesReadParam(origin_pid, |
916 render_process_host_child_id, | 918 render_process_host_child_id, |
917 routing_id, byte_count))); | 919 routing_id, byte_count))); |
918 } | 920 } |
919 | 921 |
920 bool TaskManagerModel::GetProcessMetricsForRow( | 922 bool TaskManagerModel::GetProcessMetricsForRow( |
921 int row, base::ProcessMetrics** proc_metrics) const { | 923 int row, base::ProcessMetrics** proc_metrics) const { |
922 DCHECK(row < ResourceCount()); | 924 DCHECK(row < ResourceCount()); |
923 *proc_metrics = NULL; | 925 *proc_metrics = NULL; |
924 | 926 |
925 MetricsMap::const_iterator iter = | 927 MetricsMap::const_iterator iter = |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 1040 MetricsMap::const_iterator iter = metrics_map_.find(handle); |
1039 if (iter == metrics_map_.end()) | 1041 if (iter == metrics_map_.end()) |
1040 return false; | 1042 return false; |
1041 | 1043 |
1042 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) | 1044 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) |
1043 return false; | 1045 return false; |
1044 | 1046 |
1045 memory_usage_map_.insert(std::make_pair(handle, *usage)); | 1047 memory_usage_map_.insert(std::make_pair(handle, *usage)); |
1046 return true; | 1048 return true; |
1047 } | 1049 } |
OLD | NEW |