Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / media / test_license_server.cc
blob4b6905dbfbf2843d1a4d86650eed1a09221b5a37
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() {
19 Stop();
22 bool TestLicenseServer::Start() {
23 if (license_server_process_.IsValid())
24 return true;
26 if (!server_config_->IsPlatformSupported()) {
27 DVLOG(0) << "License server is not supported on current platform.";
28 return false;
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.";
34 return false;
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!";
43 return false;
45 return true;
48 bool TestLicenseServer::Stop() {
49 if (!license_server_process_.IsValid())
50 return true;
51 DVLOG(0) << "Killing license server.";
52 bool kill_succeeded = license_server_process_.Terminate(1, true);
54 if (kill_succeeded) {
55 license_server_process_.Close();
56 } else {
57 DVLOG(1) << "Kill failed?!";
59 return kill_succeeded;
62 std::string TestLicenseServer::GetServerURL() {
63 return server_config_->GetServerURL();