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