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

Unified Diff: chrome/browser/devtools/devtools_targets_ui.cc

Issue 562513003: [DevTools] Unify workers and web contents handling in inspect_ui. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, fixed comment Created 6 years, 3 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
« no previous file with comments | « chrome/browser/devtools/devtools_targets_ui.h ('k') | chrome/browser/resources/inspect/inspect.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/devtools_targets_ui.cc
diff --git a/chrome/browser/devtools/devtools_targets_ui.cc b/chrome/browser/devtools/devtools_targets_ui.cc
index 69f4ec2343c31a674de6f068204b3ff66926e7ee..15e017696e948a69db2ad9e17d4cfb5e81ac0737 100644
--- a/chrome/browser/devtools/devtools_targets_ui.cc
+++ b/chrome/browser/devtools/devtools_targets_ui.cc
@@ -30,9 +30,8 @@ using content::BrowserThread;
namespace {
const char kTargetSourceField[] = "source";
-const char kTargetSourceRenderer[] = "renderers";
-const char kTargetSourceWorker[] = "workers";
-const char kTargetSourceAdb[] = "adb";
+const char kTargetSourceLocal[] = "local";
+const char kTargetSourceRemote[] = "remote";
const char kTargetIdField[] = "id";
const char kTargetTypeField[] = "type";
@@ -80,95 +79,6 @@ class CancelableTimer {
base::WeakPtrFactory<CancelableTimer> weak_factory_;
};
-// RenderViewHostTargetsUIHandler ---------------------------------------------
-
-class RenderViewHostTargetsUIHandler
- : public DevToolsTargetsUIHandler,
- public content::NotificationObserver {
- public:
- explicit RenderViewHostTargetsUIHandler(const Callback& callback);
- virtual ~RenderViewHostTargetsUIHandler();
-
- private:
- // content::NotificationObserver overrides.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
- void UpdateTargets();
-
- content::NotificationRegistrar notification_registrar_;
- scoped_ptr<CancelableTimer> timer_;
-};
-
-RenderViewHostTargetsUIHandler::RenderViewHostTargetsUIHandler(
- const Callback& callback)
- : DevToolsTargetsUIHandler(kTargetSourceRenderer, callback) {
- notification_registrar_.Add(this,
- content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
- content::NotificationService::AllSources());
- notification_registrar_.Add(this,
- content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
- content::NotificationService::AllSources());
- notification_registrar_.Add(this,
- content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
- content::NotificationService::AllSources());
- UpdateTargets();
-}
-
-RenderViewHostTargetsUIHandler::~RenderViewHostTargetsUIHandler() {
- notification_registrar_.RemoveAll();
-}
-
-void RenderViewHostTargetsUIHandler::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- const int kUpdateDelay = 100;
- timer_.reset(
- new CancelableTimer(
- base::Bind(&RenderViewHostTargetsUIHandler::UpdateTargets,
- base::Unretained(this)),
- base::TimeDelta::FromMilliseconds(kUpdateDelay)));
-}
-
-void RenderViewHostTargetsUIHandler::UpdateTargets() {
- base::ListValue list_value;
-
- std::map<std::string, base::DictionaryValue*> id_to_descriptor;
-
- DevToolsTargetImpl::List targets =
- DevToolsTargetImpl::EnumerateWebContentsTargets();
-
- STLDeleteValues(&targets_);
- for (DevToolsTargetImpl::List::iterator it = targets.begin();
- it != targets.end(); ++it) {
- DevToolsTargetImpl* target = *it;
- targets_[target->GetId()] = target;
- id_to_descriptor[target->GetId()] = Serialize(*target);
- }
-
- for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) {
- DevToolsTargetImpl* target = it->second;
- base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()];
-
- std::string parent_id = target->GetParentId();
- if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) {
- list_value.Append(descriptor);
- } else {
- base::DictionaryValue* parent = id_to_descriptor[parent_id];
- base::ListValue* guests = NULL;
- if (!parent->GetList(kGuestList, &guests)) {
- guests = new base::ListValue();
- parent->Set(kGuestList, guests);
- }
- guests->Append(descriptor);
- }
- }
-
- SendSerializedTargets(list_value);
-}
-
// WorkerObserver -------------------------------------------------------------
class WorkerObserver
@@ -177,7 +87,7 @@ class WorkerObserver
public:
WorkerObserver() {}
- void Start(DevToolsTargetImpl::Callback callback) {
+ void Start(base::Closure callback) {
DCHECK(callback_.is_null());
DCHECK(!callback.is_null());
callback_ = callback;
@@ -188,19 +98,12 @@ class WorkerObserver
void Stop() {
DCHECK(!callback_.is_null());
- callback_ = DevToolsTargetImpl::Callback();
+ callback_ = base::Closure();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&WorkerObserver::StopOnIOThread, this));
}
- void Enumerate() {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&WorkerObserver::EnumerateOnIOThread,
- this));
- }
-
private:
friend class base::RefCountedThreadSafe<WorkerObserver>;
virtual ~WorkerObserver() {}
@@ -211,74 +114,145 @@ class WorkerObserver
const base::string16& name,
int process_id,
int route_id) OVERRIDE {
- EnumerateOnIOThread();
+ NotifyOnIOThread();
}
virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE {
- EnumerateOnIOThread();
+ NotifyOnIOThread();
}
void StartOnIOThread() {
content::WorkerService::GetInstance()->AddObserver(this);
- EnumerateOnIOThread();
}
void StopOnIOThread() {
content::WorkerService::GetInstance()->RemoveObserver(this);
}
- void EnumerateOnIOThread() {
+ void NotifyOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DevToolsTargetImpl::EnumerateWorkerTargets(
- base::Bind(&WorkerObserver::RespondOnUIThread, this));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WorkerObserver::NotifyOnUIThread, this));
}
- void RespondOnUIThread(const DevToolsTargetImpl::List& targets) {
+ void NotifyOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (callback_.is_null())
return;
- callback_.Run(targets);
+ callback_.Run();
}
- DevToolsTargetImpl::Callback callback_;
+ // Accessed on UI thread.
+ base::Closure callback_;
};
-// WorkerTargetsUIHandler -----------------------------------------------------
+// LocalTargetsUIHandler ---------------------------------------------
-class WorkerTargetsUIHandler
- : public DevToolsTargetsUIHandler {
+class LocalTargetsUIHandler
+ : public DevToolsTargetsUIHandler,
+ public content::NotificationObserver {
public:
- explicit WorkerTargetsUIHandler(const Callback& callback);
- virtual ~WorkerTargetsUIHandler();
+ explicit LocalTargetsUIHandler(const Callback& callback);
+ virtual ~LocalTargetsUIHandler();
- private:
- void UpdateTargets(const DevToolsTargetImpl::List& targets);
+private:
+ // content::NotificationObserver overrides.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+ void ScheduleUpdate();
+ void UpdateTargets();
+ void SendTargets(const DevToolsTargetImpl::List& targets);
+
+ content::NotificationRegistrar notification_registrar_;
+ scoped_ptr<CancelableTimer> timer_;
scoped_refptr<WorkerObserver> observer_;
+ base::WeakPtrFactory<LocalTargetsUIHandler> weak_factory_;
};
-WorkerTargetsUIHandler::WorkerTargetsUIHandler(const Callback& callback)
- : DevToolsTargetsUIHandler(kTargetSourceWorker, callback),
- observer_(new WorkerObserver()) {
- observer_->Start(base::Bind(&WorkerTargetsUIHandler::UpdateTargets,
+LocalTargetsUIHandler::LocalTargetsUIHandler(
+ const Callback& callback)
+ : DevToolsTargetsUIHandler(kTargetSourceLocal, callback),
+ observer_(new WorkerObserver()),
+ weak_factory_(this) {
+ notification_registrar_.Add(this,
+ content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
+ content::NotificationService::AllSources());
+ notification_registrar_.Add(this,
+ content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
+ content::NotificationService::AllSources());
+ notification_registrar_.Add(this,
+ content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
+ content::NotificationService::AllSources());
+ observer_->Start(base::Bind(&LocalTargetsUIHandler::ScheduleUpdate,
base::Unretained(this)));
+ UpdateTargets();
}
-WorkerTargetsUIHandler::~WorkerTargetsUIHandler() {
+LocalTargetsUIHandler::~LocalTargetsUIHandler() {
+ notification_registrar_.RemoveAll();
observer_->Stop();
}
-void WorkerTargetsUIHandler::UpdateTargets(
+void LocalTargetsUIHandler::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ ScheduleUpdate();
+}
+
+void LocalTargetsUIHandler::ScheduleUpdate() {
+ const int kUpdateDelay = 100;
+ timer_.reset(
+ new CancelableTimer(
+ base::Bind(&LocalTargetsUIHandler::UpdateTargets,
+ base::Unretained(this)),
+ base::TimeDelta::FromMilliseconds(kUpdateDelay)));
+}
+
+void LocalTargetsUIHandler::UpdateTargets() {
+ DevToolsTargetImpl::EnumerateAllTargets(base::Bind(
+ &LocalTargetsUIHandler::SendTargets,
+ weak_factory_.GetWeakPtr()));
+}
+
+void LocalTargetsUIHandler::SendTargets(
const DevToolsTargetImpl::List& targets) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::ListValue list_value;
+ std::map<std::string, base::DictionaryValue*> id_to_descriptor;
+
STLDeleteValues(&targets_);
for (DevToolsTargetImpl::List::const_iterator it = targets.begin();
it != targets.end(); ++it) {
DevToolsTargetImpl* target = *it;
- list_value.Append(Serialize(*target));
+ if (target->GetType() == DevToolsTargetImpl::kTargetTypeServiceWorker)
+ continue;
targets_[target->GetId()] = target;
+ id_to_descriptor[target->GetId()] = Serialize(*target);
+ }
+
+ for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) {
+ DevToolsTargetImpl* target = it->second;
+ if (target->GetType() == DevToolsTargetImpl::kTargetTypeServiceWorker)
+ continue;
+ base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()];
+
+ std::string parent_id = target->GetParentId();
+ if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) {
+ list_value.Append(descriptor);
+ } else {
+ base::DictionaryValue* parent = id_to_descriptor[parent_id];
+ base::ListValue* guests = NULL;
+ if (!parent->GetList(kGuestList, &guests)) {
+ guests = new base::ListValue();
+ parent->Set(kGuestList, guests);
+ }
+ guests->Append(descriptor);
+ }
}
+
SendSerializedTargets(list_value);
}
@@ -312,7 +286,7 @@ class AdbTargetsUIHandler
AdbTargetsUIHandler::AdbTargetsUIHandler(const Callback& callback,
Profile* profile)
- : DevToolsTargetsUIHandler(kTargetSourceAdb, callback),
+ : DevToolsTargetsUIHandler(kTargetSourceRemote, callback),
profile_(profile) {
DevToolsAndroidBridge* android_bridge =
DevToolsAndroidBridge::Factory::GetForProfile(profile_);
@@ -449,18 +423,10 @@ DevToolsTargetsUIHandler::~DevToolsTargetsUIHandler() {
// static
scoped_ptr<DevToolsTargetsUIHandler>
-DevToolsTargetsUIHandler::CreateForRenderers(
- const DevToolsTargetsUIHandler::Callback& callback) {
- return scoped_ptr<DevToolsTargetsUIHandler>(
- new RenderViewHostTargetsUIHandler(callback));
-}
-
-// static
-scoped_ptr<DevToolsTargetsUIHandler>
-DevToolsTargetsUIHandler::CreateForWorkers(
+DevToolsTargetsUIHandler::CreateForLocal(
const DevToolsTargetsUIHandler::Callback& callback) {
return scoped_ptr<DevToolsTargetsUIHandler>(
- new WorkerTargetsUIHandler(callback));
+ new LocalTargetsUIHandler(callback));
}
// static
« no previous file with comments | « chrome/browser/devtools/devtools_targets_ui.h ('k') | chrome/browser/resources/inspect/inspect.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698