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

Unified Diff: chrome/browser/chromeos/web_socket_proxy_controller.cc

Issue 8362027: websocket-to-TCP proxy: observe value of listening port in right place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reflected comments + rebased Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/web_socket_proxy_controller.cc
diff --git a/chrome/browser/chromeos/web_socket_proxy_controller.cc b/chrome/browser/chromeos/web_socket_proxy_controller.cc
index 5436afa0e0622ece2671d31bdaa20d6fa056dc64..e2bf804ce9eb1e87d93105fe2951eae57c0d294c 100644
--- a/chrome/browser/chromeos/web_socket_proxy_controller.cc
+++ b/chrome/browser/chromeos/web_socket_proxy_controller.cc
@@ -24,6 +24,7 @@
#include "content/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/notification_service.h"
#include "content/public/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "net/base/network_change_notifier.h"
@@ -99,18 +100,35 @@ class ProxyTask : public Task {
virtual void Run() OVERRIDE;
};
-class ProxyLifetime : public net::NetworkChangeNotifier::OnlineStateObserver {
+class ProxyLifetime
+ : public net::NetworkChangeNotifier::OnlineStateObserver,
+ public content::NotificationObserver {
public:
- ProxyLifetime() : delay_ms_(1000), shutdown_requested_(false) {
+ ProxyLifetime() : delay_ms_(1000), port_(-1), shutdown_requested_(false) {
+ LOG(INFO) << "WebSocketProxyController initiation";
miket_OOO 2011/10/24 19:53:00 Sorry if I missed this earlier. Can this be a DLOG
Denis Lagno 2011/10/25 11:19:37 Done.
BrowserThread::PostTask(
BrowserThread::WEB_SOCKET_PROXY, FROM_HERE, new ProxyTask());
net::NetworkChangeNotifier::AddOnlineStateObserver(this);
+ registrar_.Add(
+ this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED,
+ content::NotificationService::AllSources());
}
virtual ~ProxyLifetime() {
net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
}
+ virtual void Observe(int type, const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE {
+ base::AutoLock alk(lock_);
+ port_ = *content::Details<int>(details).ptr();
+ }
+
+ int GetPort() {
+ base::AutoLock alk(lock_);
+ return port_;
+ }
+
private:
// net::NetworkChangeNotifier::OnlineStateObserver overrides.
virtual void OnOnlineStateChanged(bool online) OVERRIDE {
@@ -121,7 +139,10 @@ class ProxyLifetime : public net::NetworkChangeNotifier::OnlineStateObserver {
}
// Delay between next attempt to run proxy.
- int delay_ms_;
+ int volatile delay_ms_;
+
+ // Proxy listens for incoming websocket connections on this port.
+ int volatile port_;
chromeos::WebSocketProxy* volatile server_;
volatile bool shutdown_requested_;
@@ -173,7 +194,6 @@ void FillWithExtensionsIdsWithPrivateAccess(std::vector<std::string>* ids) {
// static
void WebSocketProxyController::Initiate() {
- LOG(INFO) << "WebSocketProxyController initiation";
g_proxy_lifetime.Get();
}
@@ -183,6 +203,13 @@ bool WebSocketProxyController::IsInitiated() {
}
// static
+int WebSocketProxyController::GetPort() {
+ int port = g_proxy_lifetime.Get().GetPort();
+ DCHECK(IsInitiated());
+ return port;
+}
+
+// static
void WebSocketProxyController::Shutdown() {
if (IsInitiated()) {
LOG(INFO) << "WebSocketProxyController shutdown";

Powered by Google App Engine
This is Rietveld 408576698