OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ | |
6 #define EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/scoped_observer.h" | |
11 #include "chromeos/network/firewall_hole.h" | |
12 #include "extensions/browser/app_window/app_window_registry.h" | |
13 | |
14 namespace content { | |
15 class BrowserContext; | |
16 } | |
17 | |
18 namespace extensions { | |
19 | |
20 class AppFirewallHoleManager; | |
21 | |
22 // Represents an open port in the system firewall that will be opened and closed | |
23 // automatically when the application has a visible window or not. The hole is | |
24 // closed on destruction. | |
25 class AppFirewallHole { | |
26 public: | |
27 typedef chromeos::FirewallHole::PortType PortType; | |
28 | |
29 ~AppFirewallHole(); | |
30 | |
31 PortType type() const { return type_; } | |
32 uint16_t port() const { return port_; } | |
33 const std::string& extension_id() const { return extension_id_; } | |
34 | |
35 private: | |
36 friend class AppFirewallHoleManager; | |
37 | |
38 AppFirewallHole(AppFirewallHoleManager* manager, | |
39 PortType type, | |
40 uint16_t port, | |
41 const std::string& extension_id); | |
42 | |
43 void SetVisible(bool app_visible); | |
44 void OnFirewallHoleOpened(scoped_ptr<chromeos::FirewallHole> firewall_hole); | |
45 | |
46 PortType type_; | |
47 uint16_t port_; | |
48 std::string extension_id_; | |
49 bool app_visible_ = false; | |
50 | |
51 AppFirewallHoleManager* manager_; | |
rpaquay
2015/03/23 18:29:07
nit: comment why it is ok to have raw ptr?
Reilly Grant (use Gerrit)
2015/03/23 20:09:31
Done.
Reilly Grant (use Gerrit)
2015/03/23 20:09:31
Done.
| |
52 | |
53 // This will hold the FirewallHole object if one is opened. | |
54 scoped_ptr<chromeos::FirewallHole> firewall_hole_; | |
55 | |
56 base::WeakPtrFactory<AppFirewallHole> weak_factory_; | |
57 }; | |
58 | |
59 // Tracks ports in the system firewall opened by an application so that they | |
60 // may be automatically opened and closed only when the application has a | |
61 // visible window. | |
62 class AppFirewallHoleManager : public KeyedService, | |
63 public AppWindowRegistry::Observer { | |
64 public: | |
65 explicit AppFirewallHoleManager(content::BrowserContext* context); | |
66 ~AppFirewallHoleManager() override; | |
67 | |
68 // Returns the instance for a given browser context, or NULL if none. | |
69 static AppFirewallHoleManager* Get(content::BrowserContext* context); | |
70 | |
71 // Takes ownership of the AppFirewallHole and will open a port on the system | |
72 // firewall if the associated application is currently visible. | |
73 AppFirewallHole* Open(AppFirewallHole::PortType type, | |
rpaquay
2015/03/23 18:29:07
Why don't we return a scoped_ptr<AppFirewallHole,
Reilly Grant (use Gerrit)
2015/03/23 20:09:31
I've switched it to a regular scoped_ptr. I want t
rpaquay
2015/03/23 21:04:57
Yes, yes, agreed, I didn't mean to imply you shoul
| |
74 uint16_t port, | |
75 const std::string& extension_id); | |
76 | |
77 private: | |
78 friend class AppFirewallHole; | |
79 | |
80 void Close(AppFirewallHole* hole); | |
81 | |
82 // AppWindowRegistry::Observer | |
83 void OnAppWindowRemoved(AppWindow* app_window) override; | |
84 void OnAppWindowHidden(AppWindow* app_window) override; | |
85 void OnAppWindowShown(AppWindow* app_window, bool was_hidden) override; | |
86 | |
87 content::BrowserContext* context_; | |
88 ScopedObserver<AppWindowRegistry, AppWindowRegistry::Observer> observer_; | |
89 std::multimap<std::string, AppFirewallHole*> tracked_holes_; | |
90 }; | |
91 | |
92 } // namespace extensions | |
93 | |
94 #endif // EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_ | |
OLD | NEW |