OLD | NEW |
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/devtools/browser_list_tabcontents_provider.h" | 5 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_iterator.h" | 12 #include "chrome/browser/ui/browser_iterator.h" |
13 #include "chrome/browser/ui/host_desktop.h" | 13 #include "chrome/browser/ui/host_desktop.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
16 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
17 #include "net/socket/tcp_listen_socket.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/socket/tcp_server_socket.h" |
18 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const int kMinTetheringPort = 9333; | 24 const int kMinTetheringPort = 9333; |
24 const int kMaxTetheringPort = 9444; | 25 const int kMaxTetheringPort = 9444; |
25 | 26 |
| 27 const int kBackLog = 10; |
| 28 |
26 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; | 29 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; |
27 | 30 |
28 } | 31 } |
29 | 32 |
30 // static | 33 // static |
31 void BrowserListTabContentsProvider::EnableTethering() { | 34 void BrowserListTabContentsProvider::EnableTethering() { |
32 g_tethering_enabled.Get() = true; | 35 g_tethering_enabled.Get() = true; |
33 } | 36 } |
34 | 37 |
35 BrowserListTabContentsProvider::BrowserListTabContentsProvider( | 38 BrowserListTabContentsProvider::BrowserListTabContentsProvider( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 base::FilePath BrowserListTabContentsProvider::GetDebugFrontendDir() { | 70 base::FilePath BrowserListTabContentsProvider::GetDebugFrontendDir() { |
68 #if defined(DEBUG_DEVTOOLS) | 71 #if defined(DEBUG_DEVTOOLS) |
69 base::FilePath inspector_dir; | 72 base::FilePath inspector_dir; |
70 PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir); | 73 PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir); |
71 return inspector_dir; | 74 return inspector_dir; |
72 #else | 75 #else |
73 return base::FilePath(); | 76 return base::FilePath(); |
74 #endif | 77 #endif |
75 } | 78 } |
76 | 79 |
77 scoped_ptr<net::StreamListenSocket> | 80 scoped_ptr<net::ServerSocket> |
78 BrowserListTabContentsProvider::CreateSocketForTethering( | 81 BrowserListTabContentsProvider::CreateSocketForTethering( |
79 net::StreamListenSocket::Delegate* delegate, | |
80 std::string* name) { | 82 std::string* name) { |
81 if (!g_tethering_enabled.Get()) | 83 if (!g_tethering_enabled.Get()) |
82 return scoped_ptr<net::StreamListenSocket>(); | 84 return scoped_ptr<net::ServerSocket>(); |
83 | 85 |
84 if (last_tethering_port_ == kMaxTetheringPort) | 86 if (last_tethering_port_ == kMaxTetheringPort) |
85 last_tethering_port_ = kMinTetheringPort; | 87 last_tethering_port_ = kMinTetheringPort; |
86 int port = ++last_tethering_port_; | 88 int port = ++last_tethering_port_; |
87 *name = base::IntToString(port); | 89 *name = base::IntToString(port); |
88 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate); | 90 scoped_ptr<net::TCPServerSocket> socket( |
| 91 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
| 92 if (socket->ListenWithAddressAndPort("127.0.0.1", port, kBackLog) != net::OK) |
| 93 return scoped_ptr<net::ServerSocket>(); |
| 94 |
| 95 return socket.Pass(); |
89 } | 96 } |
OLD | NEW |