summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 22:14:39 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 22:14:39 +0000
commitd19ee3444d4c8042a97bd653e57c775206a04bed (patch)
tree89f0e3822bab8f163ec99ff4dde6a48cd529d54b /chrome
parent4cb6dca5bcdabfa14f067f741243ca4fcda0b833 (diff)
downloadchromium_src-d19ee3444d4c8042a97bd653e57c775206a04bed.zip
chromium_src-d19ee3444d4c8042a97bd653e57c775206a04bed.tar.gz
chromium_src-d19ee3444d4c8042a97bd653e57c775206a04bed.tar.bz2
Add notification processes to the task manager.
BUG=29332 TEST=notifications in task manager Review URL: http://codereview.chromium.org/1610006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44014 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl.h2
-rw-r--r--chrome/browser/chromeos/notifications/balloon_view.cc4
-rw-r--r--chrome/browser/chromeos/notifications/balloon_view.h1
-rw-r--r--chrome/browser/cocoa/notifications/balloon_controller.h3
-rw-r--r--chrome/browser/cocoa/notifications/balloon_controller.mm5
-rw-r--r--chrome/browser/cocoa/notifications/balloon_controller_unittest.mm6
-rw-r--r--chrome/browser/cocoa/notifications/balloon_view_bridge.h1
-rw-r--r--chrome/browser/cocoa/notifications/balloon_view_bridge.mm3
-rw-r--r--chrome/browser/gtk/notifications/balloon_view_gtk.h3
-rw-r--r--chrome/browser/notifications/balloon.h4
-rw-r--r--chrome/browser/notifications/balloon_collection.h6
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h3
-rw-r--r--chrome/browser/notifications/balloon_host.cc26
-rw-r--r--chrome/browser/notifications/balloon_host.h12
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc27
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.h9
-rw-r--r--chrome/browser/notifications/notification_test_util.h1
-rw-r--r--chrome/browser/task_manager.cc4
-rw-r--r--chrome/browser/task_manager_resource_providers.cc136
-rw-r--r--chrome/browser/task_manager_resource_providers.h65
-rw-r--r--chrome/browser/views/notifications/balloon_view.h3
-rw-r--r--chrome/common/notification_type.h11
22 files changed, 298 insertions, 37 deletions
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.h b/chrome/browser/chromeos/notifications/balloon_collection_impl.h
index 684a5e0..4a071b9 100644
--- a/chrome/browser/chromeos/notifications/balloon_collection_impl.h
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.h
@@ -53,6 +53,7 @@ class BalloonCollectionImpl : public BalloonCollection {
virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size);
virtual void DisplayChanged() {}
virtual void OnBalloonClosed(Balloon* source);
+ virtual const Balloons& GetActiveBalloons() { return balloons_; }
// Adds new system notification.
// |sticky| is used to indicate that the notification
@@ -86,7 +87,6 @@ class BalloonCollectionImpl : public BalloonCollection {
// The number of balloons being displayed.
int count() const { return balloons_.size(); }
- typedef std::deque<Balloon*> Balloons;
Balloons::iterator FindBalloon(const Notification& notification);
// Queue of active balloons.
diff --git a/chrome/browser/chromeos/notifications/balloon_view.cc b/chrome/browser/chromeos/notifications/balloon_view.cc
index 602167e..af03ad3 100644
--- a/chrome/browser/chromeos/notifications/balloon_view.cc
+++ b/chrome/browser/chromeos/notifications/balloon_view.cc
@@ -126,6 +126,10 @@ gfx::Size BalloonViewImpl::GetSize() const {
return gfx::Size(0, 0);
}
+BalloonHost* BalloonViewImpl::GetHost() const {
+ return html_contents_;
+}
+
void BalloonViewImpl::RepositionToBalloon() {
// Not used. The layout is managed by the Panel.
}
diff --git a/chrome/browser/chromeos/notifications/balloon_view.h b/chrome/browser/chromeos/notifications/balloon_view.h
index a7c3fba..e350c953 100644
--- a/chrome/browser/chromeos/notifications/balloon_view.h
+++ b/chrome/browser/chromeos/notifications/balloon_view.h
@@ -56,6 +56,7 @@ class BalloonViewImpl : public BalloonView,
virtual void Close(bool by_user);
virtual void RepositionToBalloon();
gfx::Size GetSize() const;
+ virtual BalloonHost* GetHost() const;
// True if the notification is stale. False if the notification is new.
bool stale() const { return stale_; }
diff --git a/chrome/browser/cocoa/notifications/balloon_controller.h b/chrome/browser/cocoa/notifications/balloon_controller.h
index d71c8e3..3cff471 100644
--- a/chrome/browser/cocoa/notifications/balloon_controller.h
+++ b/chrome/browser/cocoa/notifications/balloon_controller.h
@@ -65,6 +65,9 @@
// The current size of the view, possibly subject to an animation completing.
- (int)desiredTotalWidth;
- (int)desiredTotalHeight;
+
+// The BalloonHost
+- (BalloonViewHost*)getHost;
@end
@interface BalloonController (UnitTesting)
diff --git a/chrome/browser/cocoa/notifications/balloon_controller.mm b/chrome/browser/cocoa/notifications/balloon_controller.mm
index f452cb4..d8a42ca 100644
--- a/chrome/browser/cocoa/notifications/balloon_controller.mm
+++ b/chrome/browser/cocoa/notifications/balloon_controller.mm
@@ -237,6 +237,11 @@ const int kDefaultShelfHeight = 22;
[self shelfHeight];
}
+// Returns the BalloonHost {
+- (BalloonViewHost*) getHost {
+ return htmlContents_.get();
+}
+
// Relative to the lower left of the frame, above the shelf.
- (NSPoint)contentsOffset {
return NSMakePoint(kLeftShadowWidth + kLeftMargin,
diff --git a/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm b/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm
index 7f48b1e..c7b565c 100644
--- a/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm
+++ b/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm
@@ -24,6 +24,12 @@ class MockBalloonCollection : public BalloonCollection {
virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) {};
virtual void DisplayChanged() {}
virtual void OnBalloonClosed(Balloon* source) {};
+ virtual const Balloons& GetActiveBalloons() {
+ NOTREACHED();
+ return balloons_;
+ }
+ private:
+ Balloons balloons_;
};
class BalloonControllerTest : public RenderViewHostTestHarness {
diff --git a/chrome/browser/cocoa/notifications/balloon_view_bridge.h b/chrome/browser/cocoa/notifications/balloon_view_bridge.h
index 5c4b927..fee9312 100644
--- a/chrome/browser/cocoa/notifications/balloon_view_bridge.h
+++ b/chrome/browser/cocoa/notifications/balloon_view_bridge.h
@@ -23,6 +23,7 @@ class BalloonViewBridge : public BalloonView {
virtual void RepositionToBalloon();
virtual void Close(bool by_user);
virtual gfx::Size GetSize() const;
+ virtual BalloonHost* GetHost() const;
private:
// Weak pointer to the balloon controller which manages the UI.
diff --git a/chrome/browser/cocoa/notifications/balloon_view_bridge.mm b/chrome/browser/cocoa/notifications/balloon_view_bridge.mm
index 89d2f39..9edf952 100644
--- a/chrome/browser/cocoa/notifications/balloon_view_bridge.mm
+++ b/chrome/browser/cocoa/notifications/balloon_view_bridge.mm
@@ -34,3 +34,6 @@ void BalloonViewBridge::Show(Balloon* balloon) {
[controller_ showWindow:nil];
}
+BalloonHost* BalloonViewBridge::GetHost() const {
+ return [controller_ getHost];
+}
diff --git a/chrome/browser/gtk/notifications/balloon_view_gtk.h b/chrome/browser/gtk/notifications/balloon_view_gtk.h
index 9655f85..b941de4 100644
--- a/chrome/browser/gtk/notifications/balloon_view_gtk.h
+++ b/chrome/browser/gtk/notifications/balloon_view_gtk.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/gtk/menu_gtk.h"
+#include "chrome/browser/gtk/notifications/balloon_view_host_gtk.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -20,7 +21,6 @@
#include "gfx/size.h"
class BalloonCollection;
-class BalloonViewHost;
class GtkThemeProvider;
class MenuGtk;
class NineBox;
@@ -45,6 +45,7 @@ class BalloonViewImpl : public BalloonView,
virtual void RepositionToBalloon();
virtual void Close(bool by_user);
virtual gfx::Size GetSize() const;
+ virtual BalloonHost* GetHost() const { return html_contents_.get(); }
private:
// NotificationObserver interface.
diff --git a/chrome/browser/notifications/balloon.h b/chrome/browser/notifications/balloon.h
index ddaa14d..2df44d9 100644
--- a/chrome/browser/notifications/balloon.h
+++ b/chrome/browser/notifications/balloon.h
@@ -17,6 +17,7 @@
class Balloon;
class BalloonCollection;
+class BalloonHost;
class Notification;
class Profile;
class SiteInstance;
@@ -40,6 +41,9 @@ class BalloonView {
// The total size of the view.
virtual gfx::Size GetSize() const = 0;
+
+ // The host for the view's contents.
+ virtual BalloonHost* GetHost() const = 0;
};
// Represents a Notification on the screen.
diff --git a/chrome/browser/notifications/balloon_collection.h b/chrome/browser/notifications/balloon_collection.h
index 998142b..2d868c4 100644
--- a/chrome/browser/notifications/balloon_collection.h
+++ b/chrome/browser/notifications/balloon_collection.h
@@ -7,6 +7,8 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
+#include <deque>
+
class Balloon;
class Notification;
class Profile;
@@ -54,6 +56,10 @@ class BalloonCollection {
// Inform the collection that a balloon was closed.
virtual void OnBalloonClosed(Balloon* source) = 0;
+ // Get const collection of the active balloons.
+ typedef std::deque<Balloon*> Balloons;
+ virtual const Balloons& GetActiveBalloons() = 0;
+
BalloonSpaceChangeListener* space_change_listener() {
return space_change_listener_;
}
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index c7fe67c..5b39f6f 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -31,6 +31,9 @@ class BalloonCollectionImpl : public BalloonCollection {
virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size);
virtual void DisplayChanged();
virtual void OnBalloonClosed(Balloon* source);
+ virtual const Balloons& GetActiveBalloons() {
+ return balloons_;
+ }
protected:
// Calculates layout values for the balloons including
diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc
index 19414a0..541d5a4 100644
--- a/chrome/browser/notifications/balloon_host.cc
+++ b/chrome/browser/notifications/balloon_host.cc
@@ -41,6 +41,7 @@ BalloonHost::BalloonHost(Balloon* balloon)
void BalloonHost::Shutdown() {
if (render_view_host_) {
+ NotifyDisconnect();
render_view_host_->Shutdown();
render_view_host_ = NULL;
}
@@ -56,27 +57,20 @@ void BalloonHost::Close(RenderViewHost* render_view_host) {
balloon_->CloseByScript();
}
-
void BalloonHost::RenderViewCreated(RenderViewHost* render_view_host) {
render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
render_view_host->routing_id()));
}
-void BalloonHost::RendererReady(RenderViewHost* render_view_host) {
+void BalloonHost::RenderViewReady(RenderViewHost* render_view_host) {
should_notify_on_disconnect_ = true;
NotificationService::current()->Notify(
NotificationType::NOTIFY_BALLOON_CONNECTED,
- Source<Balloon>(balloon_), NotificationService::NoDetails());
+ Source<BalloonHost>(this), NotificationService::NoDetails());
}
-void BalloonHost::RendererGone(RenderViewHost* render_view_host) {
- if (!should_notify_on_disconnect_)
- return;
-
- should_notify_on_disconnect_ = false;
- NotificationService::current()->Notify(
- NotificationType::NOTIFY_BALLOON_DISCONNECTED,
- Source<Balloon>(balloon_), NotificationService::NoDetails());
+void BalloonHost::RenderViewGone(RenderViewHost* render_view_host) {
+ Close(render_view_host);
}
void BalloonHost::ProcessDOMUIMessage(const std::string& message,
@@ -141,3 +135,13 @@ void BalloonHost::Init() {
initialized_ = true;
}
+
+void BalloonHost::NotifyDisconnect() {
+ if (!should_notify_on_disconnect_)
+ return;
+
+ should_notify_on_disconnect_ = false;
+ NotificationService::current()->Notify(
+ NotificationType::NOTIFY_BALLOON_DISCONNECTED,
+ Source<BalloonHost>(this), NotificationService::NoDetails());
+}
diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h
index 5935cf7..521d898 100644
--- a/chrome/browser/notifications/balloon_host.h
+++ b/chrome/browser/notifications/balloon_host.h
@@ -43,6 +43,10 @@ class BalloonHost : public RenderViewHostDelegate,
RenderViewHost* render_view_host() const { return render_view_host_; }
+ std::wstring GetSource() const {
+ return balloon_->notification().display_source();
+ }
+
// RenderViewHostDelegate overrides.
virtual WebPreferences GetWebkitPrefs();
virtual SiteInstance* GetSiteInstance() const {
@@ -54,8 +58,8 @@ class BalloonHost : public RenderViewHostDelegate,
}
virtual void Close(RenderViewHost* render_view_host);
virtual void RenderViewCreated(RenderViewHost* render_view_host);
- virtual void RendererReady(RenderViewHost* render_view_host);
- virtual void RendererGone(RenderViewHost* render_view_host);
+ virtual void RenderViewReady(RenderViewHost* render_view_host);
+ virtual void RenderViewGone(RenderViewHost* render_view_host);
virtual void UpdateTitle(RenderViewHost* render_view_host,
int32 page_id, const std::wstring& title) {}
virtual int GetBrowserWindowID() const { return -1; }
@@ -112,6 +116,10 @@ class BalloonHost : public RenderViewHostDelegate,
RenderViewHost* render_view_host_;
private:
+ // Called to send an event that the balloon has been disconnected from
+ // a renderer (if should_notify_on_disconnect_ is true).
+ void NotifyDisconnect();
+
// Non-owned pointer to the associated balloon.
Balloon* balloon_;
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index b15a46e..637d9a1 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -38,18 +38,24 @@ Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification,
// Start with a normal balloon but mock out the view.
Balloon* balloon = BalloonCollectionImpl::MakeBalloon(notification, profile);
balloon->set_view(new MockBalloonView(balloon));
- balloons_.insert(balloon);
+ balloons_.push_back(balloon);
return balloon;
}
void MockBalloonCollection::OnBalloonClosed(Balloon* source) {
- balloons_.erase(source);
- BalloonCollectionImpl::OnBalloonClosed(source);
+ std::deque<Balloon*>::iterator it;
+ for (it = balloons_.begin(); it != balloons_.end(); ++it) {
+ if (*it == source) {
+ balloons_.erase(it);
+ BalloonCollectionImpl::OnBalloonClosed(source);
+ break;
+ }
+ }
}
int MockBalloonCollection::UppermostVerticalPosition() {
int min = 0;
- std::set<Balloon*>::iterator iter;
+ std::deque<Balloon*>::iterator iter;
for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
int pos = (*iter)->position().y();
if (iter == balloons_.begin() || pos < min)
@@ -111,15 +117,10 @@ TEST_F(DesktopNotificationsTest, TestClose) {
EXPECT_EQ(1, balloon_collection_->count());
// Close all the open balloons.
- std::set<Balloon*> balloons = balloon_collection_->balloons();
- std::set<Balloon*>::iterator iter;
- for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
- (*iter)->OnClose(true);
+ while (balloon_collection_->count() > 0) {
+ (*(balloon_collection_->GetActiveBalloons().begin()))->OnClose(true);
}
- // Verify that the balloon collection is now empty.
- EXPECT_EQ(0, balloon_collection_->count());
-
EXPECT_EQ("notification displayed\n"
"notification closed by user\n",
log_output_);
@@ -190,8 +191,8 @@ TEST_F(DesktopNotificationsTest, TestVariableSize) {
0, 0, DesktopNotificationService::PageNotification, 1));
expected_log.append("notification displayed\n");
- std::set<Balloon*>& balloons = balloon_collection_->balloons();
- std::set<Balloon*>::iterator iter;
+ std::deque<Balloon*>& balloons = balloon_collection_->balloons();
+ std::deque<Balloon*>::iterator iter;
for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
if ((*iter)->notification().origin_url().host() == "long.google.com") {
EXPECT_GE((*iter)->GetViewSize().height(),
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h
index 60112c3..77e1b11 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.h
+++ b/chrome/browser/notifications/desktop_notifications_unittest.h
@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_
#define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_
-#include <set>
+#include <deque>
#include <string>
#include "base/message_loop.h"
@@ -44,9 +44,12 @@ class MockBalloonCollection : public BalloonCollectionImpl {
Profile* profile);
virtual void DisplayChanged() {}
virtual void OnBalloonClosed(Balloon* source);
+ virtual const BalloonCollection::Balloons& GetActiveBalloons() {
+ return balloons_;
+ }
// Number of balloons being shown.
- std::set<Balloon*>& balloons() { return balloons_; }
+ std::deque<Balloon*>& balloons() { return balloons_; }
int count() const { return balloons_.size(); }
// Returns the highest y-coordinate of all the balloons in the collection.
@@ -57,7 +60,7 @@ class MockBalloonCollection : public BalloonCollectionImpl {
int MaxHeight() { return Layout::max_balloon_height(); }
private:
- std::set<Balloon*> balloons_;
+ std::deque<Balloon*> balloons_;
scoped_refptr<LoggingNotificationProxy> log_proxy_;
};
diff --git a/chrome/browser/notifications/notification_test_util.h b/chrome/browser/notifications/notification_test_util.h
index 15849c4..d3ad7ee 100644
--- a/chrome/browser/notifications/notification_test_util.h
+++ b/chrome/browser/notifications/notification_test_util.h
@@ -44,6 +44,7 @@ class MockBalloonView : public BalloonView {
void RepositionToBalloon() {}
void Close(bool by_user) { balloon_->OnClose(by_user); }
gfx::Size GetSize() const { return balloon_->content_size(); }
+ BalloonHost* GetHost() const { return NULL; }
private:
// Non-owned pointer.
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index 533a696..4418cae 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -87,6 +87,10 @@ TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
new TaskManagerExtensionProcessResourceProvider(task_manager);
extension_process_provider->AddRef();
providers_.push_back(extension_process_provider);
+ TaskManagerNotificationResourceProvider* notification_provider =
+ new TaskManagerNotificationResourceProvider(task_manager);
+ notification_provider->AddRef();
+ providers_.push_back(notification_provider);
}
TaskManagerModel::~TaskManagerModel() {
diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc
index 8d43db0..e9219a3 100644
--- a/chrome/browser/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager_resource_providers.cc
@@ -22,6 +22,9 @@
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/notifications/balloon_collection.h"
+#include "chrome/browser/notifications/balloon_host.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
@@ -686,6 +689,139 @@ void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager(
}
////////////////////////////////////////////////////////////////////////////////
+// TaskManagerNotificationResource class
+////////////////////////////////////////////////////////////////////////////////
+
+SkBitmap* TaskManagerNotificationResource::default_icon_ = NULL;
+
+TaskManagerNotificationResource::TaskManagerNotificationResource(
+ BalloonHost* balloon_host)
+ : balloon_host_(balloon_host) {
+ if (!default_icon_) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
+ }
+ process_handle_ = balloon_host_->render_view_host()->process()->GetHandle();
+ pid_ = base::GetProcId(process_handle_);
+ title_ = l10n_util::GetStringF(IDS_TASK_MANAGER_NOTIFICATION_PREFIX,
+ balloon_host_->GetSource());
+}
+
+TaskManagerNotificationResource::~TaskManagerNotificationResource() {
+}
+
+SkBitmap TaskManagerNotificationResource::GetIcon() const {
+ return *default_icon_;
+}
+
+base::ProcessHandle TaskManagerNotificationResource::GetProcess() const {
+ return process_handle_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TaskManagerNotificationResourceProvider class
+////////////////////////////////////////////////////////////////////////////////
+
+TaskManagerNotificationResourceProvider::
+ TaskManagerNotificationResourceProvider(TaskManager* task_manager)
+ : task_manager_(task_manager),
+ updating_(false) {
+}
+
+TaskManagerNotificationResourceProvider::
+ ~TaskManagerNotificationResourceProvider() {
+}
+
+TaskManager::Resource* TaskManagerNotificationResourceProvider::GetResource(
+ int origin_pid,
+ int render_process_host_id,
+ int routing_id) {
+ // TODO(johnnyg): provide resources by pid if necessary.
+ return NULL;
+}
+
+void TaskManagerNotificationResourceProvider::StartUpdating() {
+ DCHECK(!updating_);
+ updating_ = true;
+
+ // Add all the existing BalloonHosts.
+ BalloonCollection* collection =
+ g_browser_process->notification_ui_manager()->balloon_collection();
+ const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons();
+ for (BalloonCollection::Balloons::const_iterator it = balloons.begin();
+ it != balloons.end(); ++it) {
+ AddToTaskManager((*it)->view()->GetHost());
+ }
+
+ // Register for notifications about extension process changes.
+ registrar_.Add(this, NotificationType::NOTIFY_BALLOON_CONNECTED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::NOTIFY_BALLOON_DISCONNECTED,
+ NotificationService::AllSources());
+}
+
+void TaskManagerNotificationResourceProvider::StopUpdating() {
+ DCHECK(updating_);
+ updating_ = false;
+
+ // Unregister for notifications about extension process changes.
+ registrar_.Remove(this, NotificationType::NOTIFY_BALLOON_CONNECTED,
+ NotificationService::AllSources());
+ registrar_.Remove(this, NotificationType::NOTIFY_BALLOON_DISCONNECTED,
+ NotificationService::AllSources());
+
+ // Delete all the resources.
+ STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
+ resources_.clear();
+}
+
+void TaskManagerNotificationResourceProvider::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::NOTIFY_BALLOON_CONNECTED:
+ AddToTaskManager(Source<BalloonHost>(source).ptr());
+ break;
+ case NotificationType::NOTIFY_BALLOON_DISCONNECTED:
+ RemoveFromTaskManager(Source<BalloonHost>(source).ptr());
+ break;
+ default:
+ NOTREACHED() << "Unexpected notification.";
+ return;
+ }
+}
+
+void TaskManagerNotificationResourceProvider::AddToTaskManager(
+ BalloonHost* balloon_host) {
+ TaskManagerNotificationResource* resource =
+ new TaskManagerNotificationResource(balloon_host);
+ DCHECK(resources_.find(balloon_host) == resources_.end());
+ resources_[balloon_host] = resource;
+ task_manager_->AddResource(resource);
+}
+
+void TaskManagerNotificationResourceProvider::RemoveFromTaskManager(
+ BalloonHost* balloon_host) {
+ if (!updating_)
+ return;
+ std::map<BalloonHost*, TaskManagerNotificationResource*>::iterator iter =
+ resources_.find(balloon_host);
+ if (iter == resources_.end())
+ return;
+
+ // Remove the resource from the Task Manager.
+ TaskManagerNotificationResource* resource = iter->second;
+ task_manager_->RemoveResource(resource);
+
+ // Remove it from the map.
+ resources_.erase(iter);
+
+ // Finally, delete the resource.
+ delete resource;
+}
+
+////////////////////////////////////////////////////////////////////////////////
// TaskManagerBrowserProcessResource class
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h
index 65209f4..8de984d 100644
--- a/chrome/browser/task_manager_resource_providers.h
+++ b/chrome/browser/task_manager_resource_providers.h
@@ -16,6 +16,7 @@
#include "chrome/common/notification_registrar.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
+class BalloonHost;
class Extension;
class ExtensionHost;
class TabContents;
@@ -271,6 +272,70 @@ class TaskManagerExtensionProcessResourceProvider
DISALLOW_COPY_AND_ASSIGN(TaskManagerExtensionProcessResourceProvider);
};
+class TaskManagerNotificationResource : public TaskManager::Resource {
+ public:
+ explicit TaskManagerNotificationResource(BalloonHost* balloon_host);
+ ~TaskManagerNotificationResource();
+
+ // TaskManager::Resource interface
+ std::wstring GetTitle() const { return title_; }
+ SkBitmap GetIcon() const;
+ base::ProcessHandle GetProcess() const;
+ virtual bool SupportNetworkUsage() const { return false; }
+ virtual void SetSupportNetworkUsage() { }
+
+ private:
+ // The icon painted for notifications. .
+ static SkBitmap* default_icon_;
+
+ // Non-owned pointer to the balloon host.
+ BalloonHost* balloon_host_;
+
+ // Cached data about the balloon host.
+ base::ProcessHandle process_handle_;
+ int pid_;
+ std::wstring title_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerNotificationResource);
+};
+
+class TaskManagerNotificationResourceProvider
+ : public TaskManager::ResourceProvider,
+ public NotificationObserver {
+ public:
+ explicit TaskManagerNotificationResourceProvider(TaskManager* task_manager);
+
+ // TaskManager::ResourceProvider interface
+ virtual TaskManager::Resource* GetResource(int origin_pid,
+ int render_process_host_id,
+ int routing_id);
+ virtual void StartUpdating();
+ virtual void StopUpdating();
+
+ // NotificationObserver interface
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ private:
+ virtual ~TaskManagerNotificationResourceProvider();
+
+ void AddToTaskManager(BalloonHost* balloon_host);
+ void RemoveFromTaskManager(BalloonHost* balloon_host);
+
+ TaskManager* task_manager_;
+
+ // Maps the actual resources (BalloonHost*) to the Task Manager resources.
+ std::map<BalloonHost*, TaskManagerNotificationResource*> resources_;
+
+ // A scoped container for notification registries.
+ NotificationRegistrar registrar_;
+
+ bool updating_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerNotificationResourceProvider);
+};
+
class TaskManagerBrowserProcessResource : public TaskManager::Resource {
public:
TaskManagerBrowserProcessResource();
diff --git a/chrome/browser/views/notifications/balloon_view.h b/chrome/browser/views/notifications/balloon_view.h
index 2e11f1c..775b474 100644
--- a/chrome/browser/views/notifications/balloon_view.h
+++ b/chrome/browser/views/notifications/balloon_view.h
@@ -13,6 +13,7 @@
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/views/notifications/balloon_view_host.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
#include "gfx/path.h"
@@ -34,7 +35,6 @@ class Menu2;
} // namespace views
class BalloonCollection;
-class BalloonViewHost;
class NotificationDetails;
class NotificationSource;
class SlideAnimation;
@@ -59,6 +59,7 @@ class BalloonViewImpl : public BalloonView,
virtual void RepositionToBalloon();
virtual void Close(bool by_user);
virtual gfx::Size GetSize() const;
+ virtual BalloonHost* GetHost() const { return html_contents_; }
private:
// views::View interface.
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 04d7101..3c7806b 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -832,14 +832,15 @@ class NotificationType {
// Desktop Notifications ---------------------------------------------------
// This notification is sent when a balloon is connected to a renderer
- // process to render the balloon contents. The source is a Source<Balloon>
- // with a pointer to the the balloon. A NOTIFY_BALLOON_DISCONNECTED is
- // guaranteed before the source pointer becomes junk. No details expected.
+ // process to render the balloon contents. The source is a
+ // Source<BalloonHost> with a pointer to the the balloon. A
+ // NOTIFY_BALLOON_DISCONNECTED is guaranteed before the source pointer
+ // becomes junk. No details expected.
NOTIFY_BALLOON_CONNECTED,
// This message is sent after a balloon is disconnected from the renderer
- // process. The source is a Source<Balloon> with a pointer to the balloon
- // (the pointer is usable). No details are expected.
+ // process. The source is a Source<BalloonHost> with a pointer to the
+ // balloon host (the pointer is usable). No details are expected.
NOTIFY_BALLOON_DISCONNECTED,
// Web Database Service ----------------------------------------------------