// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BRIGHTRAY_BROWSER_DEVTOOLS_FILE_SYSTEM_INDEXER_H_ #define BRIGHTRAY_BROWSER_DEVTOOLS_FILE_SYSTEM_INDEXER_H_ #include #include #include #include #include #include "base/callback.h" #include "base/files/file_proxy.h" #include "base/macros.h" #include "base/memory/ref_counted.h" namespace base { class FilePath; class FileEnumerator; class Time; } namespace content { class WebContents; } namespace brightray { class DevToolsFileSystemIndexer : public base::RefCountedThreadSafe { public: typedef base::Callback TotalWorkCallback; typedef base::Callback WorkedCallback; typedef base::Callback DoneCallback; typedef base::Callback&)> SearchCallback; class FileSystemIndexingJob : public base::RefCounted { public: void Stop(); private: friend class base::RefCounted; friend class DevToolsFileSystemIndexer; FileSystemIndexingJob(const base::FilePath& file_system_path, const TotalWorkCallback& total_work_callback, const WorkedCallback& worked_callback, const DoneCallback& done_callback); virtual ~FileSystemIndexingJob(); void Start(); void StopOnFileThread(); void CollectFilesToIndex(); void IndexFiles(); void StartFileIndexing(base::File::Error error); void ReadFromFile(); void OnRead(base::File::Error error, const char* data, int bytes_read); void FinishFileIndexing(bool success); void CloseFile(); void CloseCallback(base::File::Error error); void ReportWorked(); base::FilePath file_system_path_; TotalWorkCallback total_work_callback_; WorkedCallback worked_callback_; DoneCallback done_callback_; std::unique_ptr file_enumerator_; typedef std::map FilePathTimesMap; FilePathTimesMap file_path_times_; FilePathTimesMap::const_iterator indexing_it_; base::FileProxy current_file_; int64_t current_file_offset_; typedef int32_t Trigram; std::vector current_trigrams_; // The index in this vector is the trigram id. std::vector current_trigrams_set_; base::TimeTicks last_worked_notification_time_; int files_indexed_; bool stopped_; }; DevToolsFileSystemIndexer(); // Performs file system indexing for given |file_system_path| and sends // progress callbacks. scoped_refptr IndexPath( const std::string& file_system_path, const TotalWorkCallback& total_work_callback, const WorkedCallback& worked_callback, const DoneCallback& done_callback); // Performs trigram search for given |query| in |file_system_path|. void SearchInPath(const std::string& file_system_path, const std::string& query, const SearchCallback& callback); private: friend class base::RefCountedThreadSafe; virtual ~DevToolsFileSystemIndexer(); void SearchInPathOnFileThread(const std::string& file_system_path, const std::string& query, const SearchCallback& callback); DISALLOW_COPY_AND_ASSIGN(DevToolsFileSystemIndexer); }; } // namespace brightray #endif // BRIGHTRAY_BROWSER_DEVTOOLS_FILE_SYSTEM_INDEXER_H_