OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/devtools/devtools_file_system_indexer.h" | 5 #include "chrome/browser/devtools/devtools_file_system_indexer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/file_util_proxy.h" | 15 #include "base/files/file_util_proxy.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 | 23 |
23 using base::Bind; | 24 using base::Bind; |
24 using base::Callback; | 25 using base::Callback; |
25 using base::FileEnumerator; | 26 using base::FileEnumerator; |
26 using base::FilePath; | 27 using base::FilePath; |
27 using base::Time; | 28 using base::Time; |
28 using base::TimeDelta; | 29 using base::TimeDelta; |
29 using base::TimeTicks; | 30 using base::TimeTicks; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (!trigram_chars) { | 86 if (!trigram_chars) { |
86 trigram_chars = new TrigramChar[256]; | 87 trigram_chars = new TrigramChar[256]; |
87 for (size_t i = 0; i < 256; ++i) { | 88 for (size_t i = 0; i < 256; ++i) { |
88 if (i > 127) { | 89 if (i > 127) { |
89 trigram_chars[i] = kUndefinedTrigramChar; | 90 trigram_chars[i] = kUndefinedTrigramChar; |
90 continue; | 91 continue; |
91 } | 92 } |
92 char ch = static_cast<char>(i); | 93 char ch = static_cast<char>(i); |
93 if (ch == '\t') | 94 if (ch == '\t') |
94 ch = ' '; | 95 ch = ' '; |
95 if (ch >= 'A' && ch <= 'Z') | 96 if (base::IsAsciiUpper(ch)) |
96 ch = ch - 'A' + 'a'; | 97 ch = ch - 'A' + 'a'; |
97 | 98 |
98 bool is_binary_char = ch < 9 || (ch >= 14 && ch < 32) || ch == 127; | 99 bool is_binary_char = ch < 9 || (ch >= 14 && ch < 32) || ch == 127; |
99 if (is_binary_char) { | 100 if (is_binary_char) { |
100 trigram_chars[i] = kBinaryTrigramChar; | 101 trigram_chars[i] = kBinaryTrigramChar; |
101 continue; | 102 continue; |
102 } | 103 } |
103 | 104 |
104 if (ch < ' ') { | 105 if (ch < ' ') { |
105 trigram_chars[i] = kUndefinedTrigramChar; | 106 trigram_chars[i] = kUndefinedTrigramChar; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 vector<FilePath> file_paths = g_trigram_index.Get().Search(query); | 477 vector<FilePath> file_paths = g_trigram_index.Get().Search(query); |
477 vector<string> result; | 478 vector<string> result; |
478 FilePath path = FilePath::FromUTF8Unsafe(file_system_path); | 479 FilePath path = FilePath::FromUTF8Unsafe(file_system_path); |
479 vector<FilePath>::const_iterator it = file_paths.begin(); | 480 vector<FilePath>::const_iterator it = file_paths.begin(); |
480 for (; it != file_paths.end(); ++it) { | 481 for (; it != file_paths.end(); ++it) { |
481 if (path.IsParent(*it)) | 482 if (path.IsParent(*it)) |
482 result.push_back(it->AsUTF8Unsafe()); | 483 result.push_back(it->AsUTF8Unsafe()); |
483 } | 484 } |
484 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, Bind(callback, result)); | 485 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, Bind(callback, result)); |
485 } | 486 } |
OLD | NEW |