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_
12 #include "base/callback.h"
13 #include "base/files/file.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/platform_file.h"
29 class DevToolsFileSystemIndexer
30 : public base::RefCountedThreadSafe
<DevToolsFileSystemIndexer
> {
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
> {
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();
52 void StopOnFileThread();
53 void CollectFilesToIndex();
55 void StartFileIndexing(base::File::Error error
,
56 base::PassPlatformFile pass_file
,
59 void OnRead(base::File::Error error
,
62 void FinishFileIndexing(bool success
);
64 void CloseCallback(base::File::Error error
);
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_
;
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
);
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_