replace OVERRIDE and FINAL with override and final in ash/
[chromium-blink-merge.git] / chrome / browser / media / test_license_server.cc
blob300274ebabb84c35592e3d9476bd74e7086a0a73
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/kill.h"
10 #include "base/process/launch.h"
11 #include "chrome/browser/media/test_license_server_config.h"
14 TestLicenseServer::TestLicenseServer(
15 scoped_ptr<TestLicenseServerConfig> server_config)
16 : server_config_(server_config.Pass()),
17 license_server_process_(base::kNullProcessHandle) {
20 TestLicenseServer::~TestLicenseServer() {
21 Stop();
24 bool TestLicenseServer::Start() {
25 if (license_server_process_ != base::kNullProcessHandle)
26 return true;
28 if (!server_config_->IsPlatformSupported()) {
29 VLOG(0) << "License server is not supported on current platform.";
30 return false;
33 CommandLine command_line(CommandLine::NO_PROGRAM);
34 if (!server_config_->GetServerCommandLine(&command_line)) {
35 VLOG(0) << "Could not get server command line to launch.";
36 return false;
39 VLOG(0) << "Starting test license server " <<
40 command_line.GetCommandLineString();
41 if (!base::LaunchProcess(command_line, base::LaunchOptions(),
42 &license_server_process_)) {
43 VLOG(0) << "Failed to start test license server!";
44 return false;
46 DCHECK_NE(license_server_process_, base::kNullProcessHandle);
47 return true;
50 bool TestLicenseServer::Stop() {
51 if (license_server_process_ == base::kNullProcessHandle)
52 return true;
53 VLOG(0) << "Killing license server.";
54 bool kill_succeeded = base::KillProcess(license_server_process_, 1, true);
56 if (kill_succeeded) {
57 base::CloseProcessHandle(license_server_process_);
58 license_server_process_ = base::kNullProcessHandle;
59 } else {
60 VLOG(1) << "Kill failed?!";
62 return kill_succeeded;
65 std::string TestLicenseServer::GetServerURL() {
66 return server_config_->GetServerURL();