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

Side by Side Diff: chrome/browser/devtools/devtools_targets_ui.cc

Issue 568403002: Unify shared and service workers in chrome://inspect, remove service workers iframe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed review comments 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 unified diff | Download patch
OLDNEW
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 // LocalTargetsUIHandler --------------------------------------------- 150 // LocalTargetsUIHandler ---------------------------------------------
151 151
152 class LocalTargetsUIHandler 152 class LocalTargetsUIHandler
153 : public DevToolsTargetsUIHandler, 153 : public DevToolsTargetsUIHandler,
154 public content::NotificationObserver { 154 public content::NotificationObserver {
155 public: 155 public:
156 explicit LocalTargetsUIHandler(const Callback& callback); 156 explicit LocalTargetsUIHandler(const Callback& callback);
157 virtual ~LocalTargetsUIHandler(); 157 virtual ~LocalTargetsUIHandler();
158 158
159 // DevToolsTargetsUIHandler overrides.
160 virtual void ForceUpdate() OVERRIDE;
161
159 private: 162 private:
160 // content::NotificationObserver overrides. 163 // content::NotificationObserver overrides.
161 virtual void Observe(int type, 164 virtual void Observe(int type,
162 const content::NotificationSource& source, 165 const content::NotificationSource& source,
163 const content::NotificationDetails& details) OVERRIDE; 166 const content::NotificationDetails& details) OVERRIDE;
164 167
165 void ScheduleUpdate(); 168 void ScheduleUpdate();
166 void UpdateTargets(); 169 void UpdateTargets();
167 void SendTargets(const DevToolsTargetImpl::List& targets); 170 void SendTargets(const DevToolsTargetImpl::List& targets);
168 171
(...skipping 27 matching lines...) Expand all
196 observer_->Stop(); 199 observer_->Stop();
197 } 200 }
198 201
199 void LocalTargetsUIHandler::Observe( 202 void LocalTargetsUIHandler::Observe(
200 int type, 203 int type,
201 const content::NotificationSource& source, 204 const content::NotificationSource& source,
202 const content::NotificationDetails& details) { 205 const content::NotificationDetails& details) {
203 ScheduleUpdate(); 206 ScheduleUpdate();
204 } 207 }
205 208
209 void LocalTargetsUIHandler::ForceUpdate() {
210 ScheduleUpdate();
211 }
212
206 void LocalTargetsUIHandler::ScheduleUpdate() { 213 void LocalTargetsUIHandler::ScheduleUpdate() {
207 const int kUpdateDelay = 100; 214 const int kUpdateDelay = 100;
208 timer_.reset( 215 timer_.reset(
209 new CancelableTimer( 216 new CancelableTimer(
210 base::Bind(&LocalTargetsUIHandler::UpdateTargets, 217 base::Bind(&LocalTargetsUIHandler::UpdateTargets,
211 base::Unretained(this)), 218 base::Unretained(this)),
212 base::TimeDelta::FromMilliseconds(kUpdateDelay))); 219 base::TimeDelta::FromMilliseconds(kUpdateDelay)));
213 } 220 }
214 221
215 void LocalTargetsUIHandler::UpdateTargets() { 222 void LocalTargetsUIHandler::UpdateTargets() {
216 DevToolsTargetImpl::EnumerateAllTargets(base::Bind( 223 DevToolsTargetImpl::EnumerateAllTargets(base::Bind(
217 &LocalTargetsUIHandler::SendTargets, 224 &LocalTargetsUIHandler::SendTargets,
218 weak_factory_.GetWeakPtr())); 225 weak_factory_.GetWeakPtr()));
219 } 226 }
220 227
221 void LocalTargetsUIHandler::SendTargets( 228 void LocalTargetsUIHandler::SendTargets(
222 const DevToolsTargetImpl::List& targets) { 229 const DevToolsTargetImpl::List& targets) {
223 base::ListValue list_value; 230 base::ListValue list_value;
224 std::map<std::string, base::DictionaryValue*> id_to_descriptor; 231 std::map<std::string, base::DictionaryValue*> id_to_descriptor;
225 232
226 STLDeleteValues(&targets_); 233 STLDeleteValues(&targets_);
227 for (DevToolsTargetImpl::List::const_iterator it = targets.begin(); 234 for (DevToolsTargetImpl::List::const_iterator it = targets.begin();
228 it != targets.end(); ++it) { 235 it != targets.end(); ++it) {
229 DevToolsTargetImpl* target = *it; 236 DevToolsTargetImpl* target = *it;
230 if (target->GetType() == DevToolsTargetImpl::kTargetTypeServiceWorker)
231 continue;
232 targets_[target->GetId()] = target; 237 targets_[target->GetId()] = target;
233 id_to_descriptor[target->GetId()] = Serialize(*target); 238 id_to_descriptor[target->GetId()] = Serialize(*target);
234 } 239 }
235 240
236 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { 241 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) {
237 DevToolsTargetImpl* target = it->second; 242 DevToolsTargetImpl* target = it->second;
238 if (target->GetType() == DevToolsTargetImpl::kTargetTypeServiceWorker)
239 continue;
240 base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()]; 243 base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()];
241
242 std::string parent_id = target->GetParentId(); 244 std::string parent_id = target->GetParentId();
243 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { 245 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) {
244 list_value.Append(descriptor); 246 list_value.Append(descriptor);
245 } else { 247 } else {
246 base::DictionaryValue* parent = id_to_descriptor[parent_id]; 248 base::DictionaryValue* parent = id_to_descriptor[parent_id];
247 base::ListValue* guests = NULL; 249 base::ListValue* guests = NULL;
248 if (!parent->GetList(kGuestList, &guests)) { 250 if (!parent->GetList(kGuestList, &guests)) {
249 guests = new base::ListValue(); 251 guests = new base::ListValue();
250 parent->Set(kGuestList, guests); 252 parent->Set(kGuestList, guests);
251 } 253 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 target_data->SetString(kFaviconUrlField, target.GetFaviconURL().spec()); 470 target_data->SetString(kFaviconUrlField, target.GetFaviconURL().spec());
469 target_data->SetString(kDescriptionField, target.GetDescription()); 471 target_data->SetString(kDescriptionField, target.GetDescription());
470 return target_data; 472 return target_data;
471 } 473 }
472 474
473 void DevToolsTargetsUIHandler::SendSerializedTargets( 475 void DevToolsTargetsUIHandler::SendSerializedTargets(
474 const base::ListValue& list) { 476 const base::ListValue& list) {
475 callback_.Run(source_id_, list); 477 callback_.Run(source_id_, list);
476 } 478 }
477 479
480 void DevToolsTargetsUIHandler::ForceUpdate() {
481 }
482
478 // PortForwardingStatusSerializer --------------------------------------------- 483 // PortForwardingStatusSerializer ---------------------------------------------
479 484
480 PortForwardingStatusSerializer::PortForwardingStatusSerializer( 485 PortForwardingStatusSerializer::PortForwardingStatusSerializer(
481 const Callback& callback, Profile* profile) 486 const Callback& callback, Profile* profile)
482 : callback_(callback), 487 : callback_(callback),
483 profile_(profile) { 488 profile_(profile) {
484 DevToolsAndroidBridge* android_bridge = 489 DevToolsAndroidBridge* android_bridge =
485 DevToolsAndroidBridge::Factory::GetForProfile(profile_); 490 DevToolsAndroidBridge::Factory::GetForProfile(profile_);
486 if (android_bridge) 491 if (android_bridge)
487 android_bridge->AddPortForwardingListener(this); 492 android_bridge->AddPortForwardingListener(this);
(...skipping 19 matching lines...) Expand all
507 base::StringPrintf("%d", it->first), it->second); 512 base::StringPrintf("%d", it->first), it->second);
508 } 513 }
509 514
510 std::string device_id = base::StringPrintf( 515 std::string device_id = base::StringPrintf(
511 kAdbDeviceIdFormat, 516 kAdbDeviceIdFormat,
512 sit->first.c_str()); 517 sit->first.c_str());
513 result.Set(device_id, device_status_dict); 518 result.Set(device_id, device_status_dict);
514 } 519 }
515 callback_.Run(result); 520 callback_.Run(result);
516 } 521 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_targets_ui.h ('k') | chrome/browser/resources/inspect/inspect.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698