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/test_license_server.h" | 5 #include "chrome/browser/media/test_license_server.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
11 #include "chrome/browser/media/test_license_server_config.h" | 11 #include "chrome/browser/media/test_license_server_config.h" |
12 | 12 |
13 | 13 |
14 TestLicenseServer::TestLicenseServer( | 14 TestLicenseServer::TestLicenseServer( |
15 scoped_ptr<TestLicenseServerConfig> server_config) | 15 scoped_ptr<TestLicenseServerConfig> server_config) |
16 : server_config_(server_config.Pass()), | 16 : server_config_(server_config.Pass()) { |
17 license_server_process_(base::kNullProcessHandle) { | |
18 } | 17 } |
19 | 18 |
20 TestLicenseServer::~TestLicenseServer() { | 19 TestLicenseServer::~TestLicenseServer() { |
21 Stop(); | 20 Stop(); |
22 } | 21 } |
23 | 22 |
24 bool TestLicenseServer::Start() { | 23 bool TestLicenseServer::Start() { |
25 if (license_server_process_ != base::kNullProcessHandle) | 24 if (license_server_process_.IsValid()) |
26 return true; | 25 return true; |
27 | 26 |
28 if (!server_config_->IsPlatformSupported()) { | 27 if (!server_config_->IsPlatformSupported()) { |
29 DVLOG(0) << "License server is not supported on current platform."; | 28 DVLOG(0) << "License server is not supported on current platform."; |
30 return false; | 29 return false; |
31 } | 30 } |
32 | 31 |
33 CommandLine command_line(CommandLine::NO_PROGRAM); | 32 CommandLine command_line(CommandLine::NO_PROGRAM); |
34 if (!server_config_->GetServerCommandLine(&command_line)) { | 33 if (!server_config_->GetServerCommandLine(&command_line)) { |
35 DVLOG(0) << "Could not get server command line to launch."; | 34 DVLOG(0) << "Could not get server command line to launch."; |
36 return false; | 35 return false; |
37 } | 36 } |
38 | 37 |
39 DVLOG(0) << "Starting test license server " << | 38 DVLOG(0) << "Starting test license server " << |
40 command_line.GetCommandLineString(); | 39 command_line.GetCommandLineString(); |
41 if (!base::LaunchProcess(command_line, base::LaunchOptions(), | 40 license_server_process_ = |
42 &license_server_process_)) { | 41 base::LaunchProcess(command_line, base::LaunchOptions()); |
| 42 if (!license_server_process_.IsValid()) { |
43 DVLOG(0) << "Failed to start test license server!"; | 43 DVLOG(0) << "Failed to start test license server!"; |
44 return false; | 44 return false; |
45 } | 45 } |
46 DCHECK_NE(license_server_process_, base::kNullProcessHandle); | |
47 return true; | 46 return true; |
48 } | 47 } |
49 | 48 |
50 bool TestLicenseServer::Stop() { | 49 bool TestLicenseServer::Stop() { |
51 if (license_server_process_ == base::kNullProcessHandle) | 50 if (!license_server_process_.IsValid()) |
52 return true; | 51 return true; |
53 DVLOG(0) << "Killing license server."; | 52 DVLOG(0) << "Killing license server."; |
54 bool kill_succeeded = base::KillProcess(license_server_process_, 1, true); | 53 bool kill_succeeded = |
| 54 base::KillProcess(license_server_process_.Handle(), 1, true); |
55 | 55 |
56 if (kill_succeeded) { | 56 if (kill_succeeded) { |
57 base::CloseProcessHandle(license_server_process_); | 57 license_server_process_.Close(); |
58 license_server_process_ = base::kNullProcessHandle; | |
59 } else { | 58 } else { |
60 DVLOG(1) << "Kill failed?!"; | 59 DVLOG(1) << "Kill failed?!"; |
61 } | 60 } |
62 return kill_succeeded; | 61 return kill_succeeded; |
63 } | 62 } |
64 | 63 |
65 std::string TestLicenseServer::GetServerURL() { | 64 std::string TestLicenseServer::GetServerURL() { |
66 return server_config_->GetServerURL(); | 65 return server_config_->GetServerURL(); |
67 } | 66 } |
OLD | NEW |