summaryrefslogtreecommitdiffstats
path: root/chrome/browser/task_manager/web_contents_information.cc
diff options
context:
space:
mode:
authornick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 12:39:23 +0000
committernick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 12:39:23 +0000
commit4bf7283e0b24061f5c254d0c443198b2346bfe4a (patch)
tree4ba9b2a2cf00d5062d3df97632e6d4a798878451 /chrome/browser/task_manager/web_contents_information.cc
parentd1895670eda3166276ab46c6e8419f965dc47372 (diff)
downloadchromium_src-4bf7283e0b24061f5c254d0c443198b2346bfe4a.zip
chromium_src-4bf7283e0b24061f5c254d0c443198b2346bfe4a.tar.gz
chromium_src-4bf7283e0b24061f5c254d0c443198b2346bfe4a.tar.bz2
Step 1 in unifying the task manager's WebContents-based ResourceProviders.
Motivation. The primary motivation here is to centralize the tracking of WebContents, so that the upcoming logic that shows cross-process iframes in the task manager does not have to be copied five times. A secondary motivations is to eliminate uses of some (but not all) deprecated notification service notifications, switching to WebContentsObserver instead. Design. A new class, WebContentsResourceProvider, will provides resources to the task manager on behalf of a chrome service that owns WebContentses. The chrome services will be parameterized via another new interface, WebContentsInformation, which provides a list of WebContentses to track and also acts as a RendererResource* factory. The WebContentsInformation is responsible for notifying the WebContentsResourceProvider of the existence of new WebContents* instances only (not deletion/updates). This is because for the rest of the tracking, WebContentsResourceProvider creates a WebContentsObserver. The WebContentsInformation impls will derive from, as an implementation detail, an abstract base class called NotificationObservingWebContentsInformation. This base class takes care of listening for NOTIFICATION_WEB_CONTENTS_CONNECTED. In this CL, serving as an example, only the Panel resource provider is replaced: PanelResourceProvider just becomes a much smaller PanelInformation, and the TaskManager instantiates a WebContentsResourceProvider, passing instance of PanelInformation as its |info_| parameter. Direction. In subsequent CLs this new mechanism will subsume the commonly implemented parts of Extension, Panel, TabContents, and Background resource providers. This promises to be a net deletion of code, on account of how much duplicate functionality existed between these classes. BUG=348836 TEST=browser_tests Review URL: https://codereview.chromium.org/196203003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/task_manager/web_contents_information.cc')
-rw-r--r--chrome/browser/task_manager/web_contents_information.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/chrome/browser/task_manager/web_contents_information.cc b/chrome/browser/task_manager/web_contents_information.cc
new file mode 100644
index 0000000..c82cd16
--- /dev/null
+++ b/chrome/browser/task_manager/web_contents_information.cc
@@ -0,0 +1,52 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// 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/web_contents_information.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+
+namespace task_manager {
+
+WebContentsInformation::WebContentsInformation() {}
+
+WebContentsInformation::~WebContentsInformation() {}
+
+NotificationObservingWebContentsInformation::
+ NotificationObservingWebContentsInformation() {}
+
+NotificationObservingWebContentsInformation::
+ ~NotificationObservingWebContentsInformation() {}
+
+void NotificationObservingWebContentsInformation::StartObservingCreation(
+ const NewWebContentsCallback& callback) {
+ observer_callback_ = callback;
+ registrar_.Add(this,
+ content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
+ content::NotificationService::AllBrowserContextsAndSources());
+}
+
+void NotificationObservingWebContentsInformation::StopObservingCreation() {
+ registrar_.Remove(
+ this,
+ content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
+ content::NotificationService::AllBrowserContextsAndSources());
+ observer_callback_.Reset();
+}
+
+void NotificationObservingWebContentsInformation::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ content::WebContents* web_contents =
+ content::Source<content::WebContents>(source).ptr();
+
+ switch (type) {
+ case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
+ if (CheckOwnership(web_contents))
+ observer_callback_.Run(web_contents);
+ break;
+ }
+}
+
+} // namespace task_manager