| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 const content::RenderProcessHost* render_process_host) { | 42 const content::RenderProcessHost* render_process_host) { |
| 43 Profile* profile = | 43 Profile* profile = |
| 44 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); | 44 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
| 45 return Task::GetProfileNameFromProfile(profile); | 45 return Task::GetProfileNameFromProfile(profile); |
| 46 } | 46 } |
| 47 | 47 |
| 48 inline bool IsRendererResourceSamplingDisabled(int64 flags) { | 48 inline bool IsRendererResourceSamplingDisabled(int64 flags) { |
| 49 return (flags & (REFRESH_TYPE_V8_MEMORY | REFRESH_TYPE_WEBCACHE_STATS)) == 0; | 49 return (flags & (REFRESH_TYPE_V8_MEMORY | REFRESH_TYPE_WEBCACHE_STATS)) == 0; |
| 50 } | 50 } |
| 51 | 51 |
| 52 std::string GetRapporSampleName(content::WebContents* web_contents) { |
| 53 return web_contents->GetVisibleURL().GetOrigin().spec(); |
| 54 } |
| 55 |
| 52 } // namespace | 56 } // namespace |
| 53 | 57 |
| 54 RendererTask::RendererTask(const base::string16& title, | 58 RendererTask::RendererTask(const base::string16& title, |
| 55 const gfx::ImageSkia* icon, | 59 const gfx::ImageSkia* icon, |
| 56 content::WebContents* web_contents, | 60 content::WebContents* web_contents, |
| 57 content::RenderProcessHost* render_process_host) | 61 content::RenderProcessHost* render_process_host) |
| 58 : Task(title, icon, render_process_host->GetHandle()), | 62 : Task(title, |
| 63 GetRapporSampleName(web_contents), |
| 64 icon, |
| 65 render_process_host->GetHandle()), |
| 59 web_contents_(web_contents), | 66 web_contents_(web_contents), |
| 60 render_process_host_(render_process_host), | 67 render_process_host_(render_process_host), |
| 61 renderer_resources_sampler_( | 68 renderer_resources_sampler_( |
| 62 CreateRendererResourcesSampler(render_process_host_)), | 69 CreateRendererResourcesSampler(render_process_host_)), |
| 63 render_process_id_(render_process_host_->GetID()), | 70 render_process_id_(render_process_host_->GetID()), |
| 64 v8_memory_allocated_(0), | 71 v8_memory_allocated_(0), |
| 65 v8_memory_used_(0), | 72 v8_memory_used_(0), |
| 66 webcache_stats_(), | 73 webcache_stats_(), |
| 67 profile_name_(GetRendererProfileName(render_process_host_)) { | 74 profile_name_(GetRendererProfileName(render_process_host_)) { |
| 68 // All renderer tasks are capable of reporting network usage, so the default | 75 // All renderer tasks are capable of reporting network usage, so the default |
| 69 // invalid value of -1 doesn't apply here. | 76 // invalid value of -1 doesn't apply here. |
| 70 OnNetworkBytesRead(0); | 77 OnNetworkBytesRead(0); |
| 71 | 78 |
| 72 // Tag the web_contents with a |ContentFaviconDriver| (if needed) so that | 79 // Tag the web_contents with a |ContentFaviconDriver| (if needed) so that |
| 73 // we can use it to observe favicons changes. | 80 // we can use it to observe favicons changes. |
| 74 favicon::CreateContentFaviconDriverForWebContents(web_contents); | 81 favicon::CreateContentFaviconDriverForWebContents(web_contents); |
| 75 favicon::ContentFaviconDriver::FromWebContents(web_contents)->AddObserver( | 82 favicon::ContentFaviconDriver::FromWebContents(web_contents)->AddObserver( |
| 76 this); | 83 this); |
| 77 } | 84 } |
| 78 | 85 |
| 79 RendererTask::~RendererTask() { | 86 RendererTask::~RendererTask() { |
| 80 favicon::ContentFaviconDriver::FromWebContents(web_contents())-> | 87 favicon::ContentFaviconDriver::FromWebContents(web_contents())-> |
| 81 RemoveObserver(this); | 88 RemoveObserver(this); |
| 82 } | 89 } |
| 83 | 90 |
| 91 void RendererTask::UpdateRapporSampleName() { |
| 92 set_rappor_sample_name(GetRapporSampleName(web_contents())); |
| 93 } |
| 94 |
| 84 void RendererTask::Activate() { | 95 void RendererTask::Activate() { |
| 85 if (!web_contents_->GetDelegate()) | 96 if (!web_contents_->GetDelegate()) |
| 86 return; | 97 return; |
| 87 | 98 |
| 88 web_contents_->GetDelegate()->ActivateContents(web_contents_); | 99 web_contents_->GetDelegate()->ActivateContents(web_contents_); |
| 89 } | 100 } |
| 90 | 101 |
| 91 void RendererTask::Refresh(const base::TimeDelta& update_interval, | 102 void RendererTask::Refresh(const base::TimeDelta& update_interval, |
| 92 int64 refresh_flags) { | 103 int64 refresh_flags) { |
| 93 Task::Refresh(update_interval, refresh_flags); | 104 Task::Refresh(update_interval, refresh_flags); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 if (is_incognito) | 220 if (is_incognito) |
| 210 message_id = IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; | 221 message_id = IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; |
| 211 else | 222 else |
| 212 message_id = IDS_TASK_MANAGER_EXTENSION_PREFIX; | 223 message_id = IDS_TASK_MANAGER_EXTENSION_PREFIX; |
| 213 } | 224 } |
| 214 | 225 |
| 215 return l10n_util::GetStringFUTF16(message_id, title); | 226 return l10n_util::GetStringFUTF16(message_id, title); |
| 216 } | 227 } |
| 217 | 228 |
| 218 } // namespace task_management | 229 } // namespace task_management |
| OLD | NEW |