Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(923)

Side by Side Diff: extensions/browser/api/socket/app_firewall_hole_manager.h

Issue 1022663003: Bind open firewall ports to visible application windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually fix the GN build. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/BUILD.gn ('k') | extensions/browser/api/socket/app_firewall_hole_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // This object is destroyed when the AppFirewallHoleManager that owns it is
52 // destroyed and so a raw pointer is okay here.
53 AppFirewallHoleManager* manager_;
54
55 // This will hold the FirewallHole object if one is opened.
56 scoped_ptr<chromeos::FirewallHole> firewall_hole_;
57
58 base::WeakPtrFactory<AppFirewallHole> weak_factory_;
59 };
60
61 // Tracks ports in the system firewall opened by an application so that they
62 // may be automatically opened and closed only when the application has a
63 // visible window.
64 class AppFirewallHoleManager : public KeyedService,
65 public AppWindowRegistry::Observer {
66 public:
67 explicit AppFirewallHoleManager(content::BrowserContext* context);
68 ~AppFirewallHoleManager() override;
69
70 // Returns the instance for a given browser context, or NULL if none.
71 static AppFirewallHoleManager* Get(content::BrowserContext* context);
72
73 // Takes ownership of the AppFirewallHole and will open a port on the system
74 // firewall if the associated application is currently visible.
75 scoped_ptr<AppFirewallHole> Open(AppFirewallHole::PortType type,
76 uint16_t port,
77 const std::string& extension_id);
78
79 private:
80 friend class AppFirewallHole;
81
82 void Close(AppFirewallHole* hole);
83
84 // AppWindowRegistry::Observer
85 void OnAppWindowRemoved(AppWindow* app_window) override;
86 void OnAppWindowHidden(AppWindow* app_window) override;
87 void OnAppWindowShown(AppWindow* app_window, bool was_hidden) override;
88
89 content::BrowserContext* context_;
90 ScopedObserver<AppWindowRegistry, AppWindowRegistry::Observer> observer_;
91 std::multimap<std::string, AppFirewallHole*> tracked_holes_;
92 };
93
94 } // namespace extensions
95
96 #endif // EXTENSIONS_BROWSER_API_SOCKET_APP_FIREWALL_HOLE_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/BUILD.gn ('k') | extensions/browser/api/socket/app_firewall_hole_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698