OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_interface.h" | 5 #include "chrome/browser/task_manager/task_manager_interface.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/task_manager/sampling/task_manager_impl.h" | 8 #include "chrome/browser/task_manager/sampling/task_manager_impl.h" |
9 #include "chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h" | 9 #include "chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "components/prefs/pref_registry_simple.h" | 12 #include "components/prefs/pref_registry_simple.h" |
13 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/resource_request_info.h" |
15 | 16 |
16 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
17 #include "chrome/browser/ui/browser_dialogs.h" | 18 #include "chrome/browser/ui/browser_dialogs.h" |
18 #endif // defined(OS_MACOSX) | 19 #endif // defined(OS_MACOSX) |
19 | 20 |
20 namespace task_manager { | 21 namespace task_manager { |
21 | 22 |
| 23 namespace { |
| 24 BytesTransferredKey KeyForRequest(const net::URLRequest& request) { |
| 25 // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
| 26 // have an associated ResourceRequestInfo and a render frame associated. |
| 27 // All other jobs will have -1 returned for the render process child and |
| 28 // routing ids - the jobs may still match a resource based on their origin id, |
| 29 // otherwise BytesRead() will attribute the activity to the Browser resource. |
| 30 const content::ResourceRequestInfo* info = |
| 31 content::ResourceRequestInfo::ForRequest(&request); |
| 32 int child_id = -1; |
| 33 int route_id = -1; |
| 34 |
| 35 if (info) |
| 36 info->GetAssociatedRenderFrame(&child_id, &route_id); |
| 37 |
| 38 // Get the origin PID of the request's originator. This will only be set for |
| 39 // plugins - for renderer or browser initiated requests it will be zero. |
| 40 int origin_pid = info ? info->GetOriginPID() : 0; |
| 41 return {origin_pid, child_id, route_id}; |
| 42 } |
| 43 } // namespace |
| 44 |
22 // static | 45 // static |
23 void TaskManagerInterface::RegisterPrefs(PrefRegistrySimple* registry) { | 46 void TaskManagerInterface::RegisterPrefs(PrefRegistrySimple* registry) { |
24 registry->RegisterDictionaryPref(prefs::kTaskManagerWindowPlacement); | 47 registry->RegisterDictionaryPref(prefs::kTaskManagerWindowPlacement); |
25 registry->RegisterDictionaryPref(prefs::kTaskManagerColumnVisibility); | 48 registry->RegisterDictionaryPref(prefs::kTaskManagerColumnVisibility); |
26 registry->RegisterBooleanPref(prefs::kTaskManagerEndProcessEnabled, true); | 49 registry->RegisterBooleanPref(prefs::kTaskManagerEndProcessEnabled, true); |
27 } | 50 } |
28 | 51 |
29 // static | 52 // static |
30 bool TaskManagerInterface::IsEndProcessEnabled() { | 53 bool TaskManagerInterface::IsEndProcessEnabled() { |
31 PrefService* state = g_browser_process->local_state(); | 54 PrefService* state = g_browser_process->local_state(); |
32 return !state || state->GetBoolean(prefs::kTaskManagerEndProcessEnabled); | 55 return !state || state->GetBoolean(prefs::kTaskManagerEndProcessEnabled); |
33 } | 56 } |
34 | 57 |
35 // static | 58 // static |
36 TaskManagerInterface* TaskManagerInterface::GetTaskManager() { | 59 TaskManagerInterface* TaskManagerInterface::GetTaskManager() { |
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
38 | 61 |
39 return TaskManagerImpl::GetInstance(); | 62 return TaskManagerImpl::GetInstance(); |
40 } | 63 } |
41 | 64 |
42 // static | 65 // static |
43 void TaskManagerInterface::OnRawBytesRead(const net::URLRequest& request, | 66 void TaskManagerInterface::OnRawBytesRead(const net::URLRequest& request, |
44 int64_t bytes_read) { | 67 int64_t bytes_read) { |
45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 68 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
46 | 69 BytesTransferredKey key = KeyForRequest(request); |
47 TaskManagerIoThreadHelper::OnRawBytesRead(request, bytes_read); | 70 TaskManagerIoThreadHelper::OnRawBytesTransferred(key, bytes_read, |
| 71 0 /*bytes_sent*/); |
48 } | 72 } |
49 | 73 |
50 // static | 74 // static |
51 void TaskManagerInterface::OnRawBytesSent(const net::URLRequest& request, | 75 void TaskManagerInterface::OnRawBytesSent(const net::URLRequest& request, |
52 int64_t bytes_sent) { | 76 int64_t bytes_sent) { |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 77 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
54 TaskManagerIoThreadHelper::OnRawBytesSent(request, bytes_sent); | 78 BytesTransferredKey key = KeyForRequest(request); |
| 79 TaskManagerIoThreadHelper::OnRawBytesTransferred(key, 0 /*bytes_read*/, |
| 80 bytes_sent); |
55 } | 81 } |
56 | 82 |
57 void TaskManagerInterface::AddObserver(TaskManagerObserver* observer) { | 83 void TaskManagerInterface::AddObserver(TaskManagerObserver* observer) { |
58 observers_.AddObserver(observer); | 84 observers_.AddObserver(observer); |
59 observer->observed_task_manager_ = this; | 85 observer->observed_task_manager_ = this; |
60 | 86 |
61 ResourceFlagsAdded(observer->desired_resources_flags()); | 87 ResourceFlagsAdded(observer->desired_resources_flags()); |
62 | 88 |
63 base::TimeDelta current_refresh_time = GetCurrentRefreshTime(); | 89 base::TimeDelta current_refresh_time = GetCurrentRefreshTime(); |
64 if (current_refresh_time == base::TimeDelta::Max()) { | 90 if (current_refresh_time == base::TimeDelta::Max()) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 188 } |
163 | 189 |
164 void TaskManagerInterface::ScheduleRefresh(base::TimeDelta refresh_time) { | 190 void TaskManagerInterface::ScheduleRefresh(base::TimeDelta refresh_time) { |
165 refresh_timer_->Start(FROM_HERE, | 191 refresh_timer_->Start(FROM_HERE, |
166 refresh_time, | 192 refresh_time, |
167 base::Bind(&TaskManagerInterface::Refresh, | 193 base::Bind(&TaskManagerInterface::Refresh, |
168 base::Unretained(this))); | 194 base::Unretained(this))); |
169 } | 195 } |
170 | 196 |
171 } // namespace task_manager | 197 } // namespace task_manager |
OLD | NEW |