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/port_forwarding_controller.h" | 5 #include "chrome/browser/devtools/port_forwarding_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 265 |
266 } // namespace | 266 } // namespace |
267 | 267 |
268 class PortForwardingController::Connection | 268 class PortForwardingController::Connection |
269 : public AdbWebSocket::Delegate, | 269 : public AdbWebSocket::Delegate, |
270 public base::RefCountedThreadSafe< | 270 public base::RefCountedThreadSafe< |
271 Connection, | 271 Connection, |
272 content::BrowserThread::DeleteOnUIThread> { | 272 content::BrowserThread::DeleteOnUIThread> { |
273 public: | 273 public: |
274 Connection(Registry* registry, | 274 Connection(Registry* registry, |
275 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 275 scoped_refptr<AndroidDevice> device, |
276 const std::string& socket, | 276 const std::string& socket, |
277 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 277 scoped_refptr<RefCountedAdbThread> adb_thread, |
278 PrefService* pref_service); | 278 PrefService* pref_service); |
279 | 279 |
280 const PortStatusMap& GetPortStatusMap(); | 280 const PortStatusMap& GetPortStatusMap(); |
281 | 281 |
282 void Shutdown(); | 282 void Shutdown(); |
283 | 283 |
284 private: | 284 private: |
285 friend struct content::BrowserThread::DeleteOnThread< | 285 friend struct content::BrowserThread::DeleteOnThread< |
286 content::BrowserThread::UI>; | 286 content::BrowserThread::UI>; |
287 friend class base::DeleteHelper<Connection>; | 287 friend class base::DeleteHelper<Connection>; |
(...skipping 22 matching lines...) Expand all Loading... |
310 void UpdatePortStatusMap(); | 310 void UpdatePortStatusMap(); |
311 void UpdatePortStatusMapOnUIThread(const PortStatusMap& status_map); | 311 void UpdatePortStatusMapOnUIThread(const PortStatusMap& status_map); |
312 | 312 |
313 // AdbWebSocket::Delegate implementation: | 313 // AdbWebSocket::Delegate implementation: |
314 virtual void OnSocketOpened() OVERRIDE; | 314 virtual void OnSocketOpened() OVERRIDE; |
315 virtual void OnFrameRead(const std::string& message) OVERRIDE; | 315 virtual void OnFrameRead(const std::string& message) OVERRIDE; |
316 virtual void OnSocketClosed(bool closed_by_device) OVERRIDE; | 316 virtual void OnSocketClosed(bool closed_by_device) OVERRIDE; |
317 virtual bool ProcessIncomingMessage(const std::string& message) OVERRIDE; | 317 virtual bool ProcessIncomingMessage(const std::string& message) OVERRIDE; |
318 | 318 |
319 PortForwardingController::Registry* registry_; | 319 PortForwardingController::Registry* registry_; |
320 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device_; | 320 scoped_refptr<AndroidDevice> device_; |
321 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread_; | 321 scoped_refptr<RefCountedAdbThread> adb_thread_; |
322 PrefChangeRegistrar pref_change_registrar_; | 322 PrefChangeRegistrar pref_change_registrar_; |
323 scoped_refptr<AdbWebSocket> web_socket_; | 323 scoped_refptr<AdbWebSocket> web_socket_; |
324 int command_id_; | 324 int command_id_; |
325 ForwardingMap forwarding_map_; | 325 ForwardingMap forwarding_map_; |
326 CommandCallbackMap pending_responses_; | 326 CommandCallbackMap pending_responses_; |
327 PortStatusMap port_status_; | 327 PortStatusMap port_status_; |
328 PortStatusMap port_status_on_ui_thread_; | 328 PortStatusMap port_status_on_ui_thread_; |
329 | 329 |
330 DISALLOW_COPY_AND_ASSIGN(Connection); | 330 DISALLOW_COPY_AND_ASSIGN(Connection); |
331 }; | 331 }; |
332 | 332 |
333 PortForwardingController::Connection::Connection( | 333 PortForwardingController::Connection::Connection( |
334 Registry* registry, | 334 Registry* registry, |
335 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 335 scoped_refptr<AndroidDevice> device, |
336 const std::string& socket, | 336 const std::string& socket, |
337 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 337 scoped_refptr<RefCountedAdbThread> adb_thread, |
338 PrefService* pref_service) | 338 PrefService* pref_service) |
339 : registry_(registry), | 339 : registry_(registry), |
340 device_(device), | 340 device_(device), |
341 adb_thread_(adb_thread), | 341 adb_thread_(adb_thread), |
342 command_id_(0) { | 342 command_id_(0) { |
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
344 pref_change_registrar_.Init(pref_service); | 344 pref_change_registrar_.Init(pref_service); |
345 (*registry_)[device_->serial()] = this; | 345 (*registry_)[device_->serial()] = this; |
346 web_socket_ = new AdbWebSocket( | 346 web_socket_ = new AdbWebSocket( |
347 device, socket, kDevToolsRemoteBrowserTarget, | 347 device, socket, kDevToolsRemoteBrowserTarget, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 | 572 |
573 SocketTunnel* tunnel = new SocketTunnel(location, | 573 SocketTunnel* tunnel = new SocketTunnel(location, |
574 base::Bind(&Connection::UpdateSocketCount, this, port)); | 574 base::Bind(&Connection::UpdateSocketCount, this, port)); |
575 | 575 |
576 device_->OpenSocket(connection_id.c_str(), | 576 device_->OpenSocket(connection_id.c_str(), |
577 base::Bind(&SocketTunnel::Start, base::Unretained(tunnel))); | 577 base::Bind(&SocketTunnel::Start, base::Unretained(tunnel))); |
578 return true; | 578 return true; |
579 } | 579 } |
580 | 580 |
581 PortForwardingController::PortForwardingController(PrefService* pref_service) | 581 PortForwardingController::PortForwardingController(PrefService* pref_service) |
582 : adb_thread_(DevToolsAdbBridge::RefCountedAdbThread::GetInstance()), | 582 : adb_thread_(RefCountedAdbThread::GetInstance()), |
583 pref_service_(pref_service) { | 583 pref_service_(pref_service) { |
584 } | 584 } |
585 | 585 |
586 PortForwardingController::~PortForwardingController() { | 586 PortForwardingController::~PortForwardingController() { |
587 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) | 587 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) |
588 it->second->Shutdown(); | 588 it->second->Shutdown(); |
589 } | 589 } |
590 | 590 |
591 PortForwardingController::DevicesStatus | 591 PortForwardingController::DevicesStatus |
592 PortForwardingController::UpdateDeviceList( | 592 PortForwardingController::UpdateDeviceList( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 BrowserContextDependencyManager::GetInstance()) {} | 631 BrowserContextDependencyManager::GetInstance()) {} |
632 | 632 |
633 PortForwardingController::Factory::~Factory() {} | 633 PortForwardingController::Factory::~Factory() {} |
634 | 634 |
635 BrowserContextKeyedService* | 635 BrowserContextKeyedService* |
636 PortForwardingController::Factory::BuildServiceInstanceFor( | 636 PortForwardingController::Factory::BuildServiceInstanceFor( |
637 content::BrowserContext* context) const { | 637 content::BrowserContext* context) const { |
638 Profile* profile = Profile::FromBrowserContext(context); | 638 Profile* profile = Profile::FromBrowserContext(context); |
639 return new PortForwardingController(profile->GetPrefs()); | 639 return new PortForwardingController(profile->GetPrefs()); |
640 } | 640 } |
OLD | NEW |