NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_file_system_indexer.h
blob2f1322670c3f7ddba1eb25fb5328bc475d1076b6
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_SYSTEM_INDEXER_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_SYSTEM_INDEXER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/files/file.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/platform_file.h"
17 class Profile;
19 namespace base {
20 class FilePath;
21 class FileEnumerator;
22 class Time;
25 namespace content {
26 class WebContents;
29 class DevToolsFileSystemIndexer
30 : public base::RefCountedThreadSafe<DevToolsFileSystemIndexer> {
31 public:
33 typedef base::Callback<void(int)> TotalWorkCallback;
34 typedef base::Callback<void(int)> WorkedCallback;
35 typedef base::Callback<void()> DoneCallback;
36 typedef base::Callback<void(const std::vector<std::string>&)> SearchCallback;
38 class FileSystemIndexingJob : public base::RefCounted<FileSystemIndexingJob> {
39 public:
40 void Stop();
42 private:
43 friend class base::RefCounted<FileSystemIndexingJob>;
44 friend class DevToolsFileSystemIndexer;
45 FileSystemIndexingJob(const base::FilePath& file_system_path,
46 const TotalWorkCallback& total_work_callback,
47 const WorkedCallback& worked_callback,
48 const DoneCallback& done_callback);
49 virtual ~FileSystemIndexingJob();
51 void Start();
52 void StopOnFileThread();
53 void CollectFilesToIndex();
54 void IndexFiles();
55 void StartFileIndexing(base::File::Error error,
56 base::PassPlatformFile pass_file,
57 bool);
58 void ReadFromFile();
59 void OnRead(base::File::Error error,
60 const char* data,
61 int bytes_read);
62 void FinishFileIndexing(bool success);
63 void CloseFile();
64 void CloseCallback(base::File::Error error);
65 void ReportWorked();
67 base::FilePath file_system_path_;
68 TotalWorkCallback total_work_callback_;
69 WorkedCallback worked_callback_;
70 DoneCallback done_callback_;
71 scoped_ptr<base::FileEnumerator> file_enumerator_;
72 typedef std::map<base::FilePath, base::Time> FilePathTimesMap;
73 FilePathTimesMap file_path_times_;
74 FilePathTimesMap::const_iterator indexing_it_;
75 base::PlatformFile current_file_;
76 int64 current_file_offset_;
77 typedef int32 Trigram;
78 std::vector<Trigram> current_trigrams_;
79 // The index in this vector is the trigram id.
80 std::vector<bool> current_trigrams_set_;
81 base::TimeTicks last_worked_notification_time_;
82 int files_indexed_;
83 bool stopped_;
86 DevToolsFileSystemIndexer();
88 // Performs file system indexing for given |file_system_path| and sends
89 // progress callbacks.
90 scoped_refptr<FileSystemIndexingJob> IndexPath(
91 const std::string& file_system_path,
92 const TotalWorkCallback& total_work_callback,
93 const WorkedCallback& worked_callback,
94 const DoneCallback& done_callback);
96 // Performs trigram search for given |query| in |file_system_path|.
97 void SearchInPath(const std::string& file_system_path,
98 const std::string& query,
99 const SearchCallback& callback);
101 private:
102 friend class base::RefCountedThreadSafe<DevToolsFileSystemIndexer>;
104 virtual ~DevToolsFileSystemIndexer();
106 void SearchInPathOnFileThread(const std::string& file_system_path,
107 const std::string& query,
108 const SearchCallback& callback);
110 DISALLOW_COPY_AND_ASSIGN(DevToolsFileSystemIndexer);
113 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_SYSTEM_INDEXER_H_