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
3 // found in the LICENSE file.
5 #include "chrome/browser/media/test_license_server.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/process/launch.h"
10 #include "chrome/browser/media/test_license_server_config.h"
13 TestLicenseServer::TestLicenseServer(
14 scoped_ptr
<TestLicenseServerConfig
> server_config
)
15 : server_config_(server_config
.Pass()) {
18 TestLicenseServer::~TestLicenseServer() {
22 bool TestLicenseServer::Start() {
23 if (license_server_process_
.IsValid())
26 if (!server_config_
->IsPlatformSupported()) {
27 DVLOG(0) << "License server is not supported on current platform.";
31 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
32 if (!server_config_
->GetServerCommandLine(&command_line
)) {
33 DVLOG(0) << "Could not get server command line to launch.";
37 DVLOG(0) << "Starting test license server " <<
38 command_line
.GetCommandLineString();
39 license_server_process_
=
40 base::LaunchProcess(command_line
, base::LaunchOptions());
41 if (!license_server_process_
.IsValid()) {
42 DVLOG(0) << "Failed to start test license server!";
48 bool TestLicenseServer::Stop() {
49 if (!license_server_process_
.IsValid())
51 DVLOG(0) << "Killing license server.";
52 bool kill_succeeded
= license_server_process_
.Terminate(1, true);
55 license_server_process_
.Close();
57 DVLOG(1) << "Kill failed?!";
59 return kill_succeeded
;
62 std::string
TestLicenseServer::GetServerURL() {
63 return server_config_
->GetServerURL();