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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void ForceUpdate() override; | 162 void ForceUpdate() override; |
163 | 163 |
164 private: | 164 private: |
165 // content::NotificationObserver overrides. | 165 // content::NotificationObserver overrides. |
166 void Observe(int type, | 166 void Observe(int type, |
167 const content::NotificationSource& source, | 167 const content::NotificationSource& source, |
168 const content::NotificationDetails& details) override; | 168 const content::NotificationDetails& details) override; |
169 | 169 |
170 void ScheduleUpdate(); | 170 void ScheduleUpdate(); |
171 void UpdateTargets(); | 171 void UpdateTargets(); |
172 void SendTargets(const DevToolsTargetImpl::List& targets); | 172 void SendTargets(const std::vector<DevToolsTargetImpl*>& targets); |
173 | 173 |
174 content::NotificationRegistrar notification_registrar_; | 174 content::NotificationRegistrar notification_registrar_; |
175 scoped_ptr<CancelableTimer> timer_; | 175 scoped_ptr<CancelableTimer> timer_; |
176 scoped_refptr<WorkerObserver> observer_; | 176 scoped_refptr<WorkerObserver> observer_; |
177 base::WeakPtrFactory<LocalTargetsUIHandler> weak_factory_; | 177 base::WeakPtrFactory<LocalTargetsUIHandler> weak_factory_; |
178 }; | 178 }; |
179 | 179 |
180 LocalTargetsUIHandler::LocalTargetsUIHandler( | 180 LocalTargetsUIHandler::LocalTargetsUIHandler( |
181 const Callback& callback) | 181 const Callback& callback) |
182 : DevToolsTargetsUIHandler(kTargetSourceLocal, callback), | 182 : DevToolsTargetsUIHandler(kTargetSourceLocal, callback), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 void LocalTargetsUIHandler::ScheduleUpdate() { | 215 void LocalTargetsUIHandler::ScheduleUpdate() { |
216 const int kUpdateDelay = 100; | 216 const int kUpdateDelay = 100; |
217 timer_.reset( | 217 timer_.reset( |
218 new CancelableTimer( | 218 new CancelableTimer( |
219 base::Bind(&LocalTargetsUIHandler::UpdateTargets, | 219 base::Bind(&LocalTargetsUIHandler::UpdateTargets, |
220 base::Unretained(this)), | 220 base::Unretained(this)), |
221 base::TimeDelta::FromMilliseconds(kUpdateDelay))); | 221 base::TimeDelta::FromMilliseconds(kUpdateDelay))); |
222 } | 222 } |
223 | 223 |
224 void LocalTargetsUIHandler::UpdateTargets() { | 224 void LocalTargetsUIHandler::UpdateTargets() { |
225 DevToolsTargetImpl::EnumerateAllTargets(base::Bind( | 225 SendTargets(DevToolsTargetImpl::EnumerateAll()); |
226 &LocalTargetsUIHandler::SendTargets, | |
227 weak_factory_.GetWeakPtr())); | |
228 } | 226 } |
229 | 227 |
230 void LocalTargetsUIHandler::SendTargets( | 228 void LocalTargetsUIHandler::SendTargets( |
231 const DevToolsTargetImpl::List& targets) { | 229 const std::vector<DevToolsTargetImpl*>& targets) { |
232 base::ListValue list_value; | 230 base::ListValue list_value; |
233 std::map<std::string, base::DictionaryValue*> id_to_descriptor; | 231 std::map<std::string, base::DictionaryValue*> id_to_descriptor; |
234 | 232 |
235 STLDeleteValues(&targets_); | 233 STLDeleteValues(&targets_); |
236 for (DevToolsTargetImpl::List::const_iterator it = targets.begin(); | 234 for (DevToolsTargetImpl* target : targets) { |
237 it != targets.end(); ++it) { | |
238 DevToolsTargetImpl* target = *it; | |
239 targets_[target->GetId()] = target; | 235 targets_[target->GetId()] = target; |
240 id_to_descriptor[target->GetId()] = Serialize(*target); | 236 id_to_descriptor[target->GetId()] = Serialize(*target); |
241 } | 237 } |
242 | 238 |
243 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { | 239 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { |
244 DevToolsTargetImpl* target = it->second; | 240 DevToolsTargetImpl* target = it->second; |
245 base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()]; | 241 base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()]; |
246 std::string parent_id = target->GetParentId(); | 242 std::string parent_id = target->GetParentId(); |
247 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { | 243 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { |
248 list_value.Append(descriptor); | 244 list_value.Append(descriptor); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 device_status_dict->SetString(kPortForwardingBrowserId, | 487 device_status_dict->SetString(kPortForwardingBrowserId, |
492 sit->first->GetId()); | 488 sit->first->GetId()); |
493 | 489 |
494 std::string device_id = base::StringPrintf( | 490 std::string device_id = base::StringPrintf( |
495 kAdbDeviceIdFormat, | 491 kAdbDeviceIdFormat, |
496 sit->first->serial().c_str()); | 492 sit->first->serial().c_str()); |
497 result.Set(device_id, device_status_dict); | 493 result.Set(device_id, device_status_dict); |
498 } | 494 } |
499 callback_.Run(result); | 495 callback_.Run(result); |
500 } | 496 } |
OLD | NEW |