1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_
#define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_
#include <stdint.h>
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/task_manager/providers/task.h"
#include "components/favicon/core/favicon_driver_observer.h"
class ProcessResourceUsage;
namespace content {
class RenderFrameHost;
class RenderProcessHost;
class WebContents;
} // namespace content
namespace task_manager {
// Defines an abstract base class for various types of renderer process tasks
// such as background contents, tab contents, ... etc.
class RendererTask : public Task,
public favicon::FaviconDriverObserver {
public:
RendererTask(const std::u16string& title,
const gfx::ImageSkia* icon,
content::WebContents* web_contents);
RendererTask(const std::u16string& title,
const gfx::ImageSkia* icon,
content::RenderFrameHost* subframe);
RendererTask(const RendererTask&) = delete;
RendererTask& operator=(const RendererTask&) = delete;
~RendererTask() override;
// An abstract method that will be called when the event
// WebContentsObserver::DidNavigateMainFrame() occurs. This gives the
// freedom to concrete tasks to adjust the title however they need to before
// they set it.
virtual void UpdateTitle() = 0;
// An abstract method that will be called when the event
// FaviconDriverObserver::OnFaviconUpdated() occurs, so that concrete tasks
// can update their favicons.
virtual void UpdateFavicon() = 0;
// task_manager::Task:
void Activate() override;
void Refresh(const base::TimeDelta& update_interval,
int64_t refresh_flags) override;
Type GetType() const override;
int GetChildProcessUniqueID() const override;
void GetTerminationStatus(base::TerminationStatus* out_status,
int* out_error_code) const override;
std::u16string GetProfileName() const override;
SessionID GetTabId() const override;
int64_t GetV8MemoryAllocated() const override;
int64_t GetV8MemoryUsed() const override;
bool ReportsWebCacheStats() const override;
blink::WebCacheResourceTypeStats GetWebCacheStats() const override;
// favicon::FaviconDriverObserver:
void OnFaviconUpdated(favicon::FaviconDriver* driver,
NotificationIconType notification_icon_type,
const GURL& icon_url,
bool icon_url_changed,
const gfx::Image& image) override;
void set_termination_status(base::TerminationStatus status) {
termination_status_ = status;
}
void set_termination_error_code(int error_code) {
termination_error_code_ = error_code;
}
content::WebContents* web_contents() const { return web_contents_; }
base::WeakPtr<RendererTask> AsWeakPtr();
protected:
// Returns the title of the given |web_contents|.
static std::u16string GetTitleFromWebContents(
content::WebContents* web_contents);
// Returns the favicon of the given |web_contents| if any, and returns
// |nullptr| otherwise.
static const gfx::ImageSkia* GetFaviconFromWebContents(
content::WebContents* web_contents);
// Prefixes the given renderer |title| with the appropriate string based on
// whether it's an app, an extension, incognito or a background page or
// contents.
static const std::u16string PrefixRendererTitle(const std::u16string& title,
bool is_app,
bool is_extension,
bool is_incognito,
bool is_background);
void DefaultUpdateFaviconImpl();
private:
RendererTask(const std::u16string& title,
const gfx::ImageSkia* icon,
content::WebContents* web_contents,
content::RenderProcessHost* render_process_host);
// The WebContents of the task this object represents.
const raw_ptr<content::WebContents> web_contents_;
// The render process host of the task this object represents.
const raw_ptr<content::RenderProcessHost> render_process_host_;
// The Mojo service wrapper that will provide us with the V8 memory usage and
// the WebCache resource stats of the render process represented by this
// object.
std::unique_ptr<ProcessResourceUsage> renderer_resources_sampler_;
// The unique ID of the RenderProcessHost.
const int render_process_id_;
// The allocated and used V8 memory (in bytes).
int64_t v8_memory_allocated_ = 0;
int64_t v8_memory_used_ = 0;
// The WebKit resource cache statistics for this renderer.
blink::WebCacheResourceTypeStats webcache_stats_ = {};
// The profile name associated with the browser context of the render view
// host.
const std::u16string profile_name_;
base::TerminationStatus termination_status_ =
base::TERMINATION_STATUS_STILL_RUNNING;
int termination_error_code_ = 0;
base::WeakPtrFactory<RendererTask> weak_ptr_factor_{this};
};
} // namespace task_manager
#endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WEB_CONTENTS_RENDERER_TASK_H_
|