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

Side by Side Diff: chrome/browser/extensions/extension_web_socket_proxy_private_api.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed changes to rand_util_unittest Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h"
6
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "base/string_number_conversions.h"
10 #include "chrome/browser/internal_auth.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "content/common/notification_service.h"
13
14 #if defined(OS_CHROMEOS)
15 #include "chrome/browser/chromeos/web_socket_proxy_controller.h"
16 #endif
17
18 bool WebSocketProxyPrivateGetPassportForTCPFunction::RunImpl() {
19 bool delay_response = false;
20 result_.reset(Value::CreateStringValue(""));
21
22 #if defined(OS_CHROMEOS)
23 std::string hostname;
24 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &hostname));
25 int port = -1;
26 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &port));
27
28 if (chromeos::WebSocketProxyController::CheckCredentials(
29 extension_id(), hostname, port,
30 chromeos::WebSocketProxyController::PLAIN_TCP)) {
31 if (!chromeos::WebSocketProxyController::IsInitiated()) {
32 delay_response = true;
33 registrar_.Add(
34 this, NotificationType::WEB_SOCKET_PROXY_STARTED,
35 NotificationService::AllSources());
36 chromeos::WebSocketProxyController::Initiate();
37 }
38
39 std::map<std::string, std::string> map;
40 map["hostname"] = hostname;
41 map["port"] = base::IntToString(port);
42 map["extension_id"] = extension_id();
43 StringValue* passport = Value::CreateStringValue(
44 browser::InternalAuthGeneration::GeneratePassport(
45 "web_socket_proxy", map));
46 result_.reset(passport);
47 }
48 #endif // defined(OS_CHROMEOS)
49
50 // TODO(dilmah): get idea why notification is not observed and timer callback
51 // is not called and remove this line.
52 delay_response = false;
53
54 if (delay_response) {
55 timer_.Start(base::TimeDelta::FromSeconds(3),
56 this, &WebSocketProxyPrivateGetPassportForTCPFunction::Finalize);
57 } else {
58 Finalize();
59 }
60 return true;
61 }
62
63 void WebSocketProxyPrivateGetPassportForTCPFunction::Observe(
64 NotificationType type, const NotificationSource& source,
65 const NotificationDetails& details) {
66 #if defined(OS_CHROMEOS)
67 DCHECK(type.value == NotificationType::WEB_SOCKET_PROXY_STARTED);
68 #else
69 NOTREACHED();
70 #endif
71 timer_.Stop(); // Cancel timeout timer.
72 Finalize();
73 }
74
75 void WebSocketProxyPrivateGetPassportForTCPFunction::Finalize() {
76 SendResponse(true);
77 }
78
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698