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/location.h" | 7 #include "base/location.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> > RemoteBrowsers; | 286 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> > RemoteBrowsers; |
287 RemoteBrowsers remote_browsers_; | 287 RemoteBrowsers remote_browsers_; |
288 }; | 288 }; |
289 | 289 |
290 AdbTargetsUIHandler::AdbTargetsUIHandler(const Callback& callback, | 290 AdbTargetsUIHandler::AdbTargetsUIHandler(const Callback& callback, |
291 Profile* profile) | 291 Profile* profile) |
292 : DevToolsTargetsUIHandler(kTargetSourceRemote, callback), | 292 : DevToolsTargetsUIHandler(kTargetSourceRemote, callback), |
293 profile_(profile), | 293 profile_(profile), |
294 android_bridge_( | 294 android_bridge_( |
295 DevToolsAndroidBridge::Factory::GetForProfile(profile_)) { | 295 DevToolsAndroidBridge::Factory::GetForProfile(profile_)) { |
296 DCHECK(android_bridge_); | 296 if (android_bridge_) |
297 android_bridge_->AddDeviceListListener(this); | 297 android_bridge_->AddDeviceListListener(this); |
298 } | 298 } |
299 | 299 |
300 AdbTargetsUIHandler::~AdbTargetsUIHandler() { | 300 AdbTargetsUIHandler::~AdbTargetsUIHandler() { |
301 android_bridge_->RemoveDeviceListListener(this); | 301 if (android_bridge_) |
| 302 android_bridge_->RemoveDeviceListListener(this); |
302 } | 303 } |
303 | 304 |
304 void AdbTargetsUIHandler::Open(const std::string& browser_id, | 305 void AdbTargetsUIHandler::Open(const std::string& browser_id, |
305 const std::string& url) { | 306 const std::string& url) { |
306 RemoteBrowsers::iterator it = remote_browsers_.find(browser_id); | 307 RemoteBrowsers::iterator it = remote_browsers_.find(browser_id); |
307 if (it != remote_browsers_.end()) | 308 if (it != remote_browsers_.end() && android_bridge_) |
308 android_bridge_->OpenRemotePage(it->second, url); | 309 android_bridge_->OpenRemotePage(it->second, url); |
309 } | 310 } |
310 | 311 |
311 scoped_refptr<content::DevToolsAgentHost> | 312 scoped_refptr<content::DevToolsAgentHost> |
312 AdbTargetsUIHandler::GetBrowserAgentHost( | 313 AdbTargetsUIHandler::GetBrowserAgentHost( |
313 const std::string& browser_id) { | 314 const std::string& browser_id) { |
314 RemoteBrowsers::iterator it = remote_browsers_.find(browser_id); | 315 RemoteBrowsers::iterator it = remote_browsers_.find(browser_id); |
315 if (it == remote_browsers_.end()) | 316 if (it == remote_browsers_.end() || !android_bridge_) |
316 return NULL; | 317 return nullptr; |
317 | 318 |
318 return android_bridge_->GetBrowserAgentHost(it->second); | 319 return android_bridge_->GetBrowserAgentHost(it->second); |
319 } | 320 } |
320 | 321 |
321 void AdbTargetsUIHandler::DeviceListChanged( | 322 void AdbTargetsUIHandler::DeviceListChanged( |
322 const DevToolsAndroidBridge::RemoteDevices& devices) { | 323 const DevToolsAndroidBridge::RemoteDevices& devices) { |
323 remote_browsers_.clear(); | 324 remote_browsers_.clear(); |
324 STLDeleteValues(&targets_); | 325 STLDeleteValues(&targets_); |
| 326 if (!android_bridge_) |
| 327 return; |
325 | 328 |
326 base::ListValue device_list; | 329 base::ListValue device_list; |
327 for (DevToolsAndroidBridge::RemoteDevices::const_iterator dit = | 330 for (DevToolsAndroidBridge::RemoteDevices::const_iterator dit = |
328 devices.begin(); dit != devices.end(); ++dit) { | 331 devices.begin(); dit != devices.end(); ++dit) { |
329 DevToolsAndroidBridge::RemoteDevice* device = dit->get(); | 332 DevToolsAndroidBridge::RemoteDevice* device = dit->get(); |
330 base::DictionaryValue* device_data = new base::DictionaryValue(); | 333 base::DictionaryValue* device_data = new base::DictionaryValue(); |
331 device_data->SetString(kAdbModelField, device->model()); | 334 device_data->SetString(kAdbModelField, device->model()); |
332 device_data->SetString(kAdbSerialField, device->serial()); | 335 device_data->SetString(kAdbSerialField, device->serial()); |
333 device_data->SetBoolean(kAdbConnectedField, device->is_connected()); | 336 device_data->SetBoolean(kAdbConnectedField, device->is_connected()); |
334 std::string device_id = base::StringPrintf( | 337 std::string device_id = base::StringPrintf( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 device_status_dict->SetString(kPortForwardingBrowserId, | 491 device_status_dict->SetString(kPortForwardingBrowserId, |
489 sit->first->GetId()); | 492 sit->first->GetId()); |
490 | 493 |
491 std::string device_id = base::StringPrintf( | 494 std::string device_id = base::StringPrintf( |
492 kAdbDeviceIdFormat, | 495 kAdbDeviceIdFormat, |
493 sit->first->serial().c_str()); | 496 sit->first->serial().c_str()); |
494 result.Set(device_id, device_status_dict); | 497 result.Set(device_id, device_status_dict); |
495 } | 498 } |
496 callback_.Run(result); | 499 callback_.Run(result); |
497 } | 500 } |
OLD | NEW |