OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/test_files_request_filter.h" | 5 #include "chrome/browser/ui/webui/test_files_request_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/threading/thread_restrictions.h" |
12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 bool HandleTestFileRequestCallback( | 17 bool HandleTestFileRequestCallback( |
17 const std::string& path, | 18 const std::string& path, |
18 const content::WebUIDataSource::GotDataCallback& callback) { | 19 const content::WebUIDataSource::GotDataCallback& callback) { |
| 20 base::ThreadRestrictions::ScopedAllowIO allow_io; |
19 std::vector<std::string> url_substr = | 21 std::vector<std::string> url_substr = |
20 base::SplitString(path, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 22 base::SplitString(path, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
21 if (url_substr.size() != 2 || url_substr[0] != "test") | 23 if (url_substr.size() != 2 || url_substr[0] != "test") |
22 return false; | 24 return false; |
23 | 25 |
24 std::string contents; | 26 std::string contents; |
25 base::FilePath test_data_dir; | 27 base::FilePath test_data_dir; |
26 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 28 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
27 if (!base::ReadFileToString( | 29 if (!base::ReadFileToString( |
28 test_data_dir.AppendASCII("webui").AppendASCII(url_substr[1]), | 30 test_data_dir.AppendASCII("webui").AppendASCII(url_substr[1]), |
29 &contents)) | 31 &contents)) |
30 return false; | 32 return false; |
31 | 33 |
32 base::RefCountedString* ref_contents = new base::RefCountedString(); | 34 base::RefCountedString* ref_contents = new base::RefCountedString(); |
33 ref_contents->data() = contents; | 35 ref_contents->data() = contents; |
34 callback.Run(ref_contents); | 36 callback.Run(ref_contents); |
35 return true; | 37 return true; |
36 } | 38 } |
37 | 39 |
38 } // namespace | 40 } // namespace |
39 | 41 |
40 namespace test { | 42 namespace test { |
41 | 43 |
42 content::WebUIDataSource::HandleRequestCallback GetTestFilesRequestFilter() { | 44 content::WebUIDataSource::HandleRequestCallback GetTestFilesRequestFilter() { |
43 return base::Bind(&HandleTestFileRequestCallback); | 45 return base::Bind(&HandleTestFileRequestCallback); |
44 } | 46 } |
45 | 47 |
46 } // namespace test | 48 } // namespace test |
OLD | NEW |