summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 18:53:54 +0000
committersreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 18:53:54 +0000
commita15905af23e4f4a42c5072fa0c7525c3f783dde8 (patch)
tree388cd2fc0a4c3fb1652e33f91f259bd9796ec8d7 /chrome
parent26f7130782a10231bf85c807fcc49e2096420b51 (diff)
downloadchromium_src-a15905af23e4f4a42c5072fa0c7525c3f783dde8.zip
chromium_src-a15905af23e4f4a42c5072fa0c7525c3f783dde8.tar.gz
chromium_src-a15905af23e4f4a42c5072fa0c7525c3f783dde8.tar.bz2
Add "Instant:" prefix to Instant preview tabs in the Task manager.
BUG=105130 TEST=Open Task Manager. Enable Instant. Type a query into the omnibox. Observe that the Instant preview is listed as "Instant: ..." instead of "Tab: ...". Review URL: http://codereview.chromium.org/8759009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112745 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/instant/instant_browsertest.cc27
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.cc60
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.h6
-rw-r--r--chrome/chrome_tests.gypi1
5 files changed, 89 insertions, 8 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index a915f9d..143a014 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -3783,6 +3783,9 @@ Public Exponent (<ph name="PUBLIC_EXPONENT_NUM_BITS">$3<ex>24</ex></ph> bits):
<message name="IDS_TASK_MANAGER_NOTIFICATION_PREFIX" desc="The prefix for a Desktop Notification in the Task Manager">
Notification: <ph name="NOTIFICATION_NAME">$1<ex>http://www.domain.com</ex></ph>
</message>
+ <message name="IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX" desc="The prefix for an Instant preview in the Task Manager">
+ Instant: <ph name="INSTANT_PREVIEW_NAME">$1<ex>http://www.google.com/</ex></ph>
+ </message>
<!-- Theme preview info bar -->
<message name="IDS_THEME_INSTALL_INFOBAR_LABEL" desc="Text displayed on an infobar when a theme has been installed.">
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
index a8859dd..96ad8e3 100644
--- a/chrome/browser/instant/instant_browsertest.cc
+++ b/chrome/browser/instant/instant_browsertest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
@@ -14,6 +15,8 @@
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/task_manager/task_manager.h"
+#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
@@ -29,6 +32,8 @@
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_service.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
// Tests are flaky on Linux because of http://crbug.com/80118.
#if defined(OS_LINUX)
@@ -802,6 +807,28 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) {
ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
}
+// Tests that the task manager identifies instant's preview tab correctly.
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) {
+ // The browser starts with one new tab, so the task manager should have two
+ // rows initially, one for the browser process and one for tab's renderer.
+ TaskManagerModel* task_manager = TaskManager::GetInstance()->model();
+ task_manager->StartUpdating();
+ TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+
+ ASSERT_TRUE(test_server()->Start());
+ EnableInstant();
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
+
+ // Now there should be three rows, the third being the instant preview.
+ TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ string16 prefix = l10n_util::GetStringFUTF16(
+ IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16());
+ string16 title = task_manager->GetResourceTitle(2);
+ EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix;
+}
+
// Tests the INSTANT experiment of the field trial.
class InstantFieldTrialInstantTest : public InstantTest {
public:
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc
index 7b3658f..5b91f4a 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager/task_manager_resource_providers.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -70,8 +71,11 @@ 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) {
+int GetMessagePrefixID(bool is_app,
+ bool is_extension,
+ bool is_incognito,
+ bool is_prerender,
+ bool is_instant_preview) {
if (is_app) {
if (is_incognito)
return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX;
@@ -84,6 +88,8 @@ int GetMessagePrefixID(bool is_app, bool is_extension,
return IDS_TASK_MANAGER_EXTENSION_PREFIX;
} else if (is_prerender) {
return IDS_TASK_MANAGER_PRERENDER_PREFIX;
+ } else if (is_instant_preview) {
+ return IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX;
} else {
return IDS_TASK_MANAGER_TAB_PREFIX;
}
@@ -216,16 +222,30 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource(
: TaskManagerRendererResource(
tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle(),
tab_contents->render_view_host()),
- tab_contents_(tab_contents) {
+ tab_contents_(tab_contents),
+ is_instant_preview_(false) {
if (!prerender_icon_) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER);
}
+ for (BrowserList::const_iterator i = BrowserList::begin();
+ i != BrowserList::end(); ++i) {
+ if ((*i)->instant() &&
+ (*i)->instant()->GetPreviewContents() == tab_contents_) {
+ is_instant_preview_ = true;
+ break;
+ }
+ }
}
TaskManagerTabContentsResource::~TaskManagerTabContentsResource() {
}
+void TaskManagerTabContentsResource::InstantCommitted() {
+ DCHECK(is_instant_preview_);
+ is_instant_preview_ = false;
+}
+
bool TaskManagerTabContentsResource::IsPrerendering() const {
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForProfile(
@@ -279,7 +299,8 @@ string16 TaskManagerTabContentsResource::GetTitle() const {
is_app,
HostsExtension(),
tab_contents_->profile()->IsOffTheRecord(),
- IsPrerendering());
+ IsPrerendering(),
+ is_instant_preview_);
return l10n_util::GetStringFUTF16(message_id, tab_title);
}
@@ -376,6 +397,8 @@ void TaskManagerTabContentsResourceProvider::StartUpdating() {
// (http://crbug.com/7321).
registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources());
+ registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
+ content::NotificationService::AllBrowserContextsAndSources());
}
void TaskManagerTabContentsResourceProvider::StopUpdating() {
@@ -395,6 +418,9 @@ void TaskManagerTabContentsResourceProvider::StopUpdating() {
registrar_.Remove(
this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources());
+ registrar_.Remove(
+ this, chrome::NOTIFICATION_INSTANT_COMMITTED,
+ content::NotificationService::AllBrowserContextsAndSources());
// Delete all the resources.
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
@@ -456,12 +482,27 @@ void TaskManagerTabContentsResourceProvider::Remove(
delete resource;
}
+void TaskManagerTabContentsResourceProvider::Update(
+ TabContentsWrapper* tab_contents) {
+ if (!updating_)
+ return;
+ std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator
+ iter = resources_.find(tab_contents);
+ DCHECK(iter != resources_.end());
+ if (iter != resources_.end())
+ iter->second->InstantCommitted();
+}
+
void TaskManagerTabContentsResourceProvider::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- TabContentsWrapper* tab_contents =
- TabContentsWrapper::GetCurrentWrapperForContents(
- content::Source<TabContents>(source).ptr());
+ TabContentsWrapper* tab_contents;
+ if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) {
+ tab_contents = content::Source<TabContentsWrapper>(source).ptr();
+ } else {
+ tab_contents = TabContentsWrapper::GetCurrentWrapperForContents(
+ content::Source<TabContents>(source).ptr());
+ }
// A background page does not have a TabContentsWrapper.
if (!tab_contents)
return;
@@ -482,6 +523,9 @@ void TaskManagerTabContentsResourceProvider::Observe(int type,
case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED:
Remove(tab_contents);
break;
+ case chrome::NOTIFICATION_INSTANT_COMMITTED:
+ Update(tab_contents);
+ break;
default:
NOTREACHED() << "Unexpected notification.";
return;
@@ -1073,7 +1117,7 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource(
DCHECK(!extension_name.empty());
int message_id = GetMessagePrefixID(GetExtension()->is_app(), true,
- extension_host_->profile()->IsOffTheRecord(), false);
+ extension_host_->profile()->IsOffTheRecord(), false, false);
title_ = l10n_util::GetStringFUTF16(message_id, extension_name);
}
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.h b/chrome/browser/task_manager/task_manager_resource_providers.h
index 6999afb..728d29e 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.h
+++ b/chrome/browser/task_manager/task_manager_resource_providers.h
@@ -98,6 +98,10 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource {
explicit TaskManagerTabContentsResource(TabContentsWrapper* tab_contents);
virtual ~TaskManagerTabContentsResource();
+ // Called when the underlying tab_contents has been committed, and is thus no
+ // longer an Instant preview.
+ void InstantCommitted();
+
// TaskManager::Resource methods:
virtual Type GetType() const OVERRIDE;
virtual string16 GetTitle() const OVERRIDE;
@@ -114,6 +118,7 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource {
static SkBitmap* prerender_icon_;
TabContentsWrapper* tab_contents_;
+ bool is_instant_preview_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource);
};
@@ -140,6 +145,7 @@ class TaskManagerTabContentsResourceProvider
void Add(TabContentsWrapper* tab_contents);
void Remove(TabContentsWrapper* tab_contents);
+ void Update(TabContentsWrapper* tab_contents);
void AddToTaskManager(TabContentsWrapper* tab_contents);
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 07a82a3..00e5f1d 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -542,6 +542,7 @@
'browser/mouseleave_interactive_uitest.cc',
'browser/notifications/notifications_interactive_uitest.cc',
'browser/npapi_interactive_test.cc',
+ 'browser/task_manager/task_manager_browsertest_util.cc',
'browser/ui/gtk/bookmarks/bookmark_bar_gtk_interactive_uitest.cc',
'browser/ui/omnibox/omnibox_view_browsertest.cc',
'browser/ui/panels/panel_browsertest.cc',