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

Side by Side Diff: chrome/browser/chromeos/web_socket_proxy_controller.cc

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/web_socket_proxy_controller.h" 5 #include "chrome/browser/chromeos/web_socket_proxy_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include <netinet/in.h> 9 #include <netinet/in.h>
10 #include <sys/wait.h> 10 #include <sys/wait.h>
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/notification_observer.h" 26 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_registrar.h" 27 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/common/url_constants.h" 29 #include "content/public/common/url_constants.h"
30 #include "googleurl/src/gurl.h" 30 #include "googleurl/src/gurl.h"
31 #include "net/base/network_change_notifier.h" 31 #include "net/base/network_change_notifier.h"
32 32
33 namespace { 33 namespace {
34 34
35 class ProxyLifetime 35 class ProxyLifetime
36 : public net::NetworkChangeNotifier::ConnectionTypeObserver, 36 : public net::NetworkChangeNotifier::NetworkChangeObserver,
37 public content::NotificationObserver { 37 public content::NotificationObserver {
38 public: 38 public:
39 ProxyLifetime() 39 ProxyLifetime()
40 : delay_ms_(1000), 40 : delay_ms_(1000),
41 port_(-1), 41 port_(-1),
42 shutdown_requested_(false), 42 shutdown_requested_(false),
43 web_socket_proxy_thread_("Chrome_WebSocketproxyThread") { 43 web_socket_proxy_thread_("Chrome_WebSocketproxyThread") {
44 DLOG(INFO) << "WebSocketProxyController initiation"; 44 DLOG(INFO) << "WebSocketProxyController initiation";
45 base::Thread::Options options(MessageLoop::TYPE_IO, 0); 45 base::Thread::Options options(MessageLoop::TYPE_IO, 0);
46 web_socket_proxy_thread_.StartWithOptions(options); 46 web_socket_proxy_thread_.StartWithOptions(options);
47 web_socket_proxy_thread_.message_loop()->PostTask( 47 web_socket_proxy_thread_.message_loop()->PostTask(
48 FROM_HERE, 48 FROM_HERE,
49 base::Bind(&ProxyLifetime::ProxyCallback, base::Unretained(this))); 49 base::Bind(&ProxyLifetime::ProxyCallback, base::Unretained(this)));
50 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 50 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
51 registrar_.Add( 51 registrar_.Add(
52 this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED, 52 this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED,
53 content::NotificationService::AllSources()); 53 content::NotificationService::AllSources());
54 } 54 }
55 55
56 virtual ~ProxyLifetime() { 56 virtual ~ProxyLifetime() {
57 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 57 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
58 } 58 }
59 59
60 virtual void Observe(int type, const content::NotificationSource& source, 60 virtual void Observe(int type, const content::NotificationSource& source,
61 const content::NotificationDetails& details) OVERRIDE { 61 const content::NotificationDetails& details) OVERRIDE {
62 base::AutoLock alk(lock_); 62 base::AutoLock alk(lock_);
63 port_ = *content::Details<int>(details).ptr(); 63 port_ = *content::Details<int>(details).ptr();
64 } 64 }
65 65
66 int GetPort() { 66 int GetPort() {
67 base::AutoLock alk(lock_); 67 base::AutoLock alk(lock_);
68 return port_; 68 return port_;
69 } 69 }
70 70
71 private: 71 private:
72 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. 72 // net::NetworkChangeNotifier::NetworkChangeObserver implementation.
73 virtual void OnConnectionTypeChanged( 73 virtual void OnNetworkChanged(
74 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { 74 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
75 if (type != net::NetworkChangeNotifier::CONNECTION_NONE)
76 return;
szym 2013/01/20 06:52:08 This filters out changes online -> offline. Are yo
75 DCHECK(chromeos::WebSocketProxyController::IsInitiated()); 77 DCHECK(chromeos::WebSocketProxyController::IsInitiated());
76 base::AutoLock alk(lock_); 78 base::AutoLock alk(lock_);
77 if (server_) 79 if (server_)
78 server_->OnNetworkChange(); 80 server_->OnNetworkChange();
79 } 81 }
80 82
81 void ProxyCallback() { 83 void ProxyCallback() {
82 LOG(INFO) << "Attempt to run web socket proxy task"; 84 LOG(INFO) << "Attempt to run web socket proxy task";
83 chromeos::WebSocketProxy* server = new chromeos::WebSocketProxy(); 85 chromeos::WebSocketProxy* server = new chromeos::WebSocketProxy();
84 { 86 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 { 155 {
154 base::AutoLock alk(g_proxy_lifetime.Get().lock_); 156 base::AutoLock alk(g_proxy_lifetime.Get().lock_);
155 g_proxy_lifetime.Get().shutdown_requested_ = true; 157 g_proxy_lifetime.Get().shutdown_requested_ = true;
156 if (g_proxy_lifetime.Get().server_) 158 if (g_proxy_lifetime.Get().server_)
157 g_proxy_lifetime.Get().server_->Shutdown(); 159 g_proxy_lifetime.Get().server_->Shutdown();
158 } 160 }
159 g_proxy_lifetime.Get().web_socket_proxy_thread_.Stop(); 161 g_proxy_lifetime.Get().web_socket_proxy_thread_.Stop();
160 } 162 }
161 163
162 } // namespace chromeos 164 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698