Index: chrome/browser/task_manager/guest_resource_provider.cc |
diff --git a/chrome/browser/task_manager/task_manager_guest_resource_provider.cc b/chrome/browser/task_manager/guest_resource_provider.cc |
similarity index 57% |
rename from chrome/browser/task_manager/task_manager_guest_resource_provider.cc |
rename to chrome/browser/task_manager/guest_resource_provider.cc |
index 16db63012ccb5a3980794a9c40f2176812bc6f9f..daef3ff9a62ed7fa252caa358fa71a03dda1db9d 100644 |
--- a/chrome/browser/task_manager/task_manager_guest_resource_provider.cc |
+++ b/chrome/browser/task_manager/guest_resource_provider.cc |
@@ -2,19 +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_guest_resource_provider.h" |
+#include "chrome/browser/task_manager/guest_resource_provider.h" |
-#include <string> |
- |
-#include "base/basictypes.h" |
-#include "base/i18n/rtl.h" |
#include "base/string16.h" |
-#include "base/utf_string_conversions.h" |
-#include "chrome/browser/browser_process.h" |
#include "chrome/browser/favicon/favicon_tab_helper.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/common/chrome_notification_types.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/render_process_host.h" |
@@ -23,6 +17,7 @@ |
#include "content/public/browser/web_contents.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/gfx/image/image_skia.h" |
using content::RenderProcessHost; |
using content::RenderViewHost; |
@@ -30,82 +25,59 @@ using content::RenderWidgetHost; |
using content::WebContents; |
using extensions::Extension; |
-namespace { |
- |
-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); |
-} |
- |
-string16 GetTitleFromWebContents(WebContents* web_contents) { |
- string16 title = web_contents->GetTitle(); |
- if (title.empty()) { |
- GURL url = web_contents->GetURL(); |
- title = UTF8ToUTF16(url.spec()); |
- // Force URL to be LTR. |
- title = base::i18n::GetDisplayStringInLTRDirectionality(title); |
- } else { |
- // Since the tab_title will be concatenated with |
- // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to |
- // be LTR format if there is no strong RTL charater in it. Otherwise, if |
- // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result |
- // might be wrong. For example, http://mail.yahoo.com, whose title is |
- // "Yahoo! Mail: The best web-based Email!", without setting it explicitly |
- // as LTR format, the concatenated result will be "!Yahoo! Mail: The best |
- // web-based Email :BAT", in which the capital letters "BAT" stands for |
- // the Hebrew word for "tab". |
- base::i18n::AdjustStringForLocaleDirection(&title); |
- } |
- return title; |
-} |
+namespace task_manager { |
-} // namespace |
+class GuestResource : public RendererResource { |
+ public: |
+ explicit GuestResource(content::RenderViewHost* render_view_host); |
+ virtual ~GuestResource(); |
-//////////////////////////////////////////////////////////////////////////////// |
-// TaskManagerGuestResource class |
-//////////////////////////////////////////////////////////////////////////////// |
+ // 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; |
-TaskManagerGuestResource::TaskManagerGuestResource( |
- RenderViewHost* render_view_host) |
- : TaskManagerRendererResource( |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(GuestResource); |
+}; |
+ |
+GuestResource::GuestResource(RenderViewHost* render_view_host) |
+ : RendererResource( |
render_view_host->GetSiteInstance()->GetProcess()->GetHandle(), |
render_view_host) { |
} |
-TaskManagerGuestResource::~TaskManagerGuestResource() { |
+GuestResource::~GuestResource() { |
} |
-TaskManager::Resource::Type TaskManagerGuestResource::GetType() const { |
+TaskManager::Resource::Type GuestResource::GetType() const { |
return GUEST; |
} |
-string16 TaskManagerGuestResource::GetTitle() const { |
+string16 GuestResource::GetTitle() const { |
WebContents* web_contents = GetWebContents(); |
const int message_id = IDS_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
if (web_contents) { |
- string16 title = GetTitleFromWebContents(web_contents); |
+ string16 title = ResourceUtil::GetTitleFromWebContents(web_contents); |
return l10n_util::GetStringFUTF16(message_id, title); |
} |
return l10n_util::GetStringFUTF16(message_id, string16()); |
} |
-string16 TaskManagerGuestResource::GetProfileName() const { |
+string16 GuestResource::GetProfileName() const { |
WebContents* web_contents = GetWebContents(); |
if (web_contents) { |
Profile* profile = Profile::FromBrowserContext( |
web_contents->GetBrowserContext()); |
- return GetProfileNameFromInfoCache(profile); |
+ return ResourceUtil::GetProfileNameFromInfoCache(profile); |
} |
return string16(); |
} |
-gfx::ImageSkia TaskManagerGuestResource::GetIcon() const { |
+gfx::ImageSkia GuestResource::GetIcon() const { |
WebContents* web_contents = GetWebContents(); |
if (web_contents && FaviconTabHelper::FromWebContents(web_contents)) { |
return FaviconTabHelper::FromWebContents(web_contents)-> |
@@ -114,28 +86,23 @@ gfx::ImageSkia TaskManagerGuestResource::GetIcon() const { |
return gfx::ImageSkia(); |
} |
-WebContents* TaskManagerGuestResource::GetWebContents() const { |
+WebContents* GuestResource::GetWebContents() const { |
return WebContents::FromRenderViewHost(render_view_host()); |
} |
-const Extension* TaskManagerGuestResource::GetExtension() const { |
+const Extension* GuestResource::GetExtension() const { |
return NULL; |
} |
-//////////////////////////////////////////////////////////////////////////////// |
-// TaskManagerGuestContentsResourceProvider class |
-//////////////////////////////////////////////////////////////////////////////// |
- |
-TaskManagerGuestResourceProvider:: |
- TaskManagerGuestResourceProvider(TaskManager* task_manager) |
+GuestResourceProvider::GuestResourceProvider(TaskManager* task_manager) |
: updating_(false), |
task_manager_(task_manager) { |
} |
-TaskManagerGuestResourceProvider::~TaskManagerGuestResourceProvider() { |
+GuestResourceProvider::~GuestResourceProvider() { |
} |
-TaskManager::Resource* TaskManagerGuestResourceProvider::GetResource( |
+TaskManager::Resource* GuestResourceProvider::GetResource( |
int origin_pid, |
int render_process_host_id, |
int routing_id) { |
@@ -157,7 +124,7 @@ TaskManager::Resource* TaskManagerGuestResourceProvider::GetResource( |
return NULL; |
} |
-void TaskManagerGuestResourceProvider::StartUpdating() { |
+void GuestResourceProvider::StartUpdating() { |
DCHECK(!updating_); |
updating_ = true; |
@@ -185,7 +152,7 @@ void TaskManagerGuestResourceProvider::StartUpdating() { |
content::NotificationService::AllBrowserContextsAndSources()); |
} |
-void TaskManagerGuestResourceProvider::StopUpdating() { |
+void GuestResourceProvider::StopUpdating() { |
DCHECK(updating_); |
updating_ = false; |
@@ -201,16 +168,13 @@ void TaskManagerGuestResourceProvider::StopUpdating() { |
resources_.clear(); |
} |
-void TaskManagerGuestResourceProvider::Add( |
- RenderViewHost* render_view_host) { |
- TaskManagerGuestResource* resource = |
- new TaskManagerGuestResource(render_view_host); |
+void GuestResourceProvider::Add(RenderViewHost* render_view_host) { |
+ GuestResource* resource = new GuestResource(render_view_host); |
resources_[render_view_host] = resource; |
task_manager_->AddResource(resource); |
} |
-void TaskManagerGuestResourceProvider::Remove( |
- RenderViewHost* render_view_host) { |
+void GuestResourceProvider::Remove(RenderViewHost* render_view_host) { |
if (!updating_) |
return; |
@@ -218,13 +182,13 @@ void TaskManagerGuestResourceProvider::Remove( |
if (iter == resources_.end()) |
return; |
- TaskManagerGuestResource* resource = iter->second; |
+ GuestResource* resource = iter->second; |
task_manager_->RemoveResource(resource); |
resources_.erase(iter); |
delete resource; |
} |
-void TaskManagerGuestResourceProvider::Observe(int type, |
+void GuestResourceProvider::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
@@ -242,3 +206,5 @@ void TaskManagerGuestResourceProvider::Observe(int type, |
NOTREACHED() << "Unexpected notification."; |
} |
} |
+ |
+} // namespace task_manager |