native_media_file_util.h revision a02191e04bc25c4935f804f2c080ae28663d096d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/weak_ptr.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "webkit/browser/fileapi/async_file_util.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace net {
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class IOBuffer;
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass MediaPathFilter;
17bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// This class handles native file system operations with media type filtering.
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// To support virtual file systems it implements the AsyncFileUtil interface
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// from scratch and provides synchronous override points.
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class NativeMediaFileUtil : public fileapi::AsyncFileUtil {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
23bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter);
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual ~NativeMediaFileUtil();
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Uses the MIME sniffer code, which actually looks into the file,
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // to determine if it is really a media file (to avoid exposing
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // non-media files with a media file extension.)
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static base::File::Error IsMediaFile(const base::FilePath& path);
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf,
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                     size_t length);
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Methods to support CreateOrOpen. Public so they can be shared with
34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // DeviceMediaAsyncFileUtil.
35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  static void CreatedSnapshotFileForCreateOrOpen(
36a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      base::SequencedTaskRunner* media_task_runner,
37a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      int file_flags,
38a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      const fileapi::AsyncFileUtil::CreateOrOpenCallback& callback,
39a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      base::File::Error result,
40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      const base::File::Info& file_info,
41a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      const base::FilePath& platform_path,
42a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
43a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // AsyncFileUtil overrides.
457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void CreateOrOpen(
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& url,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int file_flags,
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const CreateOrOpenCallback& callback) OVERRIDE;
507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void EnsureFileExists(
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const EnsureFileExistsCallback& callback) OVERRIDE;
547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void CreateDirectory(
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool exclusive,
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool recursive,
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void GetFileInfo(
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const GetFileInfoCallback& callback) OVERRIDE;
647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void ReadDirectory(
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const ReadDirectoryCallback& callback) OVERRIDE;
687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void Touch(
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const base::Time& last_access_time,
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const base::Time& last_modified_time,
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void Truncate(
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      int64 length,
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void CopyFileLocal(
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& src_url,
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& dest_url,
8368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      CopyOrMoveOption option,
8458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const CopyFileProgressCallback& progress_callback,
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void MoveFileLocal(
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& src_url,
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& dest_url,
9068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      CopyOrMoveOption option,
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void CopyInForeignFile(
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const base::FilePath& src_file_path,
95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& dest_url,
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void DeleteFile(
98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
1017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void DeleteDirectory(
102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback) OVERRIDE;
1057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void DeleteRecursively(
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const fileapi::FileSystemURL& url,
108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const StatusCallback& callback) OVERRIDE;
1097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void CreateSnapshotFile(
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const CreateSnapshotFileCallback& callback) OVERRIDE;
113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected:
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void CreateDirectoryOnTaskRunnerThread(
116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool exclusive,
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool recursive,
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback);
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void GetFileInfoOnTaskRunnerThread(
122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const GetFileInfoCallback& callback);
125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void ReadDirectoryOnTaskRunnerThread(
126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& url,
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const ReadDirectoryCallback& callback);
129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void CopyOrMoveFileLocalOnTaskRunnerThread(
130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& src_url,
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& dest_url,
13368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      CopyOrMoveOption option,
134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool copy,
135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback);
136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void CopyInForeignFileOnTaskRunnerThread(
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const base::FilePath& src_file_path,
139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& dest_url,
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback);
141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void DeleteFileOnTaskRunnerThread(
142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      scoped_ptr<fileapi::FileSystemOperationContext> context,
143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const fileapi::FileSystemURL& url,
144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const StatusCallback& callback);
145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void DeleteDirectoryOnTaskRunnerThread(
146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const StatusCallback& callback);
149868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void CreateSnapshotFileOnTaskRunnerThread(
150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<fileapi::FileSystemOperationContext> context,
151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const CreateSnapshotFileCallback& callback);
153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // The following methods should only be called on the task runner thread.
155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Necessary for copy/move to succeed.
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error CreateDirectorySync(
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& url,
160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool exclusive,
161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool recursive);
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error CopyOrMoveFileSync(
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& src_url,
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& dest_url,
16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      CopyOrMoveOption option,
167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool copy);
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error CopyInForeignFileSync(
169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const base::FilePath& src_file_path,
171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& dest_url);
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error GetFileInfoSync(
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& url,
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::File::Info* file_info,
176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      base::FilePath* platform_path);
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Called by GetFileInfoSync. Meant to be overridden by subclasses that
178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // have special mappings from URLs to platform paths (virtual filesystems).
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error GetLocalFilePath(
180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      fileapi::FileSystemOperationContext* context,
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& file_system_url,
182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      base::FilePath* local_file_path);
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error ReadDirectorySync(
184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      fileapi::FileSystemOperationContext* context,
185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url,
186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      EntryList* file_list);
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error DeleteFileSync(
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
189f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const fileapi::FileSystemURL& url);
190868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Necessary for move to succeed.
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error DeleteDirectorySync(
192868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      fileapi::FileSystemOperationContext* context,
193868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const fileapi::FileSystemURL& url);
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error CreateSnapshotFileSync(
195a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
196a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const fileapi::FileSystemURL& url,
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::File::Info* file_info,
198868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      base::FilePath* platform_path,
199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_refptr<webkit_blob::ShareableFileReference>* file_ref);
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
201d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  MediaPathFilter* media_path_filter() {
202bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch    return media_path_filter_;
203bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  }
204bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Like GetLocalFilePath(), but always take media_path_filter() into
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // consideration. If the media_path_filter() check fails, return
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist.
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::File::Error GetFilteredLocalFilePath(
210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
211c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& file_system_url,
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath* local_file_path);
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Like GetLocalFilePath(), but if the file does not exist, then return
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |failure_error|.
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If |local_file_path| is a file, then take media_path_filter() into
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // consideration.
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If the media_path_filter() check fails, return |failure_error|.
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If |local_file_path| is a directory, return PLATFORM_FILE_OK.
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::File::Error GetFilteredLocalFilePathForExistingFileOrDirectory(
221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      fileapi::FileSystemOperationContext* context,
222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const fileapi::FileSystemURL& file_system_url,
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::File::Error failure_error,
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath* local_file_path);
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
227bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  // Not owned, owned by the backend which owns this.
228d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  MediaPathFilter* media_path_filter_;
229bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
2304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_;
2314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil);
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif  // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_
236