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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_
8 #include "chrome/browser/task_management/providers/task.h"
9 #include "content/public/browser/navigation_entry.h"
11 class ProcessResourceUsage
;
14 class RenderProcessHost
;
16 } // namespace content
18 namespace task_management
{
20 // Defines an abstract base class for various types of renderer process tasks
21 // such as background contents, tab contents, ... etc.
22 class RendererTask
: public Task
{
24 RendererTask(const base::string16
& title
,
25 const gfx::ImageSkia
* icon
,
26 content::WebContents
* web_contents
);
27 ~RendererTask() override
;
29 // An abstract method that will be called when the event
30 // |WebContentsObserver::TitleWasSet()| occurs. This gives the freedom to
31 // concrete tasks to adjust the title however they need to before they set it.
32 virtual void OnTitleChanged(content::NavigationEntry
* entry
) = 0;
34 // An abstract method that will be called when the event
35 // |WebContentsObserver::DidUpdateFaviconURL()| occurs, so that concrete tasks
36 // can update their favicons.
37 virtual void OnFaviconChanged() = 0;
39 // task_management::Task:
40 void Activate() override
;
41 void Refresh(const base::TimeDelta
& update_interval
,
42 int64 refresh_flags
) override
;
43 Type
GetType() const override
;
44 int GetChildProcessUniqueID() const override
;
45 base::string16
GetProfileName() const override
;
46 int64
GetV8MemoryAllocated() const override
;
47 int64
GetV8MemoryUsed() const override
;
48 bool ReportsWebCacheStats() const override
;
49 blink::WebCache::ResourceTypeStats
GetWebCacheStats() const override
;
52 // Returns the title of the given |web_contents|.
53 static base::string16
GetTitleFromWebContents(
54 content::WebContents
* web_contents
);
56 // Returns the favicon of the given |web_contents| if any, and returns
57 // |nullptr| otherwise.
58 static const gfx::ImageSkia
* GetFaviconFromWebContents(
59 content::WebContents
* web_contents
);
61 // Prefixes the given renderer |title| with the appropriate string based on
62 // whether it's an app, an extension, or incognito.
63 static const base::string16
PrefixRendererTitle(const base::string16
& title
,
68 content::WebContents
* web_contents() const { return web_contents_
; }
71 // The WebContents of the task this object represents.
72 content::WebContents
* web_contents_
;
74 // The render process host of the task this object represents.
75 content::RenderProcessHost
* render_process_host_
;
77 // The Mojo service wrapper that will provide us with the V8 memory usage and
78 // the WebCache resource stats of the render process represented by this
80 scoped_ptr
<ProcessResourceUsage
> renderer_resources_sampler_
;
82 // The unique ID of the RenderProcessHost.
83 const int render_process_id_
;
85 // The allocated and used V8 memory (in bytes).
86 int64 v8_memory_allocated_
;
87 int64 v8_memory_used_
;
89 // The WebKit resource cache statistics for this renderer.
90 blink::WebCache::ResourceTypeStats webcache_stats_
;
92 // The profile name associated with the browser context of the render view
94 const base::string16 profile_name_
;
96 DISALLOW_COPY_AND_ASSIGN(RendererTask
);
99 } // namespace task_management
101 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_