Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / renderer_task.h
blob45434c3284a302cda4f71a44de9f1eb2a87b11dd
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;
13 namespace content {
14 class RenderProcessHost;
15 class WebContents;
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 {
23 public:
24 RendererTask(const base::string16& title,
25 const gfx::ImageSkia* icon,
26 content::WebContents* web_contents,
27 content::RenderProcessHost* render_process_host);
28 ~RendererTask() override;
30 // An abstract method that will be called when the event
31 // |WebContentsObserver::TitleWasSet()| occurs. This gives the freedom to
32 // concrete tasks to adjust the title however they need to before they set it.
33 virtual void OnTitleChanged(content::NavigationEntry* entry) = 0;
35 // An abstract method that will be called when the event
36 // |WebContentsObserver::DidUpdateFaviconURL()| occurs, so that concrete tasks
37 // can update their favicons.
38 virtual void OnFaviconChanged() = 0;
40 // task_management::Task:
41 void Activate() override;
42 void Refresh(const base::TimeDelta& update_interval,
43 int64 refresh_flags) override;
44 Type GetType() const override;
45 int GetChildProcessUniqueID() const override;
46 base::string16 GetProfileName() const override;
47 int64 GetV8MemoryAllocated() const override;
48 int64 GetV8MemoryUsed() const override;
49 bool ReportsWebCacheStats() const override;
50 blink::WebCache::ResourceTypeStats GetWebCacheStats() const override;
52 protected:
53 // Returns the title of the given |web_contents|.
54 static base::string16 GetTitleFromWebContents(
55 content::WebContents* web_contents);
57 // Returns the favicon of the given |web_contents| if any, and returns
58 // |nullptr| otherwise.
59 static const gfx::ImageSkia* GetFaviconFromWebContents(
60 content::WebContents* web_contents);
62 // Prefixes the given renderer |title| with the appropriate string based on
63 // whether it's an app, an extension, incognito or a background page or
64 // contents.
65 static const base::string16 PrefixRendererTitle(const base::string16& title,
66 bool is_app,
67 bool is_extension,
68 bool is_incognito,
69 bool is_background);
71 content::WebContents* web_contents() const { return web_contents_; }
73 private:
74 // The WebContents of the task this object represents.
75 content::WebContents* web_contents_;
77 // The render process host of the task this object represents.
78 content::RenderProcessHost* render_process_host_;
80 // The Mojo service wrapper that will provide us with the V8 memory usage and
81 // the WebCache resource stats of the render process represented by this
82 // object.
83 scoped_ptr<ProcessResourceUsage> renderer_resources_sampler_;
85 // The unique ID of the RenderProcessHost.
86 const int render_process_id_;
88 // The allocated and used V8 memory (in bytes).
89 int64 v8_memory_allocated_;
90 int64 v8_memory_used_;
92 // The WebKit resource cache statistics for this renderer.
93 blink::WebCache::ResourceTypeStats webcache_stats_;
95 // The profile name associated with the browser context of the render view
96 // host.
97 const base::string16 profile_name_;
99 DISALLOW_COPY_AND_ASSIGN(RendererTask);
102 } // namespace task_management
104 #endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_