| Index: chrome/browser/task_manager/panel_resource_provider.cc
|
| diff --git a/chrome/browser/task_manager/task_manager_panel_resource_provider.cc b/chrome/browser/task_manager/panel_resource_provider.cc
|
| similarity index 62%
|
| rename from chrome/browser/task_manager/task_manager_panel_resource_provider.cc
|
| rename to chrome/browser/task_manager/panel_resource_provider.cc
|
| index 6ab53e9d12806979462cb842a67844f43f4c121d..ce52864b65d4e4e8260ef86b03a11e3da004c18c 100644
|
| --- a/chrome/browser/task_manager/task_manager_panel_resource_provider.cc
|
| +++ b/chrome/browser/task_manager/panel_resource_provider.cc
|
| @@ -2,17 +2,13 @@
|
| // 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_panel_resource_provider.h"
|
| -
|
| -#include <string>
|
| +#include "chrome/browser/task_manager/panel_resource_provider.h"
|
|
|
| #include "base/i18n/rtl.h"
|
| -#include "base/string16.h"
|
| -#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/extensions/extension_service.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/renderer_resource.h"
|
| +#include "chrome/browser/task_manager/resource_util.h"
|
| #include "chrome/browser/ui/panels/panel.h"
|
| #include "chrome/browser/ui/panels/panel_manager.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| @@ -22,8 +18,6 @@
|
| #include "content/public/browser/render_view_host.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"
|
|
|
| using content::RenderProcessHost;
|
| @@ -31,73 +25,52 @@ using content::RenderViewHost;
|
| 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 PanelResource : public RendererResource {
|
| + public:
|
| + explicit PanelResource(Panel* panel);
|
| + virtual ~PanelResource();
|
|
|
| -} // namespace
|
| + // TaskManager::Resource methods:
|
| + virtual Type GetType() const OVERRIDE;
|
| + virtual string16 GetTitle() const OVERRIDE;
|
| + virtual string16 GetProfileName() const OVERRIDE;
|
| + virtual gfx::ImageSkia GetIcon() const OVERRIDE;
|
| + virtual content::WebContents* GetWebContents() const OVERRIDE;
|
| + virtual const extensions::Extension* GetExtension() const OVERRIDE;
|
|
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -// TaskManagerPanelResource class
|
| -////////////////////////////////////////////////////////////////////////////////
|
| + private:
|
| + Panel* panel_;
|
| + // Determines prefix for title reflecting whether extensions are apps
|
| + // or in incognito mode.
|
| + int message_prefix_id_;
|
|
|
| -TaskManagerPanelResource::TaskManagerPanelResource(Panel* panel)
|
| - : TaskManagerRendererResource(
|
| + DISALLOW_COPY_AND_ASSIGN(PanelResource);
|
| +};
|
| +
|
| +PanelResource::PanelResource(Panel* panel)
|
| + : RendererResource(
|
| panel->GetWebContents()->GetRenderProcessHost()->GetHandle(),
|
| panel->GetWebContents()->GetRenderViewHost()),
|
| panel_(panel) {
|
| - message_prefix_id_ = GetMessagePrefixID(
|
| - GetExtension()->is_app(), true, panel->profile()->IsOffTheRecord(),
|
| - false, false, false);
|
| + message_prefix_id_ = ResourceUtil::GetMessagePrefixID(
|
| + GetExtension()->is_app(),
|
| + true, // is_extension
|
| + panel->profile()->IsOffTheRecord(),
|
| + false, // is_prerender
|
| + false, // is_instant_overlay
|
| + false); // is_background
|
| }
|
|
|
| -TaskManagerPanelResource::~TaskManagerPanelResource() {
|
| +PanelResource::~PanelResource() {
|
| }
|
|
|
| -TaskManager::Resource::Type TaskManagerPanelResource::GetType() const {
|
| +TaskManager::Resource::Type PanelResource::GetType() const {
|
| return EXTENSION;
|
| }
|
|
|
| -string16 TaskManagerPanelResource::GetTitle() const {
|
| +string16 PanelResource::GetTitle() const {
|
| string16 title = panel_->GetWindowTitle();
|
| // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix
|
| // we need to explicitly set the title to be LTR format if there is no
|
| @@ -112,39 +85,38 @@ string16 TaskManagerPanelResource::GetTitle() const {
|
| return l10n_util::GetStringFUTF16(message_prefix_id_, title);
|
| }
|
|
|
| -string16 TaskManagerPanelResource::GetProfileName() const {
|
| - return GetProfileNameFromInfoCache(panel_->profile());
|
| +string16 PanelResource::GetProfileName() const {
|
| + return ResourceUtil::GetProfileNameFromInfoCache(panel_->profile());
|
| }
|
|
|
| -gfx::ImageSkia TaskManagerPanelResource::GetIcon() const {
|
| +gfx::ImageSkia PanelResource::GetIcon() const {
|
| gfx::Image icon = panel_->GetCurrentPageIcon();
|
| return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
|
| }
|
|
|
| -WebContents* TaskManagerPanelResource::GetWebContents() const {
|
| +WebContents* PanelResource::GetWebContents() const {
|
| return panel_->GetWebContents();
|
| }
|
|
|
| -const Extension* TaskManagerPanelResource::GetExtension() const {
|
| +const Extension* PanelResource::GetExtension() const {
|
| ExtensionService* extension_service =
|
| panel_->profile()->GetExtensionService();
|
| return extension_service->extensions()->GetByID(panel_->extension_id());
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -// TaskManagerPanelResourceProvider class
|
| +// PanelResourceProvider class
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -TaskManagerPanelResourceProvider::TaskManagerPanelResourceProvider(
|
| - TaskManager* task_manager)
|
| +PanelResourceProvider::PanelResourceProvider(TaskManager* task_manager)
|
| : updating_(false),
|
| task_manager_(task_manager) {
|
| }
|
|
|
| -TaskManagerPanelResourceProvider::~TaskManagerPanelResourceProvider() {
|
| +PanelResourceProvider::~PanelResourceProvider() {
|
| }
|
|
|
| -TaskManager::Resource* TaskManagerPanelResourceProvider::GetResource(
|
| +TaskManager::Resource* PanelResourceProvider::GetResource(
|
| int origin_pid,
|
| int render_process_host_id,
|
| int routing_id) {
|
| @@ -168,7 +140,7 @@ TaskManager::Resource* TaskManagerPanelResourceProvider::GetResource(
|
| return NULL;
|
| }
|
|
|
| -void TaskManagerPanelResourceProvider::StartUpdating() {
|
| +void PanelResourceProvider::StartUpdating() {
|
| DCHECK(!updating_);
|
| updating_ = true;
|
|
|
| @@ -184,7 +156,7 @@ void TaskManagerPanelResourceProvider::StartUpdating() {
|
| content::NotificationService::AllSources());
|
| }
|
|
|
| -void TaskManagerPanelResourceProvider::StopUpdating() {
|
| +void PanelResourceProvider::StopUpdating() {
|
| DCHECK(updating_);
|
| updating_ = false;
|
|
|
| @@ -199,7 +171,7 @@ void TaskManagerPanelResourceProvider::StopUpdating() {
|
| resources_.clear();
|
| }
|
|
|
| -void TaskManagerPanelResourceProvider::Add(Panel* panel) {
|
| +void PanelResourceProvider::Add(Panel* panel) {
|
| if (!updating_)
|
| return;
|
|
|
| @@ -207,12 +179,12 @@ void TaskManagerPanelResourceProvider::Add(Panel* panel) {
|
| if (iter != resources_.end())
|
| return;
|
|
|
| - TaskManagerPanelResource* resource = new TaskManagerPanelResource(panel);
|
| + PanelResource* resource = new PanelResource(panel);
|
| resources_[panel] = resource;
|
| task_manager_->AddResource(resource);
|
| }
|
|
|
| -void TaskManagerPanelResourceProvider::Remove(Panel* panel) {
|
| +void PanelResourceProvider::Remove(Panel* panel) {
|
| if (!updating_)
|
| return;
|
|
|
| @@ -220,13 +192,13 @@ void TaskManagerPanelResourceProvider::Remove(Panel* panel) {
|
| if (iter == resources_.end())
|
| return;
|
|
|
| - TaskManagerPanelResource* resource = iter->second;
|
| + PanelResource* resource = iter->second;
|
| task_manager_->RemoveResource(resource);
|
| resources_.erase(iter);
|
| delete resource;
|
| }
|
|
|
| -void TaskManagerPanelResourceProvider::Observe(int type,
|
| +void PanelResourceProvider::Observe(int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| WebContents* web_contents = content::Source<WebContents>(source).ptr();
|
| @@ -263,3 +235,5 @@ void TaskManagerPanelResourceProvider::Observe(int type,
|
| break;
|
| }
|
| }
|
| +
|
| +} // namespace task_manager
|
|
|