Home | History | Annotate | Download | only in devtools
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_DEVTOOLS_PORT_FORWARDING_CONTROLLER_H_
      6 #define CHROME_BROWSER_DEVTOOLS_PORT_FORWARDING_CONTROLLER_H_
      7 
      8 #include <map>
      9 
     10 #include "chrome/browser/devtools/devtools_adb_bridge.h"
     11 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
     12 #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
     13 
     14 class PrefService;
     15 
     16 class PortForwardingController : public BrowserContextKeyedService {
     17  public:
     18   explicit PortForwardingController(PrefService* pref_service);
     19 
     20   virtual ~PortForwardingController();
     21 
     22   class Factory : public BrowserContextKeyedServiceFactory {
     23    public:
     24     // Returns singleton instance of Factory.
     25     static Factory* GetInstance();
     26 
     27     // Returns PortForwardingController associated with |profile|.
     28     static PortForwardingController* GetForProfile(Profile* profile);
     29 
     30    private:
     31     friend struct DefaultSingletonTraits<Factory>;
     32 
     33     Factory();
     34     virtual ~Factory();
     35 
     36     // BrowserContextKeyedServiceFactory overrides:
     37     virtual BrowserContextKeyedService* BuildServiceInstanceFor(
     38         content::BrowserContext* context) const OVERRIDE;
     39     DISALLOW_COPY_AND_ASSIGN(Factory);
     40   };
     41 
     42   typedef int PortStatus;
     43   typedef std::map<int, PortStatus> PortStatusMap;
     44   typedef std::map<std::string, PortStatusMap> DevicesStatus;
     45 
     46   DevicesStatus UpdateDeviceList(
     47       const DevToolsAdbBridge::RemoteDevices& devices);
     48 
     49  private:
     50   class Connection;
     51   typedef std::map<std::string, Connection* > Registry;
     52 
     53   scoped_refptr<RefCountedAdbThread> adb_thread_;
     54   PrefService* pref_service_;
     55   Registry registry_;
     56 
     57   DISALLOW_COPY_AND_ASSIGN(PortForwardingController);
     58 };
     59 
     60 #endif  // CHROME_BROWSER_DEVTOOLS_PORT_FORWARDING_CONTROLLER_H_
     61