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

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

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed a typo Created 8 years, 7 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
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::OnlineStateObserver, 36 : public net::NetworkChangeNotifier::ConnectionTypeObserver,
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::AddOnlineStateObserver(this); 50 net::NetworkChangeNotifier::AddConnectionTypeObserver(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::RemoveOnlineStateObserver(this); 57 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(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::OnlineStateObserver implementation. 72 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation.
73 virtual void OnOnlineStateChanged(bool online) OVERRIDE { 73 virtual void OnConnectionTypeChanged(
74 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
74 DCHECK(chromeos::WebSocketProxyController::IsInitiated()); 75 DCHECK(chromeos::WebSocketProxyController::IsInitiated());
75 base::AutoLock alk(lock_); 76 base::AutoLock alk(lock_);
76 if (server_) 77 if (server_)
77 server_->OnNetworkChange(); 78 server_->OnNetworkChange();
78 } 79 }
79 80
80 void ProxyCallback() { 81 void ProxyCallback() {
81 LOG(INFO) << "Attempt to run web socket proxy task"; 82 LOG(INFO) << "Attempt to run web socket proxy task";
82 chromeos::WebSocketProxy* server = new chromeos::WebSocketProxy(); 83 chromeos::WebSocketProxy* server = new chromeos::WebSocketProxy();
83 { 84 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 { 153 {
153 base::AutoLock alk(g_proxy_lifetime.Get().lock_); 154 base::AutoLock alk(g_proxy_lifetime.Get().lock_);
154 g_proxy_lifetime.Get().shutdown_requested_ = true; 155 g_proxy_lifetime.Get().shutdown_requested_ = true;
155 if (g_proxy_lifetime.Get().server_) 156 if (g_proxy_lifetime.Get().server_)
156 g_proxy_lifetime.Get().server_->Shutdown(); 157 g_proxy_lifetime.Get().server_->Shutdown();
157 } 158 }
158 g_proxy_lifetime.Get().web_socket_proxy_thread_.Stop(); 159 g_proxy_lifetime.Get().web_socket_proxy_thread_.Stop();
159 } 160 }
160 161
161 } // namespace chromeos 162 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/offline/offline_load_page.cc ('k') | chrome/browser/sessions/session_restore.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698