| 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 #include "extensions/browser/api/socket/app_firewall_hole_manager.h" | 5 #include "extensions/browser/api/socket/app_firewall_hole_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 FirewallHole::Open(type_, port_, "" /* all interfaces */, | 90 FirewallHole::Open(type_, port_, "" /* all interfaces */, |
| 91 base::Bind(&AppFirewallHole::OnFirewallHoleOpened, | 91 base::Bind(&AppFirewallHole::OnFirewallHoleOpened, |
| 92 weak_factory_.GetWeakPtr())); | 92 weak_factory_.GetWeakPtr())); |
| 93 } | 93 } |
| 94 } else { | 94 } else { |
| 95 firewall_hole_.reset(nullptr); | 95 firewall_hole_.reset(nullptr); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void AppFirewallHole::OnFirewallHoleOpened( | 99 void AppFirewallHole::OnFirewallHoleOpened( |
| 100 scoped_ptr<FirewallHole> firewall_hole) { | 100 std::unique_ptr<FirewallHole> firewall_hole) { |
| 101 if (app_visible_) { | 101 if (app_visible_) { |
| 102 DCHECK(!firewall_hole_); | 102 DCHECK(!firewall_hole_); |
| 103 firewall_hole_ = std::move(firewall_hole); | 103 firewall_hole_ = std::move(firewall_hole); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 AppFirewallHoleManager::AppFirewallHoleManager(BrowserContext* context) | 107 AppFirewallHoleManager::AppFirewallHoleManager(BrowserContext* context) |
| 108 : context_(context), observer_(this) { | 108 : context_(context), observer_(this) { |
| 109 observer_.Add(AppWindowRegistry::Get(context)); | 109 observer_.Add(AppWindowRegistry::Get(context)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 AppFirewallHoleManager::~AppFirewallHoleManager() { | 112 AppFirewallHoleManager::~AppFirewallHoleManager() { |
| 113 STLDeleteValues(&tracked_holes_); | 113 STLDeleteValues(&tracked_holes_); |
| 114 } | 114 } |
| 115 | 115 |
| 116 AppFirewallHoleManager* AppFirewallHoleManager::Get(BrowserContext* context) { | 116 AppFirewallHoleManager* AppFirewallHoleManager::Get(BrowserContext* context) { |
| 117 return AppFirewallHoleManagerFactory::GetForBrowserContext(context, true); | 117 return AppFirewallHoleManagerFactory::GetForBrowserContext(context, true); |
| 118 } | 118 } |
| 119 | 119 |
| 120 scoped_ptr<AppFirewallHole> AppFirewallHoleManager::Open( | 120 std::unique_ptr<AppFirewallHole> AppFirewallHoleManager::Open( |
| 121 AppFirewallHole::PortType type, | 121 AppFirewallHole::PortType type, |
| 122 uint16_t port, | 122 uint16_t port, |
| 123 const std::string& extension_id) { | 123 const std::string& extension_id) { |
| 124 scoped_ptr<AppFirewallHole> hole( | 124 std::unique_ptr<AppFirewallHole> hole( |
| 125 new AppFirewallHole(this, type, port, extension_id)); | 125 new AppFirewallHole(this, type, port, extension_id)); |
| 126 tracked_holes_.insert(std::make_pair(extension_id, hole.get())); | 126 tracked_holes_.insert(std::make_pair(extension_id, hole.get())); |
| 127 if (HasVisibleAppWindows(context_, extension_id)) { | 127 if (HasVisibleAppWindows(context_, extension_id)) { |
| 128 hole->SetVisible(true); | 128 hole->SetVisible(true); |
| 129 } | 129 } |
| 130 return hole; | 130 return hole; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void AppFirewallHoleManager::Close(AppFirewallHole* hole) { | 133 void AppFirewallHoleManager::Close(AppFirewallHole* hole) { |
| 134 auto range = tracked_holes_.equal_range(hole->extension_id()); | 134 auto range = tracked_holes_.equal_range(hole->extension_id()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 157 | 157 |
| 158 void AppFirewallHoleManager::OnAppWindowShown(AppWindow* app_window, | 158 void AppFirewallHoleManager::OnAppWindowShown(AppWindow* app_window, |
| 159 bool was_hidden) { | 159 bool was_hidden) { |
| 160 const auto& range = tracked_holes_.equal_range(app_window->extension_id()); | 160 const auto& range = tracked_holes_.equal_range(app_window->extension_id()); |
| 161 for (auto iter = range.first; iter != range.second; ++iter) { | 161 for (auto iter = range.first; iter != range.second; ++iter) { |
| 162 iter->second->SetVisible(true); | 162 iter->second->SetVisible(true); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace extensions | 166 } // namespace extensions |
| OLD | NEW |