Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Unified Diff: chrome/browser/task_manager/task_manager_worker_resource_provider.cc

Issue 12212089: content: convert child process notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: private Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/task_manager/task_manager_worker_resource_provider.cc
diff --git a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc
index cce8f2264bf5a873ca34db94bbc50ef0dc34972e..51823bb50c8ef3ef378d0294c384495ade1dc970 100644
--- a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc
+++ b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc
@@ -14,8 +14,6 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/devtools_agent_host.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_types.h"
#include "content/public/browser/worker_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -191,16 +189,13 @@ TaskManager::Resource* TaskManagerWorkerResourceProvider::GetResource(
void TaskManagerWorkerResourceProvider::StartUpdating() {
DCHECK(!updating_);
updating_ = true;
- // Register for notifications to get new child processes.
- registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED,
- content::NotificationService::AllBrowserContextsAndSources());
- registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED,
- content::NotificationService::AllBrowserContextsAndSources());
// Get existing workers.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(
&TaskManagerWorkerResourceProvider::StartObservingWorkers,
this));
+
+ BrowserChildProcessObserver::Add(this);
}
void TaskManagerWorkerResourceProvider::StopUpdating() {
@@ -208,16 +203,55 @@ void TaskManagerWorkerResourceProvider::StopUpdating() {
updating_ = false;
launching_workers_.clear();
DeleteAllResources();
- registrar_.Remove(
- this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED,
- content::NotificationService::AllBrowserContextsAndSources());
- registrar_.Remove(
- this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED,
- content::NotificationService::AllBrowserContextsAndSources());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(
&TaskManagerWorkerResourceProvider::StopObservingWorkers,
this));
+
+ BrowserChildProcessObserver::Remove(this);
+}
+
+void TaskManagerWorkerResourceProvider::BrowserChildProcessHostConnected(
+ const content::ChildProcessData& data) {
+ DCHECK(updating_);
+
+ if (data.type != content::PROCESS_TYPE_WORKER)
+ return;
+
+ ProcessIdToWorkerResources::iterator it(launching_workers_.find(data.id));
+ if (it == launching_workers_.end())
+ return;
+ WorkerResourceList& resources = it->second;
+ for (WorkerResourceList::iterator r = resources.begin();
+ r != resources.end(); ++r) {
+ (*r)->UpdateProcessHandle(data.handle);
+ task_manager_->AddResource(*r);
+ }
+ launching_workers_.erase(it);
+}
+
+void TaskManagerWorkerResourceProvider::BrowserChildProcessHostDisconnected(
+ const content::ChildProcessData& data) {
+ DCHECK(updating_);
+
+ if (data.type != content::PROCESS_TYPE_WORKER)
+ return;
+
+ // Worker process may be destroyed before WorkerMsg_TerminateWorkerContex
+ // message is handled and WorkerDestroyed is fired. In this case we won't
+ // get WorkerDestroyed notification and have to clear resources for such
+ // workers here when the worker process has been destroyed.
+ for (WorkerResourceList::iterator it = resources_.begin();
+ it != resources_.end();) {
+ if ((*it)->process_id() == data.id) {
+ task_manager_->RemoveResource(*it);
+ delete *it;
+ it = resources_.erase(it);
+ } else {
+ ++it;
+ }
+ }
+ DCHECK(!ContainsKey(launching_workers_, data.id));
}
void TaskManagerWorkerResourceProvider::WorkerCreated(
@@ -242,46 +276,6 @@ void TaskManagerWorkerResourceProvider::WorkerDestroyed(int process_id,
this, process_id, route_id));
}
-void TaskManagerWorkerResourceProvider::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- content::ChildProcessData* process_data =
- content::Details<content::ChildProcessData>(details).ptr();
- if (process_data->type != content::PROCESS_TYPE_WORKER)
- return;
- if (type == content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED) {
- ProcessIdToWorkerResources::iterator it =
- launching_workers_.find(process_data->id);
- if (it == launching_workers_.end())
- return;
- WorkerResourceList& resources = it->second;
- for (WorkerResourceList::iterator r = resources.begin();
- r !=resources.end(); ++r) {
- (*r)->UpdateProcessHandle(process_data->handle);
- task_manager_->AddResource(*r);
- }
- launching_workers_.erase(it);
- } else if (type == content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED) {
- // Worker process may be destroyed before WorkerMsg_TerminateWorkerContex
- // message is handled and WorkerDestroyed is fired. In this case we won't
- // get WorkerDestroyed notification and have to clear resources for such
- // workers here when the worker process has been destroyed.
- for (WorkerResourceList::iterator it = resources_.begin();
- it !=resources_.end();) {
- if ((*it)->process_id() == process_data->id) {
- task_manager_->RemoveResource(*it);
- delete *it;
- it = resources_.erase(it);
- } else {
- ++it;
- }
- }
- DCHECK(launching_workers_.find(process_data->id) ==
- launching_workers_.end());
- }
-}
-
void TaskManagerWorkerResourceProvider::NotifyWorkerCreated(
WorkerResourceHolder* resource_holder) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
« no previous file with comments | « chrome/browser/task_manager/task_manager_worker_resource_provider.h ('k') | content/browser/browser_child_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698