1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
#include <stdint.h>
#include <memory>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/file_system/async_file_util.h"
#include "storage/browser/file_system/watcher_manager.h"
namespace storage {
class FileSystemOperationContext;
class FileSystemURL;
}
namespace storage {
class FileStreamReader;
}
enum MediaFileValidationType {
NO_MEDIA_FILE_VALIDATION,
APPLY_MEDIA_FILE_VALIDATION,
};
class DeviceMediaAsyncFileUtil : public storage::AsyncFileUtil {
public:
DeviceMediaAsyncFileUtil(const DeviceMediaAsyncFileUtil&) = delete;
DeviceMediaAsyncFileUtil& operator=(const DeviceMediaAsyncFileUtil&) = delete;
~DeviceMediaAsyncFileUtil() override;
// Returns an instance of DeviceMediaAsyncFileUtil.
static std::unique_ptr<DeviceMediaAsyncFileUtil> Create(
const base::FilePath& profile_path,
MediaFileValidationType validation_type);
bool SupportsStreaming(const storage::FileSystemURL& url);
// AsyncFileUtil overrides.
void CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
EnsureFileExistsCallback callback) override;
void CreateDirectory(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
bool exclusive,
bool recursive,
StatusCallback callback) override;
void GetFileInfo(std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
GetMetadataFieldSet fields,
GetFileInfoCallback callback) override;
void ReadDirectory(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
ReadDirectoryCallback callback) override;
void Touch(std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
const base::Time& last_access_time,
const base::Time& last_modified_time,
StatusCallback callback) override;
void Truncate(std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int64_t length,
StatusCallback callback) override;
void CopyFileLocal(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url,
CopyOrMoveOptionSet options,
CopyFileProgressCallback progress_callback,
StatusCallback callback) override;
void MoveFileLocal(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url,
CopyOrMoveOptionSet options,
StatusCallback callback) override;
void CopyInForeignFile(
std::unique_ptr<storage::FileSystemOperationContext> context,
const base::FilePath& src_file_path,
const storage::FileSystemURL& dest_url,
StatusCallback callback) override;
void DeleteFile(std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
StatusCallback callback) override;
void DeleteDirectory(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
StatusCallback callback) override;
void DeleteRecursively(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
StatusCallback callback) override;
void CreateSnapshotFile(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
CreateSnapshotFileCallback callback) override;
// This method is called when existing Blobs are read.
// |expected_modification_time| indicates the expected snapshot state of the
// underlying storage. The returned FileStreamReader must return an error
// when the state of the underlying storage changes. Any errors associated
// with reading this file are returned by the FileStreamReader itself.
virtual std::unique_ptr<storage::FileStreamReader> GetFileStreamReader(
const storage::FileSystemURL& url,
int64_t offset,
const base::Time& expected_modification_time,
storage::FileSystemContext* context);
// Adds watcher to |url|.
void AddWatcher(
const storage::FileSystemURL& url,
bool recursive,
storage::WatcherManager::StatusCallback callback,
storage::WatcherManager::NotificationCallback notification_callback);
// Removes watcher of |url|.
void RemoveWatcher(const storage::FileSystemURL& url,
const bool recursive,
storage::WatcherManager::StatusCallback callback);
private:
class MediaPathFilterWrapper;
// Use Create() to get an instance of DeviceMediaAsyncFileUtil.
DeviceMediaAsyncFileUtil(const base::FilePath& profile_path,
MediaFileValidationType validation_type);
// Called when CreateDirectory method call succeeds. |callback| is invoked to
// complete the CreateDirectory request.
void OnDidCreateDirectory(StatusCallback callback);
// Called when GetFileInfo method call succeeds. |file_info| contains the
// file details of the requested url. |callback| is invoked to complete the
// GetFileInfo request.
void OnDidGetFileInfo(base::SequencedTaskRunner* task_runner,
const base::FilePath& path,
GetFileInfoCallback callback,
const base::File::Info& file_info);
// Called when ReadDirectory method call succeeds. |callback| is invoked to
// complete the ReadDirectory request.
//
// If the contents of the given directory are reported in one batch, then
// |file_list| will have the list of all files/directories in the given
// directory and |has_more| will be false.
//
// If the contents of the given directory are reported in multiple chunks,
// |file_list| will have only a subset of all contents (the subsets reported
// in any two calls are disjoint), and |has_more| will be true, except for
// the last chunk.
void OnDidReadDirectory(base::SequencedTaskRunner* task_runner,
ReadDirectoryCallback callback,
EntryList file_list,
bool has_more);
// Called when MoveFileLocal method call succeeds. |callback| is invoked to
// complete the MoveFileLocal request.
void OnDidMoveFileLocal(StatusCallback callback);
// Called when CopyFileLocal method call succeeds. |callback| is invoked to
// complete the CopyFileLocal request.
void OnDidCopyFileLocal(StatusCallback callback);
// Called when CopyInForeignFile method call succeeds. |callback| is invoked
// to complete the CopyInForeignFile request.
void OnDidCopyInForeignFile(StatusCallback callback);
// Called when DeleteFile method call succeeeds. |callback| is invoked to
// complete the DeleteFile request.
void OnDidDeleteFile(StatusCallback callback);
// Called when DeleteDirectory method call succeeds. |callback| is invoked to
// complete the DeleteDirectory request.
void OnDidDeleteDirectory(StatusCallback callback);
bool validate_media_files() const;
// Profile path.
const base::FilePath profile_path_;
scoped_refptr<MediaPathFilterWrapper> media_path_filter_wrapper_;
// For callbacks that may run after destruction.
base::WeakPtrFactory<DeviceMediaAsyncFileUtil> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
|