| 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_management/providers/web_contents/renderer_task.h" | 5 #include "chrome/browser/task_management/providers/web_contents/renderer_task.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 if (index != std::string::npos) | 52 if (index != std::string::npos) |
| 53 return cache.GetNameOfProfileAtIndex(index); | 53 return cache.GetNameOfProfileAtIndex(index); |
| 54 | 54 |
| 55 return base::string16(); | 55 return base::string16(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 inline bool IsRendererResourceSamplingDisabled(int64 flags) { | 58 inline bool IsRendererResourceSamplingDisabled(int64 flags) { |
| 59 return (flags & (REFRESH_TYPE_V8_MEMORY | REFRESH_TYPE_WEBCACHE_STATS)) == 0; | 59 return (flags & (REFRESH_TYPE_V8_MEMORY | REFRESH_TYPE_WEBCACHE_STATS)) == 0; |
| 60 } | 60 } |
| 61 | 61 |
| 62 std::string GetRapporSampleName(content::WebContents* web_contents) { |
| 63 return web_contents->GetVisibleURL().GetOrigin().spec(); |
| 64 } |
| 65 |
| 62 } // namespace | 66 } // namespace |
| 63 | 67 |
| 64 RendererTask::RendererTask(const base::string16& title, | 68 RendererTask::RendererTask(const base::string16& title, |
| 65 const gfx::ImageSkia* icon, | 69 const gfx::ImageSkia* icon, |
| 66 content::WebContents* web_contents, | 70 content::WebContents* web_contents, |
| 67 content::RenderProcessHost* render_process_host) | 71 content::RenderProcessHost* render_process_host) |
| 68 : Task(title, icon, render_process_host->GetHandle()), | 72 : Task(title, |
| 73 GetRapporSampleName(web_contents), |
| 74 icon, |
| 75 render_process_host->GetHandle()), |
| 69 web_contents_(web_contents), | 76 web_contents_(web_contents), |
| 70 render_process_host_(render_process_host), | 77 render_process_host_(render_process_host), |
| 71 renderer_resources_sampler_( | 78 renderer_resources_sampler_( |
| 72 CreateRendererResourcesSampler(render_process_host_)), | 79 CreateRendererResourcesSampler(render_process_host_)), |
| 73 render_process_id_(render_process_host_->GetID()), | 80 render_process_id_(render_process_host_->GetID()), |
| 74 v8_memory_allocated_(0), | 81 v8_memory_allocated_(0), |
| 75 v8_memory_used_(0), | 82 v8_memory_used_(0), |
| 76 webcache_stats_(), | 83 webcache_stats_(), |
| 77 profile_name_(GetRendererProfileName(render_process_host_)) { | 84 profile_name_(GetRendererProfileName(render_process_host_)) { |
| 78 // All renderer tasks are capable of reporting network usage, so the default | 85 // All renderer tasks are capable of reporting network usage, so the default |
| 79 // invalid value of -1 doesn't apply here. | 86 // invalid value of -1 doesn't apply here. |
| 80 OnNetworkBytesRead(0); | 87 OnNetworkBytesRead(0); |
| 81 | 88 |
| 82 // Tag the web_contents with a |ContentFaviconDriver| (if needed) so that | 89 // Tag the web_contents with a |ContentFaviconDriver| (if needed) so that |
| 83 // we can use it to observe favicons changes. | 90 // we can use it to observe favicons changes. |
| 84 favicon::CreateContentFaviconDriverForWebContents(web_contents); | 91 favicon::CreateContentFaviconDriverForWebContents(web_contents); |
| 85 favicon::ContentFaviconDriver::FromWebContents(web_contents)->AddObserver( | 92 favicon::ContentFaviconDriver::FromWebContents(web_contents)->AddObserver( |
| 86 this); | 93 this); |
| 87 } | 94 } |
| 88 | 95 |
| 89 RendererTask::~RendererTask() { | 96 RendererTask::~RendererTask() { |
| 90 favicon::ContentFaviconDriver::FromWebContents(web_contents())-> | 97 favicon::ContentFaviconDriver::FromWebContents(web_contents())-> |
| 91 RemoveObserver(this); | 98 RemoveObserver(this); |
| 92 } | 99 } |
| 93 | 100 |
| 101 void RendererTask::UpdateRapporSampleName() { |
| 102 set_rappor_sample_name(GetRapporSampleName(web_contents())); |
| 103 } |
| 104 |
| 94 void RendererTask::Activate() { | 105 void RendererTask::Activate() { |
| 95 if (!web_contents_->GetDelegate()) | 106 if (!web_contents_->GetDelegate()) |
| 96 return; | 107 return; |
| 97 | 108 |
| 98 web_contents_->GetDelegate()->ActivateContents(web_contents_); | 109 web_contents_->GetDelegate()->ActivateContents(web_contents_); |
| 99 } | 110 } |
| 100 | 111 |
| 101 void RendererTask::Refresh(const base::TimeDelta& update_interval, | 112 void RendererTask::Refresh(const base::TimeDelta& update_interval, |
| 102 int64 refresh_flags) { | 113 int64 refresh_flags) { |
| 103 Task::Refresh(update_interval, refresh_flags); | 114 Task::Refresh(update_interval, refresh_flags); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 if (is_incognito) | 229 if (is_incognito) |
| 219 message_id = IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; | 230 message_id = IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; |
| 220 else | 231 else |
| 221 message_id = IDS_TASK_MANAGER_EXTENSION_PREFIX; | 232 message_id = IDS_TASK_MANAGER_EXTENSION_PREFIX; |
| 222 } | 233 } |
| 223 | 234 |
| 224 return l10n_util::GetStringFUTF16(message_id, title); | 235 return l10n_util::GetStringFUTF16(message_id, title); |
| 225 } | 236 } |
| 226 | 237 |
| 227 } // namespace task_management | 238 } // namespace task_management |
| OLD | NEW |