| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ |
| 6 #define EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 friend class AppFirewallHoleManager; | 38 friend class AppFirewallHoleManager; |
| 39 | 39 |
| 40 AppFirewallHole(AppFirewallHoleManager* manager, | 40 AppFirewallHole(AppFirewallHoleManager* manager, |
| 41 PortType type, | 41 PortType type, |
| 42 uint16_t port, | 42 uint16_t port, |
| 43 const std::string& extension_id); | 43 const std::string& extension_id); |
| 44 | 44 |
| 45 void SetVisible(bool app_visible); | 45 void SetVisible(bool app_visible); |
| 46 void OnFirewallHoleOpened(scoped_ptr<chromeos::FirewallHole> firewall_hole); | 46 void OnFirewallHoleOpened( |
| 47 std::unique_ptr<chromeos::FirewallHole> firewall_hole); |
| 47 | 48 |
| 48 PortType type_; | 49 PortType type_; |
| 49 uint16_t port_; | 50 uint16_t port_; |
| 50 std::string extension_id_; | 51 std::string extension_id_; |
| 51 bool app_visible_ = false; | 52 bool app_visible_ = false; |
| 52 | 53 |
| 53 // This object is destroyed when the AppFirewallHoleManager that owns it is | 54 // This object is destroyed when the AppFirewallHoleManager that owns it is |
| 54 // destroyed and so a raw pointer is okay here. | 55 // destroyed and so a raw pointer is okay here. |
| 55 AppFirewallHoleManager* manager_; | 56 AppFirewallHoleManager* manager_; |
| 56 | 57 |
| 57 // This will hold the FirewallHole object if one is opened. | 58 // This will hold the FirewallHole object if one is opened. |
| 58 scoped_ptr<chromeos::FirewallHole> firewall_hole_; | 59 std::unique_ptr<chromeos::FirewallHole> firewall_hole_; |
| 59 | 60 |
| 60 base::WeakPtrFactory<AppFirewallHole> weak_factory_; | 61 base::WeakPtrFactory<AppFirewallHole> weak_factory_; |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 // Tracks ports in the system firewall opened by an application so that they | 64 // Tracks ports in the system firewall opened by an application so that they |
| 64 // may be automatically opened and closed only when the application has a | 65 // may be automatically opened and closed only when the application has a |
| 65 // visible window. | 66 // visible window. |
| 66 class AppFirewallHoleManager : public KeyedService, | 67 class AppFirewallHoleManager : public KeyedService, |
| 67 public AppWindowRegistry::Observer { | 68 public AppWindowRegistry::Observer { |
| 68 public: | 69 public: |
| 69 explicit AppFirewallHoleManager(content::BrowserContext* context); | 70 explicit AppFirewallHoleManager(content::BrowserContext* context); |
| 70 ~AppFirewallHoleManager() override; | 71 ~AppFirewallHoleManager() override; |
| 71 | 72 |
| 72 // Returns the instance for a given browser context, or NULL if none. | 73 // Returns the instance for a given browser context, or NULL if none. |
| 73 static AppFirewallHoleManager* Get(content::BrowserContext* context); | 74 static AppFirewallHoleManager* Get(content::BrowserContext* context); |
| 74 | 75 |
| 75 // Takes ownership of the AppFirewallHole and will open a port on the system | 76 // Takes ownership of the AppFirewallHole and will open a port on the system |
| 76 // firewall if the associated application is currently visible. | 77 // firewall if the associated application is currently visible. |
| 77 scoped_ptr<AppFirewallHole> Open(AppFirewallHole::PortType type, | 78 std::unique_ptr<AppFirewallHole> Open(AppFirewallHole::PortType type, |
| 78 uint16_t port, | 79 uint16_t port, |
| 79 const std::string& extension_id); | 80 const std::string& extension_id); |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 friend class AppFirewallHole; | 83 friend class AppFirewallHole; |
| 83 | 84 |
| 84 void Close(AppFirewallHole* hole); | 85 void Close(AppFirewallHole* hole); |
| 85 | 86 |
| 86 // AppWindowRegistry::Observer | 87 // AppWindowRegistry::Observer |
| 87 void OnAppWindowRemoved(AppWindow* app_window) override; | 88 void OnAppWindowRemoved(AppWindow* app_window) override; |
| 88 void OnAppWindowHidden(AppWindow* app_window) override; | 89 void OnAppWindowHidden(AppWindow* app_window) override; |
| 89 void OnAppWindowShown(AppWindow* app_window, bool was_hidden) override; | 90 void OnAppWindowShown(AppWindow* app_window, bool was_hidden) override; |
| 90 | 91 |
| 91 content::BrowserContext* context_; | 92 content::BrowserContext* context_; |
| 92 ScopedObserver<AppWindowRegistry, AppWindowRegistry::Observer> observer_; | 93 ScopedObserver<AppWindowRegistry, AppWindowRegistry::Observer> observer_; |
| 93 std::multimap<std::string, AppFirewallHole*> tracked_holes_; | 94 std::multimap<std::string, AppFirewallHole*> tracked_holes_; |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 } // namespace extensions | 97 } // namespace extensions |
| 97 | 98 |
| 98 #endif // EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ | 99 #endif // EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ |
| OLD | NEW |