Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_web_socket_proxy_private_api.h" | 5 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/internal_auth.h" | 10 #include "chrome/browser/internal_auth.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 15 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 16 | 16 |
| 17 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/chromeos/web_socket_proxy_controller.h" | 18 #include "chrome/browser/chromeos/web_socket_proxy_controller.h" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 WebSocketProxyPrivate::WebSocketProxyPrivate() | 21 WebSocketProxyPrivate::WebSocketProxyPrivate() |
| 22 : is_finalized_(false), listening_port_(-1) { | 22 : is_finalized_(false), |
| 23 listening_port_(-1) { | |
|
miket_OOO
2011/10/24 17:50:46
Is the indentation change needed?
Denis Lagno
2011/10/24 19:47:58
Done.
| |
| 24 #if defined(OS_CHROMEOS) | |
| 25 listening_port_ = chromeos::WebSocketProxyController::GetPort(); | |
| 26 #endif | |
| 23 } | 27 } |
| 24 | 28 |
| 25 WebSocketProxyPrivate::~WebSocketProxyPrivate() { | 29 WebSocketProxyPrivate::~WebSocketProxyPrivate() { |
| 26 } | 30 } |
| 27 | 31 |
| 28 void WebSocketProxyPrivate::Observe( | 32 void WebSocketProxyPrivate::Observe( |
| 29 int type, const content::NotificationSource& source, | 33 int type, const content::NotificationSource& source, |
| 30 const content::NotificationDetails& details) { | 34 const content::NotificationDetails& details) { |
| 31 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 32 DCHECK_EQ(chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED, type); | 36 DCHECK_EQ(chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED, type); |
| 33 #else | 37 #else |
| 34 NOTREACHED(); | 38 NOTREACHED(); |
| 35 #endif | 39 #endif |
| 36 timer_.Stop(); // Cancel timeout timer. | 40 timer_.Stop(); // Cancel timeout timer. |
| 37 Finalize(); | 41 Finalize(); |
| 38 } | 42 } |
| 39 | 43 |
| 40 void WebSocketProxyPrivate::Finalize() { | 44 void WebSocketProxyPrivate::Finalize() { |
| 41 if (is_finalized_) | 45 if (is_finalized_) |
| 42 return; | 46 return; |
| 43 is_finalized_ = true; | 47 is_finalized_ = true; |
| 44 SendResponse(true); | 48 SendResponse(listening_port_ > 0); |
| 45 Release(); | 49 Release(); |
| 46 } | 50 } |
| 47 | 51 |
| 48 WebSocketProxyPrivateGetPassportForTCPFunction:: | 52 WebSocketProxyPrivateGetPassportForTCPFunction:: |
| 49 WebSocketProxyPrivateGetPassportForTCPFunction() { | 53 WebSocketProxyPrivateGetPassportForTCPFunction() { |
| 50 // This obsolete API uses fixed port to listen websocket connections. | 54 // This obsolete API uses fixed port to listen websocket connections. |
| 51 listening_port_ = 10101; | 55 listening_port_ = 10101; |
| 52 } | 56 } |
| 53 | 57 |
| 54 void WebSocketProxyPrivateGetURLForTCPFunction::Observe( | 58 void WebSocketProxyPrivateGetURLForTCPFunction::Observe( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 std::string passport = browser::InternalAuthGeneration::GeneratePassport( | 152 std::string passport = browser::InternalAuthGeneration::GeneratePassport( |
| 149 "web_socket_proxy", map); | 153 "web_socket_proxy", map); |
| 150 query_ = std::string("hostname=") + | 154 query_ = std::string("hostname=") + |
| 151 net::EscapeQueryParamValue(hostname, false) + "&port=" + map["port"] + | 155 net::EscapeQueryParamValue(hostname, false) + "&port=" + map["port"] + |
| 152 "&tls=" + map["tls"] + "&passport=" + | 156 "&tls=" + map["tls"] + "&passport=" + |
| 153 net::EscapeQueryParamValue(passport, false); | 157 net::EscapeQueryParamValue(passport, false); |
| 154 } | 158 } |
| 155 #endif // defined(OS_CHROMEOS) | 159 #endif // defined(OS_CHROMEOS) |
| 156 | 160 |
| 157 if (delay_response) { | 161 if (delay_response) { |
| 158 const int kTimeout = 3; | 162 const int kTimeout = 12; |
|
miket_OOO
2011/10/24 17:50:46
Will you please add some documentation for this va
Denis Lagno
2011/10/24 19:47:58
Done.
| |
| 159 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeout), | 163 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeout), |
| 160 this, &WebSocketProxyPrivate::Finalize); | 164 this, &WebSocketProxyPrivate::Finalize); |
| 161 } else { | 165 } else { |
| 162 Finalize(); | 166 Finalize(); |
| 163 } | 167 } |
| 164 return true; | 168 return true; |
| 165 } | 169 } |
| 166 | 170 |
| OLD | NEW |