blob: fc4c83da8cef43522655c60fabffcc228cf79ab4 [file] [log] [blame]
Kristyn Hamasaki4de3d0a12019-08-12 19:31:421// Copyright 2019 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 "components/ui_devtools/agent_util.h"
6
7#include "base/command_line.h"
8#include "base/files/file_path.h"
9#include "base/files/file_util.h"
Hans Wennborg5bafbb92020-06-18 09:13:5710#include "base/logging.h"
Kristyn Hamasaki4de3d0a12019-08-12 19:31:4211#include "base/path_service.h"
12#include "base/run_loop.h"
13#include "base/task/post_task.h"
14#include "base/task/task_traits.h"
Gabriel Charettedd8d5985e2020-02-26 18:38:3515#include "base/task/thread_pool.h"
Kristyn Hamasaki4de3d0a12019-08-12 19:31:4216
17namespace ui_devtools {
18
19namespace {
20
21void OnSourceFile(base::OnceClosure quit_closure,
22 bool* return_value,
23 bool read_file_result) {
24 *return_value = read_file_result;
25 std::move(quit_closure).Run();
26}
27
28} // namespace
29
30const char kChromiumCodeSearchURL[] = "https://cs.chromium.org/";
31const char kChromiumCodeSearchSrcURL[] =
32 "https://cs.chromium.org/chromium/src/";
33
34bool GetSourceCode(std::string path, std::string* source_code) {
35 base::FilePath src_dir;
36 base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
37 src_dir = src_dir.AppendASCII(path);
38
39 base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
40
41 bool return_value;
Gabriel Charettedd8d5985e2020-02-26 18:38:3542 base::ThreadPool::PostTaskAndReplyWithResult(
Kristyn Hamasaki4de3d0a12019-08-12 19:31:4243 FROM_HERE,
Gabriel Charettedd8d5985e2020-02-26 18:38:3544 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
Kristyn Hamasaki4de3d0a12019-08-12 19:31:4245 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
46 base::BindOnce(&base::ReadFileToString, src_dir, source_code),
47 base::BindOnce(&OnSourceFile, run_loop.QuitClosure(), &return_value));
48
49 run_loop.Run();
50
51 if (!return_value)
52 DLOG(ERROR) << "Could not get source file of " << src_dir.value() << ".";
53
54 return return_value;
55}
56
57} // namespace ui_devtools