1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_
10 #include "base/prefs/pref_change_registrar.h"
11 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
12 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
13 #include "components/keyed_service/core/keyed_service.h"
18 class PortForwardingController
19 : private KeyedService,
20 private DevToolsAndroidBridge::DeviceListListener {
22 explicit PortForwardingController(Profile* profile);
24 virtual ~PortForwardingController();
26 // KeyedService implementation.
27 virtual void Shutdown() OVERRIDE;
29 class Factory : public BrowserContextKeyedServiceFactory {
31 // Returns singleton instance of Factory.
32 static Factory* GetInstance();
34 // Returns PortForwardingController associated with |profile|.
35 static PortForwardingController* GetForProfile(Profile* profile);
38 friend struct DefaultSingletonTraits<Factory>;
43 // BrowserContextKeyedServiceFactory overrides:
44 virtual KeyedService* BuildServiceInstanceFor(
45 content::BrowserContext* context) const OVERRIDE;
46 DISALLOW_COPY_AND_ASSIGN(Factory);
49 typedef int PortStatus;
50 typedef std::map<int, PortStatus> PortStatusMap;
51 typedef std::map<std::string, PortStatusMap> DevicesStatus;
55 typedef PortForwardingController::PortStatusMap PortStatusMap;
56 typedef PortForwardingController::DevicesStatus DevicesStatus;
58 virtual void PortStatusChanged(const DevicesStatus&) = 0;
60 virtual ~Listener() {}
63 void AddListener(Listener* listener);
64 void RemoveListener(Listener* listener);
68 typedef std::map<std::string, Connection*> Registry;
70 // DevToolsAndroidBridge::Listener implementation.
71 virtual void DeviceListChanged(
72 const DevToolsAndroidBridge::RemoteDevices& devices) OVERRIDE;
76 void StartListening();
79 void UpdateConnections();
80 void ShutdownConnections();
82 void NotifyListeners(const DevicesStatus& status) const;
85 PrefService* pref_service_;
86 PrefChangeRegistrar pref_change_registrar_;
89 typedef std::vector<Listener*> Listeners;
93 typedef std::map<int, std::string> ForwardingMap;
94 ForwardingMap forwarding_map_;
96 DISALLOW_COPY_AND_ASSIGN(PortForwardingController);
99 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_