| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "chrome/browser/safe_browsing/local_safebrowsing_test_server.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/path_service.h" | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/common/chrome_paths.h" | |
| 12 #include "net/test/python_utils.h" | |
| 13 #include "net/test/spawned_test_server/spawned_test_server.h" | |
| 14 | |
| 15 namespace safe_browsing { | |
| 16 | |
| 17 LocalSafeBrowsingTestServer::LocalSafeBrowsingTestServer( | |
| 18 const base::FilePath& data_file) | |
| 19 : net::LocalTestServer(net::SpawnedTestServer::TYPE_HTTP, | |
| 20 net::SpawnedTestServer::kLocalhost, | |
| 21 base::FilePath()), | |
| 22 data_file_(data_file) { | |
| 23 } | |
| 24 | |
| 25 LocalSafeBrowsingTestServer::~LocalSafeBrowsingTestServer() {} | |
| 26 | |
| 27 bool LocalSafeBrowsingTestServer::GetTestServerPath( | |
| 28 base::FilePath* testserver_path) const { | |
| 29 base::FilePath testserver_dir; | |
| 30 if (!PathService::Get(chrome::DIR_TEST_DATA, &testserver_dir)) { | |
| 31 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | |
| 32 return false; | |
| 33 } | |
| 34 | |
| 35 testserver_dir = testserver_dir | |
| 36 .Append(FILE_PATH_LITERAL("safe_browsing")); | |
| 37 | |
| 38 *testserver_path = testserver_dir.Append(FILE_PATH_LITERAL( | |
| 39 "safe_browsing_testserver.py")); | |
| 40 return true; | |
| 41 } | |
| 42 | |
| 43 bool LocalSafeBrowsingTestServer::SetPythonPath() const { | |
| 44 if (!net::LocalTestServer::SetPythonPath()) | |
| 45 return false; | |
| 46 | |
| 47 // Locate the Python code generated by the protocol buffers compiler. | |
| 48 base::FilePath pyproto_dir; | |
| 49 if (!GetPyProtoPath(&pyproto_dir)) { | |
| 50 LOG(ERROR) << "Cannot find pyproto dir for generated code."; | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 AppendToPythonPath(pyproto_dir.AppendASCII("google")); | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 bool LocalSafeBrowsingTestServer::GenerateAdditionalArguments( | |
| 59 base::DictionaryValue* arguments) const { | |
| 60 arguments->SetString("data-file", data_file_.value()); | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 } // namespace safe_browsing | |
| OLD | NEW |