| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/devtools/devtools_targets_ui.h" | 5 #include "chrome/browser/devtools/devtools_targets_ui.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 return; | 239 return; |
| 240 callback_.Run(targets); | 240 callback_.Run(targets); |
| 241 } | 241 } |
| 242 | 242 |
| 243 DevToolsTargetImpl::Callback callback_; | 243 DevToolsTargetImpl::Callback callback_; |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 // WorkerTargetsUIHandler ----------------------------------------------------- | 246 // WorkerTargetsUIHandler ----------------------------------------------------- |
| 247 | 247 |
| 248 class WorkerTargetsUIHandler | 248 class WorkerTargetsUIHandler |
| 249 : public DevToolsTargetsUIHandler, | 249 : public DevToolsTargetsUIHandler { |
| 250 public content::BrowserChildProcessObserver { | |
| 251 public: | 250 public: |
| 252 explicit WorkerTargetsUIHandler(const Callback& callback); | 251 explicit WorkerTargetsUIHandler(const Callback& callback); |
| 253 virtual ~WorkerTargetsUIHandler(); | 252 virtual ~WorkerTargetsUIHandler(); |
| 254 | 253 |
| 255 private: | 254 private: |
| 256 // content::BrowserChildProcessObserver overrides. | |
| 257 virtual void BrowserChildProcessHostConnected( | |
| 258 const content::ChildProcessData& data) OVERRIDE; | |
| 259 virtual void BrowserChildProcessHostDisconnected( | |
| 260 const content::ChildProcessData& data) OVERRIDE; | |
| 261 | |
| 262 void UpdateTargets(const DevToolsTargetImpl::List& targets); | 255 void UpdateTargets(const DevToolsTargetImpl::List& targets); |
| 263 | 256 |
| 264 scoped_refptr<WorkerObserver> observer_; | 257 scoped_refptr<WorkerObserver> observer_; |
| 265 }; | 258 }; |
| 266 | 259 |
| 267 WorkerTargetsUIHandler::WorkerTargetsUIHandler(const Callback& callback) | 260 WorkerTargetsUIHandler::WorkerTargetsUIHandler(const Callback& callback) |
| 268 : DevToolsTargetsUIHandler(kTargetSourceWorker, callback), | 261 : DevToolsTargetsUIHandler(kTargetSourceWorker, callback), |
| 269 observer_(new WorkerObserver()) { | 262 observer_(new WorkerObserver()) { |
| 270 observer_->Start(base::Bind(&WorkerTargetsUIHandler::UpdateTargets, | 263 observer_->Start(base::Bind(&WorkerTargetsUIHandler::UpdateTargets, |
| 271 base::Unretained(this))); | 264 base::Unretained(this))); |
| 272 BrowserChildProcessObserver::Add(this); | |
| 273 } | 265 } |
| 274 | 266 |
| 275 WorkerTargetsUIHandler::~WorkerTargetsUIHandler() { | 267 WorkerTargetsUIHandler::~WorkerTargetsUIHandler() { |
| 276 BrowserChildProcessObserver::Remove(this); | |
| 277 observer_->Stop(); | 268 observer_->Stop(); |
| 278 } | 269 } |
| 279 | 270 |
| 280 void WorkerTargetsUIHandler::BrowserChildProcessHostConnected( | |
| 281 const content::ChildProcessData& data) { | |
| 282 if (data.process_type == content::PROCESS_TYPE_WORKER) | |
| 283 observer_->Enumerate(); | |
| 284 } | |
| 285 | |
| 286 void WorkerTargetsUIHandler::BrowserChildProcessHostDisconnected( | |
| 287 const content::ChildProcessData& data) { | |
| 288 if (data.process_type == content::PROCESS_TYPE_WORKER) | |
| 289 observer_->Enumerate(); | |
| 290 } | |
| 291 | |
| 292 void WorkerTargetsUIHandler::UpdateTargets( | 271 void WorkerTargetsUIHandler::UpdateTargets( |
| 293 const DevToolsTargetImpl::List& targets) { | 272 const DevToolsTargetImpl::List& targets) { |
| 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 295 base::ListValue list_value; | 274 base::ListValue list_value; |
| 296 STLDeleteValues(&targets_); | 275 STLDeleteValues(&targets_); |
| 297 for (DevToolsTargetImpl::List::const_iterator it = targets.begin(); | 276 for (DevToolsTargetImpl::List::const_iterator it = targets.begin(); |
| 298 it != targets.end(); ++it) { | 277 it != targets.end(); ++it) { |
| 299 DevToolsTargetImpl* target = *it; | 278 DevToolsTargetImpl* target = *it; |
| 300 list_value.Append(Serialize(*target)); | 279 list_value.Append(Serialize(*target)); |
| 301 targets_[target->GetId()] = target; | 280 targets_[target->GetId()] = target; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 base::StringPrintf("%d", it->first), it->second); | 541 base::StringPrintf("%d", it->first), it->second); |
| 563 } | 542 } |
| 564 | 543 |
| 565 std::string device_id = base::StringPrintf( | 544 std::string device_id = base::StringPrintf( |
| 566 kAdbDeviceIdFormat, | 545 kAdbDeviceIdFormat, |
| 567 sit->first.c_str()); | 546 sit->first.c_str()); |
| 568 result.Set(device_id, device_status_dict); | 547 result.Set(device_id, device_status_dict); |
| 569 } | 548 } |
| 570 callback_.Run(result); | 549 callback_.Run(result); |
| 571 } | 550 } |
| OLD | NEW |