| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media/wv_test_license_server_config.h" | 5 #include "chrome/browser/media/wv_test_license_server_config.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "net/base/ip_address.h" | 14 #include "net/base/ip_address.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/log/net_log_source.h" |
| 16 #include "net/socket/tcp_server_socket.h" | 17 #include "net/socket/tcp_server_socket.h" |
| 17 #include "net/test/python_utils.h" | 18 #include "net/test/python_utils.h" |
| 18 | 19 |
| 19 const uint16_t kMinPort = 17000; | 20 const uint16_t kMinPort = 17000; |
| 20 const uint16_t kPortRangeSize = 1000; | 21 const uint16_t kPortRangeSize = 1000; |
| 21 | 22 |
| 22 // Widevine license server configuration files. | 23 // Widevine license server configuration files. |
| 23 const base::FilePath::CharType kKeysFileName[] = | 24 const base::FilePath::CharType kKeysFileName[] = |
| 24 FILE_PATH_LITERAL("keys.dat"); | 25 FILE_PATH_LITERAL("keys.dat"); |
| 25 const base::FilePath::CharType kPoliciesFileName[] = | 26 const base::FilePath::CharType kPoliciesFileName[] = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return true; | 101 return true; |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool WVTestLicenseServerConfig::SelectServerPort() { | 104 bool WVTestLicenseServerConfig::SelectServerPort() { |
| 104 // Try all ports within the range of kMinPort to (kMinPort + kPortRangeSize) | 105 // Try all ports within the range of kMinPort to (kMinPort + kPortRangeSize) |
| 105 // Instead of starting from kMinPort, use a random port within that range. | 106 // Instead of starting from kMinPort, use a random port within that range. |
| 106 uint16_t start_seed = base::RandInt(0, kPortRangeSize); | 107 uint16_t start_seed = base::RandInt(0, kPortRangeSize); |
| 107 uint16_t try_port = 0; | 108 uint16_t try_port = 0; |
| 108 for (uint16_t i = 0; i < kPortRangeSize; ++i) { | 109 for (uint16_t i = 0; i < kPortRangeSize; ++i) { |
| 109 try_port = kMinPort + (start_seed + i) % kPortRangeSize; | 110 try_port = kMinPort + (start_seed + i) % kPortRangeSize; |
| 110 net::NetLog::Source source; | 111 net::NetLogSource source; |
| 111 net::TCPServerSocket sock(NULL, source); | 112 net::TCPServerSocket sock(NULL, source); |
| 112 if (sock.Listen(net::IPEndPoint(net::IPAddress::IPv4Localhost(), try_port), | 113 if (sock.Listen(net::IPEndPoint(net::IPAddress::IPv4Localhost(), try_port), |
| 113 1) == net::OK) { | 114 1) == net::OK) { |
| 114 port_ = try_port; | 115 port_ = try_port; |
| 115 return true; | 116 return true; |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 DVLOG(0) << "Could not find an open port in the range of " << kMinPort << | 119 DVLOG(0) << "Could not find an open port in the range of " << kMinPort << |
| 119 " to " << kMinPort + kPortRangeSize; | 120 " to " << kMinPort + kPortRangeSize; |
| 120 return false; | 121 return false; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 147 | 148 |
| 148 void WVTestLicenseServerConfig::GetLicenseServerRootPath( | 149 void WVTestLicenseServerConfig::GetLicenseServerRootPath( |
| 149 base::FilePath* path) { | 150 base::FilePath* path) { |
| 150 base::FilePath source_root; | 151 base::FilePath source_root; |
| 151 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); | 152 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); |
| 152 *path = source_root.Append(FILE_PATH_LITERAL("third_party")) | 153 *path = source_root.Append(FILE_PATH_LITERAL("third_party")) |
| 153 .Append(FILE_PATH_LITERAL("widevine")) | 154 .Append(FILE_PATH_LITERAL("widevine")) |
| 154 .Append(FILE_PATH_LITERAL("test")) | 155 .Append(FILE_PATH_LITERAL("test")) |
| 155 .Append(FILE_PATH_LITERAL("license_server")); | 156 .Append(FILE_PATH_LITERAL("license_server")); |
| 156 } | 157 } |
| OLD | NEW |