Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_file_system_indexer.h
blob5822e5829dde224f9898addcc3c0c5383cc02554
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/memory/ref_counted.h"
14 #include "base/platform_file.h"
16 class Profile;
18 namespace base {
19 class FilePath;
20 class FileEnumerator;
21 class Time;
24 namespace content {
25 class WebContents;
28 class DevToolsFileSystemIndexer
29 : public base::RefCountedThreadSafe<DevToolsFileSystemIndexer> {
30 public:
32 typedef base::Callback<void(int)> TotalWorkCallback;
33 typedef base::Callback<void(int)> WorkedCallback;
34 typedef base::Callback<void()> DoneCallback;
35 typedef base::Callback<void(const std::vector<std::string>&)> SearchCallback;
37 class FileSystemIndexingJob : public base::RefCounted<FileSystemIndexingJob> {
38 public:
39 void Stop();
41 private:
42 friend class base::RefCounted<FileSystemIndexingJob>;
43 friend class DevToolsFileSystemIndexer;
44 FileSystemIndexingJob(const base::FilePath& file_system_path,
45 const TotalWorkCallback& total_work_callback,
46 const WorkedCallback& worked_callback,
47 const DoneCallback& done_callback);
48 virtual ~FileSystemIndexingJob();
50 void Start();
51 void StopOnFileThread();
52 void CollectFilesToIndex();
53 void IndexFiles();
54 void StartFileIndexing(base::PlatformFileError error,
55 base::PassPlatformFile pass_file,
56 bool);
57 void ReadFromFile();
58 void OnRead(base::PlatformFileError error,
59 const char* data,
60 int bytes_read);
61 void FinishFileIndexing(bool success);
62 void CloseFile();
63 void CloseCallback(base::PlatformFileError error);
64 void ReportWorked();
66 base::FilePath file_system_path_;
67 TotalWorkCallback total_work_callback_;
68 WorkedCallback worked_callback_;
69 DoneCallback done_callback_;
70 scoped_ptr<base::FileEnumerator> file_enumerator_;
71 typedef std::map<base::FilePath, base::Time> FilePathTimesMap;
72 FilePathTimesMap file_path_times_;
73 FilePathTimesMap::const_iterator indexing_it_;
74 base::PlatformFile current_file_;
75 int64 current_file_offset_;
76 typedef int32 Trigram;
77 std::vector<Trigram> current_trigrams_;
78 // The index in this vector is the trigram id.
79 std::vector<bool> current_trigrams_set_;
80 base::TimeTicks last_worked_notification_time_;
81 int files_indexed_;
82 bool stopped_;
85 DevToolsFileSystemIndexer();
87 // Performs file system indexing for given |file_system_path| and sends
88 // progress callbacks.
89 scoped_refptr<FileSystemIndexingJob> IndexPath(
90 const std::string& file_system_path,
91 const TotalWorkCallback& total_work_callback,
92 const WorkedCallback& worked_callback,
93 const DoneCallback& done_callback);
95 // Performs trigram search for given |query| in |file_system_path|.
96 void SearchInPath(const std::string& file_system_path,
97 const std::string& query,
98 const SearchCallback& callback);
100 private:
101 friend class base::RefCountedThreadSafe<DevToolsFileSystemIndexer>;
103 virtual ~DevToolsFileSystemIndexer();
105 void SearchInPathOnFileThread(const std::string& file_system_path,
106 const std::string& query,
107 const SearchCallback& callback);
109 DISALLOW_COPY_AND_ASSIGN(DevToolsFileSystemIndexer);
112 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_SYSTEM_INDEXER_H_