file_system_operation.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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)
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/callback.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/files/file.h"
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/files/file_path.h"
1358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch#include "base/process/process.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_operation_context.h"
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/storage_browser_export.h"
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/common/fileapi/directory_entry.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Time;
207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class URLRequest;
247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ShareableFileReference;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class FileSystemContext;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemURL;
367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class FileWriterDelegate;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The interface class for FileSystemOperation implementations.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This interface defines file system operations required to implement
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "File API: Directories and System"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://www.w3.org/TR/file-system-api/
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DESIGN NOTES
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class is designed to
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1) Serve one-time file system operation per instance.  Only one
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists,
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// GetMetadata, ReadDirectory and Remove) may be called during the
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// lifetime of this object and it should be called no more than once.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// 2) Deliver the results of operations to the client via the callback function
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// passed as the last parameter of the method.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Note that it is valid to delete an operation while it is running.
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// The callback will NOT be fired if the operation is deleted before
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// it gets called.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemOperation {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  STORAGE_EXPORT static FileSystemOperation* Create(
6258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const FileSystemURL& url,
6358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      FileSystemContext* file_system_context,
6458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      scoped_ptr<FileSystemOperationContext> operation_context);
6558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~FileSystemOperation() {}
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for CreateFile(), etc. |result| is the return code of the operation.
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef base::Callback<void(base::File::Error result)> StatusCallback;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for GetMetadata(). |result| is the return code of the operation,
727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // |file_info| is the obtained file info.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      void(base::File::Error result,
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)           const base::File::Info& file_info)> GetMetadataCallback;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
77cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Used for OpenFile(). |on_close_callback| will be called after the file is
78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // closed in the child process. It can be null, if no operation is needed on
79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // closing a file.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<
81cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      void(base::File file,
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)           const base::Closure& on_close_callback)> OpenFileCallback;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for ReadDirectoryCallback.
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  typedef std::vector<DirectoryEntry> FileEntryList;
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for ReadDirectory(). |result| is the return code of the operation,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |file_list| is the list of files read, and |has_more| is true if some files
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are yet to be read.
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      void(base::File::Error result,
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           const FileEntryList& file_list,
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           bool has_more)> ReadDirectoryCallback;
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for CreateSnapshotFile(). (Please see the comment at
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CreateSnapshotFile() below for how the method is called)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |result| is the return code of the operation.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |file_info| is the metadata of the snapshot file created.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |platform_path| is the path to the snapshot file created.
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The snapshot file could simply be of the local file pointed by the given
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // filesystem URL in local filesystem cases; remote filesystems
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may want to download the file into a temporary snapshot file and then
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return the metadata of the temporary file.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |file_ref| is used to manage the lifetime of the returned
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // snapshot file.  It can be set to let the chromium backend take
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // care of the life time of the snapshot file.  Otherwise (if the returned
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // file does not require any handling) the implementation can just
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return NULL.  In a more complex case, the implementaiton can manage
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the lifetime of the snapshot file on its own (e.g. by its cache system)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // but also can be notified via the reference when the file becomes no
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // longer necessary in the javascript world.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Please see the comment for ShareableFileReference for details.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      void(base::File::Error result,
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)           const base::File::Info& file_info,
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const base::FilePath& platform_path,
12003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)           const scoped_refptr<storage::ShareableFileReference>& file_ref)>
12103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      SnapshotFileCallback;
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Used for progress update callback for Copy().
12458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
12558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both
12658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // file and directory).
12758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // The |source_url| is the URL of the source entry. |size| should not be
12858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // used.
12958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
13058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // END_COPY_ENTRY is fired for each copy creation finishing (for both
13158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // file and directory).
13268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The |source_url| is the URL of the source entry. The |destination_url| is
13368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // the URL of the destination entry. |size| should not be used.
13458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
13558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS is fired periodically during file copying (not fired for
13658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // directory copy).
13758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // The |source_url| is the URL of the source file. |size| is the number
13858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // of cumulative copied bytes for the currently copied file.
13958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Both at beginning and ending of file copying, PROGRESS event should be
14058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // called. At beginning, |size| should be 0. At ending, |size| should be
14158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // the size of the file.
14258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
14358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Here is an example callback sequence of recursive copy. Suppose
14458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // there are a/b/c.txt (100 bytes) and a/b/d.txt (200 bytes), and trying to
14558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // copy a to x recursively, then the progress update sequence will be:
14658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
14758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // BEGIN_COPY_ENTRY a  (starting create "a" directory in x/).
14868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // END_COPY_ENTRY a x/a (creating "a" directory in x/ is finished).
14958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
15058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // BEGIN_COPY_ENTRY a/b (starting create "b" directory in x/a).
15168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // END_COPY_ENTRY a/b x/a/b (creating "b" directory in x/a/ is finished).
15258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
15358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // BEGIN_COPY_ENTRY a/b/c.txt (starting to copy "c.txt" in x/a/b/).
15458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/c.txt 0 (The first PROGRESS's |size| should be 0).
15558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/c.txt 10
15658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //    :
15758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/c.txt 90
15858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/c.txt 100 (The last PROGRESS's |size| should be the size of
15958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //                         the file).
16068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // END_COPY_ENTRY a/b/c.txt x/a/b/c.txt (copying "c.txt" is finished).
16158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
16258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // BEGIN_COPY_ENTRY a/b/d.txt (starting to copy "d.txt" in x/a/b).
16358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/d.txt 0 (The first PROGRESS's |size| should be 0).
16458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/d.txt 10
16558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //    :
16658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/d.txt 190
16758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // PROGRESS a/b/d.txt 200 (The last PROGRESS's |size| should be the size of
16858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //                         the file).
16968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // END_COPY_ENTRY a/b/d.txt x/a/b/d.txt (copy "d.txt" is finished).
17058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
17158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Note that event sequence of a/b/c.txt and a/b/d.txt can be interlaced,
17258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // because they can be done in parallel. Also PROGRESS events are optional,
17358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // so they may not be appeared.
17458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // All the progress callback invocation should be done before StatusCallback
17558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // given to the Copy is called. Especially if an error is found before first
17658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // progres callback invocation, the progress callback may NOT invoked for the
17758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // copy.
17858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
17958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Note for future extension. Currently this callback is only supported on
18058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Copy(). We can extend this to Move(), because Move() is sometimes
18158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // implemented as "copy then delete."
18258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // In more precise, Move() usually can be implemented either 1) by updating
18358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // the metadata of resource (e.g. root of moving directory tree), or 2) by
18458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // copying directory tree and them removing the source tree.
18558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // For 1)'s case, we can simply add BEGIN_MOVE_ENTRY and END_MOVE_ENTRY
18658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // for root directory.
18758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // For 2)'s case, we can add BEGIN_DELETE_ENTRY and END_DELETE_ENTRY for each
18858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // entry.
18958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // For both cases, we probably won't need to use PROGRESS event because
19058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // these operations should be done quickly (at least much faster than copying
19158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // usually).
19258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  enum CopyProgressType {
19358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    BEGIN_COPY_ENTRY,
19458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    END_COPY_ENTRY,
19558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    PROGRESS,
19658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  };
19768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  typedef base::Callback<void(CopyProgressType type,
19868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                              const FileSystemURL& source_url,
19968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                              const FileSystemURL& destination_url,
20068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                              int64 size)>
20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      CopyProgressCallback;
20258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
20358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Used for CopyFileLocal() to report progress update.
20458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // |size| is the cumulative copied bytes for the copy.
20558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // At the beginning the progress callback should be called with |size| = 0,
20658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // and also at the ending the progress callback should be called with |size|
20758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // set to the copied file size.
20858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  typedef base::Callback<void(int64 size)> CopyFileProgressCallback;
20958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
21068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The option for copy or move operation.
21168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  enum CopyOrMoveOption {
21268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // No additional operation.
21368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    OPTION_NONE,
21468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
21568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // Preserves last modified time if possible. If the operation to update
21668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // last modified time is not supported on the file system for the
21768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // destination file, this option would be simply ignored (i.e. Copy would
21868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // be successfully done without preserving last modified time).
21968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    OPTION_PRESERVE_LAST_MODIFIED,
22068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  };
22168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for Write().
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef base::Callback<void(base::File::Error result,
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              int64 bytes,
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              bool complete)> WriteCallback;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a file at |path|. If |exclusive| is true, an error is raised
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in case a file is already present at the URL.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CreateFile(const FileSystemURL& path,
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          bool exclusive,
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          const StatusCallback& callback) = 0;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a directory at |path|. If |exclusive| is true, an error is
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // raised in case a directory is already present at the URL. If
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |recursive| is true, create parent directories as needed just like
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // mkdir -p does.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CreateDirectory(const FileSystemURL& path,
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               bool exclusive,
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               bool recursive,
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const StatusCallback& callback) = 0;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Copies a file or directory from |src_path| to |dest_path|. If
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |src_path| is a directory, the contents of |src_path| are copied to
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |dest_path| recursively. A new file or directory is created at
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |dest_path| as needed.
24668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's
24768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // comment for details.
24858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // |progress_callback| is periodically called to report the progress
24958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // update. See also the comment of CopyProgressCallback. This callback is
25058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // optional.
251424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
252424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // For recursive case this internally creates new FileSystemOperations and
253424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // calls:
254424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // - ReadDirectory, CopyFileLocal and CreateDirectory
255424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   for same-filesystem case, or
256424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // - ReadDirectory and CreateSnapshotFile on source filesystem and
257424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   CopyInForeignFile and CreateDirectory on dest filesystem
258424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   for cross-filesystem case.
259424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Copy(const FileSystemURL& src_path,
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const FileSystemURL& dest_path,
26268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    CopyOrMoveOption option,
26358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                    const CopyProgressCallback& progress_callback,
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const StatusCallback& callback) = 0;
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Moves a file or directory from |src_path| to |dest_path|. A new file
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or directory is created at |dest_path| as needed.
26868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's
26968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // comment for details.
270424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
271424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // For recursive case this internally creates new FileSystemOperations and
272424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // calls:
273424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // - ReadDirectory, MoveFileLocal, CreateDirectory and Remove
274424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   for same-filesystem case, or
275424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // - ReadDirectory, CreateSnapshotFile and Remove on source filesystem and
276424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   CopyInForeignFile and CreateDirectory on dest filesystem
277424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   for cross-filesystem case.
278424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Move(const FileSystemURL& src_path,
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const FileSystemURL& dest_path,
28168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    CopyOrMoveOption option,
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const StatusCallback& callback) = 0;
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Checks if a directory is present at |path|.
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DirectoryExists(const FileSystemURL& path,
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const StatusCallback& callback) = 0;
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Checks if a file is present at |path|.
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void FileExists(const FileSystemURL& path,
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          const StatusCallback& callback) = 0;
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the metadata of a file or directory at |path|.
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetMetadata(const FileSystemURL& path,
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           const GetMetadataCallback& callback) = 0;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads contents of a directory at |path|.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ReadDirectory(const FileSystemURL& path,
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const ReadDirectoryCallback& callback) = 0;
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes a file or directory at |path|. If |recursive| is true, remove
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // all files and directories under the directory at |path| recursively.
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Remove(const FileSystemURL& path, bool recursive,
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                      const StatusCallback& callback) = 0;
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Writes the data read from |blob_request| using |writer_delegate|.
3067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void Write(
3077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const FileSystemURL& url,
3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    scoped_ptr<FileWriterDelegate> writer_delegate,
3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    scoped_ptr<net::URLRequest> blob_request,
3107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const WriteCallback& callback) = 0;
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Truncates a file at |path| to |length|. If |length| is larger than
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the original file size, the file will be extended, and the extended
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // part is filled with null bytes.
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Truncate(const FileSystemURL& path, int64 length,
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        const StatusCallback& callback) = 0;
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tries to cancel the current operation [we support cancelling write or
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // truncate only]. Reports failure for the current operation, then reports
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // success for the cancel operation itself via the |cancel_dispatcher|.
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // E.g. a typical cancel implementation would look like:
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   virtual void SomeOperationImpl::Cancel(
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //       const StatusCallback& cancel_callback) {
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //     // Abort the current inflight operation first.
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //     ...
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //     // Dispatch ABORT error for the current operation by invoking
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //     // the callback function for the ongoing operation,
331cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  //     operation_callback.Run(base::File::FILE_ERROR_ABORT, ...);
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //     // Dispatch 'success' for the cancel (or dispatch appropriate
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //     // error code with DidFail() if the cancel has somehow failed).
335cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  //     cancel_callback.Run(base::File::FILE_OK);
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   }
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that, for reporting failure, the callback function passed to a
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancellable operations are kept around with the operation instance
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (as |operation_callback_| in the code example).
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Cancel(const StatusCallback& cancel_callback) = 0;
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Modifies timestamps of a file or directory at |path| with
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |last_access_time| and |last_modified_time|. The function DOES NOT
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // create a file unlike 'touch' command on Linux.
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This function is used only by Pepper as of writing.
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void TouchFile(const FileSystemURL& path,
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const base::Time& last_access_time,
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const base::Time& last_modified_time,
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const StatusCallback& callback) = 0;
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Opens a file at |path| with |file_flags|, where flags are OR'ed
354cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // values of base::File::Flags.
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This function is used only by Pepper as of writing.
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OpenFile(const FileSystemURL& path,
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        int file_flags,
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        const OpenFileCallback& callback) = 0;
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a local snapshot file for a given |path| and returns the
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // metadata and platform path of the snapshot file via |callback|.
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // In local filesystem cases the implementation may simply return
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the metadata of the file itself (as well as GetMetadata does),
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // while in remote filesystem case the backend may want to download the file
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // into a temporary snapshot file and return the metadata of the
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // temporary file.  Or if the implementaiton already has the local cache
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // data for |path| it can simply return the path to the cache.
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CreateSnapshotFile(const FileSystemURL& path,
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const SnapshotFileCallback& callback) = 0;
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
372424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Copies in a single file from a different filesystem.
373424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
374424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This returns:
375cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_FOUND if |src_file_path|
376424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   or the parent directory of |dest_url| does not exist.
377cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
378424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   is not a file.
379cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_FAILED if |dest_url| does not exist and
380424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   its parent path is a file.
381424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
382424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path,
383424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                                 const FileSystemURL& dest_url,
384424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                                 const StatusCallback& callback) = 0;
385424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
386424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Removes a single file.
387424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
388424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This returns:
389cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_FOUND if |url| does not exist.
390cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_A_FILE if |url| is not a file.
391424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
392424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void RemoveFile(const FileSystemURL& url,
393424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                          const StatusCallback& callback) = 0;
394424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
395424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Removes a single empty directory.
396424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
397424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This returns:
398cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_FOUND if |url| does not exist.
399cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory.
400cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_EMPTY if |url| is not empty.
401424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
402424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void RemoveDirectory(const FileSystemURL& url,
403424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                               const StatusCallback& callback) = 0;
404424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
405424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Copies a file from |src_url| to |dest_url|.
406424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This must be called for files that belong to the same filesystem
407424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
40868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's
40968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // comment for details.
41058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // |progress_callback| is periodically called to report the progress
41158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // update. See also the comment of CopyFileProgressCallback. This callback is
41258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // optional.
413424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
414424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This returns:
415cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_FOUND if |src_url|
416424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   or the parent directory of |dest_url| does not exist.
417cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file.
418cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
419424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   is not a file.
420cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_FAILED if |dest_url| does not exist and
421424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   its parent path is a file.
422424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
423424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void CopyFileLocal(const FileSystemURL& src_url,
424424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                             const FileSystemURL& dest_url,
42568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                             CopyOrMoveOption option,
42658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                             const CopyFileProgressCallback& progress_callback,
427424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                             const StatusCallback& callback) = 0;
428424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
429424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Moves a local file from |src_url| to |dest_url|.
430424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This must be called for files that belong to the same filesystem
431424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
43268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's
43368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // comment for details.
434424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
435424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This returns:
436cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_FOUND if |src_url|
437424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   or the parent directory of |dest_url| does not exist.
438cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file.
439cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
440424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   is not a file.
441cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // - File::FILE_ERROR_FAILED if |dest_url| does not exist and
442424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //   its parent path is a file.
443424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  //
444424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void MoveFileLocal(const FileSystemURL& src_url,
445424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                             const FileSystemURL& dest_url,
44668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                             CopyOrMoveOption option,
447424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                             const StatusCallback& callback) = 0;
448424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
449424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Synchronously gets the platform path for the given |url|.
450424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // This may fail if the given |url|'s filesystem type is neither
451424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // temporary nor persistent.
452cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // In such a case, base::File::FILE_ERROR_INVALID_OPERATION will be
453424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // returned.
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error SyncGetPlatformPath(
455424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      const FileSystemURL& url,
456424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      base::FilePath* platform_path) = 0;
457424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used only for internal assertions.
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum OperationType {
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationNone,
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCreateFile,
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCreateDirectory,
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCreateSnapshotFile,
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCopy,
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCopyInForeignFile,
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationMove,
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationDirectoryExists,
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationFileExists,
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationGetMetadata,
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationReadDirectory,
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationRemove,
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationWrite,
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationTruncate,
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationTouchFile,
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationOpenFile,
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCloseFile,
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationGetLocalPath,
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationCancel,
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
48303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}  // namespace storage
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_
486