blob: fc4c83da8cef43522655c60fabffcc228cf79ab4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/ui_devtools/agent_util.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
namespace ui_devtools {
namespace {
void OnSourceFile(base::OnceClosure quit_closure,
bool* return_value,
bool read_file_result) {
*return_value = read_file_result;
std::move(quit_closure).Run();
}
} // namespace
const char kChromiumCodeSearchURL[] = "https://cs.chromium.org/";
const char kChromiumCodeSearchSrcURL[] =
"https://cs.chromium.org/chromium/src/";
bool GetSourceCode(std::string path, std::string* source_code) {
base::FilePath src_dir;
base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
src_dir = src_dir.AppendASCII(path);
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
bool return_value;
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(&base::ReadFileToString, src_dir, source_code),
base::BindOnce(&OnSourceFile, run_loop.QuitClosure(), &return_value));
run_loop.Run();
if (!return_value)
DLOG(ERROR) << "Could not get source file of " << src_dir.value() << ".";
return return_value;
}
} // namespace ui_devtools
|