| Index: chrome/browser/task_manager/extension_process_resource_provider.cc
|
| diff --git a/chrome/browser/task_manager/task_manager_extension_process_resource_provider.cc b/chrome/browser/task_manager/extension_process_resource_provider.cc
|
| similarity index 66%
|
| rename from chrome/browser/task_manager/task_manager_extension_process_resource_provider.cc
|
| rename to chrome/browser/task_manager/extension_process_resource_provider.cc
|
| index 172c7d27081b0f428db39fce5e86a8f26fd8315f..5ab741e3f82eacf15eaa97d71f07e727c1e1f330 100644
|
| --- a/chrome/browser/task_manager/task_manager_extension_process_resource_provider.cc
|
| +++ b/chrome/browser/task_manager/extension_process_resource_provider.cc
|
| @@ -2,11 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/task_manager/task_manager_extension_process_resource_provider.h"
|
| +#include "chrome/browser/task_manager/extension_process_resource_provider.h"
|
|
|
| -#include <string>
|
| -
|
| -#include "base/basictypes.h"
|
| #include "base/string16.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/browser/browser_process.h"
|
| @@ -15,15 +12,14 @@
|
| #include "chrome/browser/extensions/extension_process_manager.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/profiles/profile_info_cache.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/task_manager/resource_util.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/site_instance.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "extensions/browser/view_type_utils.h"
|
| -#include "grit/generated_resources.h"
|
| #include "grit/theme_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| @@ -32,58 +28,51 @@
|
| using content::WebContents;
|
| using extensions::Extension;
|
|
|
| -namespace {
|
| -
|
| -// Returns the appropriate message prefix ID for tabs and extensions,
|
| -// reflecting whether they are apps or in incognito mode.
|
| -int GetMessagePrefixID(bool is_app,
|
| - bool is_extension,
|
| - bool is_incognito,
|
| - bool is_prerender,
|
| - bool is_instant_overlay,
|
| - bool is_background) {
|
| - if (is_app) {
|
| - if (is_background) {
|
| - return IDS_TASK_MANAGER_BACKGROUND_PREFIX;
|
| - } else if (is_incognito) {
|
| - return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX;
|
| - } else {
|
| - return IDS_TASK_MANAGER_APP_PREFIX;
|
| - }
|
| - } else if (is_extension) {
|
| - if (is_incognito)
|
| - return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX;
|
| - else
|
| - return IDS_TASK_MANAGER_EXTENSION_PREFIX;
|
| - } else if (is_prerender) {
|
| - return IDS_TASK_MANAGER_PRERENDER_PREFIX;
|
| - } else if (is_instant_overlay) {
|
| - return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX;
|
| - } else {
|
| - return IDS_TASK_MANAGER_TAB_PREFIX;
|
| - }
|
| -}
|
| +namespace task_manager {
|
|
|
| -string16 GetProfileNameFromInfoCache(Profile* profile) {
|
| - ProfileInfoCache& cache =
|
| - g_browser_process->profile_manager()->GetProfileInfoCache();
|
| - size_t index = cache.GetIndexOfProfileWithPath(
|
| - profile->GetOriginalProfile()->GetPath());
|
| - if (index == std::string::npos)
|
| - return string16();
|
| - else
|
| - return cache.GetNameOfProfileAtIndex(index);
|
| -}
|
| +class ExtensionProcessResource : public TaskManager::Resource {
|
| + public:
|
| + explicit ExtensionProcessResource(
|
| + content::RenderViewHost* render_view_host);
|
| + virtual ~ExtensionProcessResource();
|
|
|
| -} // namespace
|
| + // TaskManager::Resource methods:
|
| + virtual string16 GetTitle() const OVERRIDE;
|
| + virtual string16 GetProfileName() const OVERRIDE;
|
| + virtual gfx::ImageSkia GetIcon() const OVERRIDE;
|
| + virtual base::ProcessHandle GetProcess() const OVERRIDE;
|
| + virtual int GetUniqueChildProcessId() const OVERRIDE;
|
| + virtual Type GetType() const OVERRIDE;
|
| + virtual bool CanInspect() const OVERRIDE;
|
| + virtual void Inspect() const OVERRIDE;
|
| + virtual bool SupportNetworkUsage() const OVERRIDE;
|
| + virtual void SetSupportNetworkUsage() OVERRIDE;
|
| + virtual const extensions::Extension* GetExtension() const OVERRIDE;
|
|
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -// TaskManagerExtensionProcessResource class
|
| -////////////////////////////////////////////////////////////////////////////////
|
| + // Returns the pid of the extension process.
|
| + int process_id() const { return pid_; }
|
|
|
| -gfx::ImageSkia* TaskManagerExtensionProcessResource::default_icon_ = NULL;
|
| + // Returns true if the associated extension has a background page.
|
| + virtual bool IsBackground() const OVERRIDE;
|
|
|
| -TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource(
|
| + private:
|
| + // The icon painted for the extension process.
|
| + static gfx::ImageSkia* default_icon_;
|
| +
|
| + content::RenderViewHost* render_view_host_;
|
| +
|
| + // Cached data about the extension.
|
| + base::ProcessHandle process_handle_;
|
| + int pid_;
|
| + int unique_process_id_;
|
| + string16 title_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ExtensionProcessResource);
|
| +};
|
| +
|
| +gfx::ImageSkia* ExtensionProcessResource::default_icon_ = NULL;
|
| +
|
| +ExtensionProcessResource::ExtensionProcessResource(
|
| content::RenderViewHost* render_view_host)
|
| : render_view_host_(render_view_host) {
|
| if (!default_icon_) {
|
| @@ -98,57 +87,62 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource(
|
|
|
| Profile* profile = Profile::FromBrowserContext(
|
| render_view_host->GetProcess()->GetBrowserContext());
|
| - int message_id = GetMessagePrefixID(GetExtension()->is_app(), true,
|
| - profile->IsOffTheRecord(), false, false, IsBackground());
|
| + int message_id = ResourceUtil::GetMessagePrefixID(
|
| + GetExtension()->is_app(),
|
| + true, // is_extension
|
| + profile->IsOffTheRecord(),
|
| + false, // is_prerender
|
| + false, // is_instant_overlay
|
| + IsBackground());
|
| title_ = l10n_util::GetStringFUTF16(message_id, extension_name);
|
| }
|
|
|
| -TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() {
|
| +ExtensionProcessResource::~ExtensionProcessResource() {
|
| }
|
|
|
| -string16 TaskManagerExtensionProcessResource::GetTitle() const {
|
| +string16 ExtensionProcessResource::GetTitle() const {
|
| return title_;
|
| }
|
|
|
| -string16 TaskManagerExtensionProcessResource::GetProfileName() const {
|
| - return GetProfileNameFromInfoCache(Profile::FromBrowserContext(
|
| - render_view_host_->GetProcess()->GetBrowserContext()));
|
| +string16 ExtensionProcessResource::GetProfileName() const {
|
| + return ResourceUtil::GetProfileNameFromInfoCache(
|
| + Profile::FromBrowserContext(
|
| + render_view_host_->GetProcess()->GetBrowserContext()));
|
| }
|
|
|
| -gfx::ImageSkia TaskManagerExtensionProcessResource::GetIcon() const {
|
| +gfx::ImageSkia ExtensionProcessResource::GetIcon() const {
|
| return *default_icon_;
|
| }
|
|
|
| -base::ProcessHandle TaskManagerExtensionProcessResource::GetProcess() const {
|
| +base::ProcessHandle ExtensionProcessResource::GetProcess() const {
|
| return process_handle_;
|
| }
|
|
|
| -int TaskManagerExtensionProcessResource::GetUniqueChildProcessId() const {
|
| +int ExtensionProcessResource::GetUniqueChildProcessId() const {
|
| return unique_process_id_;
|
| }
|
|
|
| -TaskManager::Resource::Type
|
| -TaskManagerExtensionProcessResource::GetType() const {
|
| +TaskManager::Resource::Type ExtensionProcessResource::GetType() const {
|
| return EXTENSION;
|
| }
|
|
|
| -bool TaskManagerExtensionProcessResource::CanInspect() const {
|
| +bool ExtensionProcessResource::CanInspect() const {
|
| return true;
|
| }
|
|
|
| -void TaskManagerExtensionProcessResource::Inspect() const {
|
| +void ExtensionProcessResource::Inspect() const {
|
| DevToolsWindow::OpenDevToolsWindow(render_view_host_);
|
| }
|
|
|
| -bool TaskManagerExtensionProcessResource::SupportNetworkUsage() const {
|
| +bool ExtensionProcessResource::SupportNetworkUsage() const {
|
| return true;
|
| }
|
|
|
| -void TaskManagerExtensionProcessResource::SetSupportNetworkUsage() {
|
| +void ExtensionProcessResource::SetSupportNetworkUsage() {
|
| NOTREACHED();
|
| }
|
|
|
| -const Extension* TaskManagerExtensionProcessResource::GetExtension() const {
|
| +const Extension* ExtensionProcessResource::GetExtension() const {
|
| Profile* profile = Profile::FromBrowserContext(
|
| render_view_host_->GetProcess()->GetBrowserContext());
|
| ExtensionProcessManager* process_manager =
|
| @@ -156,7 +150,7 @@ const Extension* TaskManagerExtensionProcessResource::GetExtension() const {
|
| return process_manager->GetExtensionForRenderViewHost(render_view_host_);
|
| }
|
|
|
| -bool TaskManagerExtensionProcessResource::IsBackground() const {
|
| +bool ExtensionProcessResource::IsBackground() const {
|
| WebContents* web_contents =
|
| WebContents::FromRenderViewHost(render_view_host_);
|
| extensions::ViewType view_type = extensions::GetViewType(web_contents);
|
| @@ -164,20 +158,19 @@ bool TaskManagerExtensionProcessResource::IsBackground() const {
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -// TaskManagerExtensionProcessResourceProvider class
|
| +// ExtensionProcessResourceProvider class
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -TaskManagerExtensionProcessResourceProvider::
|
| - TaskManagerExtensionProcessResourceProvider(TaskManager* task_manager)
|
| +ExtensionProcessResourceProvider::
|
| + ExtensionProcessResourceProvider(TaskManager* task_manager)
|
| : task_manager_(task_manager),
|
| updating_(false) {
|
| }
|
|
|
| -TaskManagerExtensionProcessResourceProvider::
|
| - ~TaskManagerExtensionProcessResourceProvider() {
|
| +ExtensionProcessResourceProvider::~ExtensionProcessResourceProvider() {
|
| }
|
|
|
| -TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource(
|
| +TaskManager::Resource* ExtensionProcessResourceProvider::GetResource(
|
| int origin_pid,
|
| int render_process_host_id,
|
| int routing_id) {
|
| @@ -199,7 +192,7 @@ TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource(
|
| return NULL;
|
| }
|
|
|
| -void TaskManagerExtensionProcessResourceProvider::StartUpdating() {
|
| +void ExtensionProcessResourceProvider::StartUpdating() {
|
| DCHECK(!updating_);
|
| updating_ = true;
|
|
|
| @@ -241,7 +234,7 @@ void TaskManagerExtensionProcessResourceProvider::StartUpdating() {
|
| content::NotificationService::AllBrowserContextsAndSources());
|
| }
|
|
|
| -void TaskManagerExtensionProcessResourceProvider::StopUpdating() {
|
| +void ExtensionProcessResourceProvider::StopUpdating() {
|
| DCHECK(updating_);
|
| updating_ = false;
|
|
|
| @@ -262,7 +255,7 @@ void TaskManagerExtensionProcessResourceProvider::StopUpdating() {
|
| resources_.clear();
|
| }
|
|
|
| -void TaskManagerExtensionProcessResourceProvider::Observe(
|
| +void ExtensionProcessResourceProvider::Observe(
|
| int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| @@ -286,13 +279,13 @@ void TaskManagerExtensionProcessResourceProvider::Observe(
|
| }
|
| }
|
|
|
| -bool TaskManagerExtensionProcessResourceProvider::
|
| +bool ExtensionProcessResourceProvider::
|
| IsHandledByThisProvider(content::RenderViewHost* render_view_host) {
|
| WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host);
|
| // Don't add WebContents that belong to a guest (those are handled by
|
| // TaskManagerGuestResourceProvider). Otherwise they will be added twice, and
|
| // in this case they will have the app's name as a title (due to the
|
| - // TaskManagerExtensionProcessResource constructor).
|
| + // ExtensionProcessResource constructor).
|
| if (web_contents->GetRenderProcessHost()->IsGuest())
|
| return false;
|
| extensions::ViewType view_type = extensions::GetViewType(web_contents);
|
| @@ -309,29 +302,29 @@ bool TaskManagerExtensionProcessResourceProvider::
|
| #endif // USE_ASH
|
| }
|
|
|
| -void TaskManagerExtensionProcessResourceProvider::AddToTaskManager(
|
| +void ExtensionProcessResourceProvider::AddToTaskManager(
|
| content::RenderViewHost* render_view_host) {
|
| if (!IsHandledByThisProvider(render_view_host))
|
| return;
|
|
|
| - TaskManagerExtensionProcessResource* resource =
|
| - new TaskManagerExtensionProcessResource(render_view_host);
|
| + ExtensionProcessResource* resource =
|
| + new ExtensionProcessResource(render_view_host);
|
| DCHECK(resources_.find(render_view_host) == resources_.end());
|
| resources_[render_view_host] = resource;
|
| task_manager_->AddResource(resource);
|
| }
|
|
|
| -void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager(
|
| +void ExtensionProcessResourceProvider::RemoveFromTaskManager(
|
| content::RenderViewHost* render_view_host) {
|
| if (!updating_)
|
| return;
|
| - std::map<content::RenderViewHost*, TaskManagerExtensionProcessResource*>
|
| + std::map<content::RenderViewHost*, ExtensionProcessResource*>
|
| ::iterator iter = resources_.find(render_view_host);
|
| if (iter == resources_.end())
|
| return;
|
|
|
| // Remove the resource from the Task Manager.
|
| - TaskManagerExtensionProcessResource* resource = iter->second;
|
| + ExtensionProcessResource* resource = iter->second;
|
| task_manager_->RemoveResource(resource);
|
|
|
| // Remove it from the provider.
|
| @@ -340,3 +333,5 @@ void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager(
|
| // Finally, delete the resource.
|
| delete resource;
|
| }
|
| +
|
| +} // namespace task_manager
|
|
|