#ifndef CHROME_BROWSER_ASH_FILEAPI_RECENT_DISK_SOURCE_H_
#define CHROME_BROWSER_ASH_FILEAPI_RECENT_DISK_SOURCE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/containers/id_map.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/ash/fileapi/file_accumulator.h"
#include "chrome/browser/ash/fileapi/recent_file.h"
#include "chrome/browser/ash/fileapi/recent_model.h"
#include "chrome/browser/ash/fileapi/recent_source.h"
#include "storage/browser/file_system/file_system_operation.h"
namespace ash {
class RecentDiskSource : public RecentSource {
public:
RecentDiskSource(
extensions::api::file_manager_private::VolumeType volume_type,
std::string mount_point_name,
bool ignore_dotfiles,
int max_depth,
std::string uma_histogram_name);
RecentDiskSource(const RecentDiskSource&) = delete;
RecentDiskSource& operator=(const RecentDiskSource&) = delete;
~RecentDiskSource() override;
void GetRecentFiles(const Params& params,
GetRecentFilesCallback callback) override;
std::vector<RecentFile> Stop(const int32_t call_id) override;
static bool MatchesFileType(const base::FilePath& path,
RecentSource::FileType file_type);
private:
FRIEND_TEST_ALL_PREFIXES(RecentDiskSourceTest, GetRecentFiles_UmaStats);
static const char kLoadHistogramName[];
void ScanDirectory(const int32_t call_id,
const base::FilePath& path,
int depth);
void OnReadDirectory(const int32_t call_id,
const base::FilePath& path,
int depth,
base::File::Error result,
storage::FileSystemOperation::FileEntryList entries,
bool has_more);
void OnGotMetadata(const int32_t call_id,
const storage::FileSystemURL& url,
base::File::Error result,
const base::File::Info& info);
void OnReadOrStatFinished(int32_t call_id);
storage::FileSystemURL BuildDiskURL(const Params& params,
const base::FilePath& path) const;
const std::string mount_point_name_;
const bool ignore_dotfiles_;
const int max_depth_;
const std::string uma_histogram_name_;
struct CallContext {
CallContext(const Params& params, GetRecentFilesCallback callback);
CallContext(CallContext&& context);
~CallContext();
const Params params;
GetRecentFilesCallback callback;
base::TimeTicks build_start_time;
int inflight_readdirs = 0;
int inflight_stats = 0;
FileAccumulator accumulator;
};
base::IDMap<std::unique_ptr<CallContext>> context_map_;
base::WeakPtrFactory<RecentDiskSource> weak_ptr_factory_{this};
};
}
#endif