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 "components/favicon/core/favicon_driver_observer.h"
10 #include "content/public/browser/navigation_entry.h"
12 class ProcessResourceUsage
;
15 class RenderProcessHost
;
17 } // namespace content
19 namespace task_management
{
21 // Defines an abstract base class for various types of renderer process tasks
22 // such as background contents, tab contents, ... etc.
23 class RendererTask
: public Task
,
24 public favicon::FaviconDriverObserver
{
26 RendererTask(const base::string16
& title
,
27 const gfx::ImageSkia
* icon
,
28 content::WebContents
* web_contents
,
29 content::RenderProcessHost
* render_process_host
);
30 ~RendererTask() override
;
32 // An abstract method that will be called when the event
33 // WebContentsObserver::DidNavigateMainFrame() occurs. This gives the
34 // freedom to concrete tasks to adjust the title however they need to before
36 virtual void UpdateTitle() = 0;
38 // An abstract method that will be called when the event
39 // FaviconDriverObserver::OnFaviconUpdated() occurs, so that concrete tasks
40 // can update their favicons.
41 virtual void UpdateFavicon() = 0;
43 // task_management::Task:
44 void Activate() override
;
45 void Refresh(const base::TimeDelta
& update_interval
,
46 int64 refresh_flags
) override
;
47 Type
GetType() const override
;
48 int GetChildProcessUniqueID() const override
;
49 base::string16
GetProfileName() const override
;
50 int64
GetV8MemoryAllocated() const override
;
51 int64
GetV8MemoryUsed() const override
;
52 bool ReportsWebCacheStats() const override
;
53 blink::WebCache::ResourceTypeStats
GetWebCacheStats() const override
;
55 // favicon::FaviconDriverObserver:
56 void OnFaviconAvailable(const gfx::Image
& image
) override
;
57 void OnFaviconUpdated(favicon::FaviconDriver
* favicon_driver
,
58 bool icon_url_changed
) override
;
61 // Returns the title of the given |web_contents|.
62 static base::string16
GetTitleFromWebContents(
63 content::WebContents
* web_contents
);
65 // Returns the favicon of the given |web_contents| if any, and returns
66 // |nullptr| otherwise.
67 static const gfx::ImageSkia
* GetFaviconFromWebContents(
68 content::WebContents
* web_contents
);
70 // Prefixes the given renderer |title| with the appropriate string based on
71 // whether it's an app, an extension, incognito or a background page or
73 static const base::string16
PrefixRendererTitle(const base::string16
& title
,
79 content::WebContents
* web_contents() const { return web_contents_
; }
82 // The WebContents of the task this object represents.
83 content::WebContents
* web_contents_
;
85 // The render process host of the task this object represents.
86 content::RenderProcessHost
* render_process_host_
;
88 // The Mojo service wrapper that will provide us with the V8 memory usage and
89 // the WebCache resource stats of the render process represented by this
91 scoped_ptr
<ProcessResourceUsage
> renderer_resources_sampler_
;
93 // The unique ID of the RenderProcessHost.
94 const int render_process_id_
;
96 // The allocated and used V8 memory (in bytes).
97 int64 v8_memory_allocated_
;
98 int64 v8_memory_used_
;
100 // The WebKit resource cache statistics for this renderer.
101 blink::WebCache::ResourceTypeStats webcache_stats_
;
103 // The profile name associated with the browser context of the render view
105 const base::string16 profile_name_
;
107 DISALLOW_COPY_AND_ASSIGN(RendererTask
);
110 } // namespace task_management
112 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_