summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_file_util_proxy.h
blob: 16eee747ca15887cb681e27352cc9deddeea0638 (plain)
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
// Copyright (c) 2011 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 WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_

#include <vector>

#include "base/callback.h"
#include "base/callback_old.h"
#include "base/file_path.h"
#include "base/file_util_proxy.h"
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
#include "base/tracked_objects.h"

namespace base {
class MessageLoopProxy;
}

namespace fileapi {

using base::MessageLoopProxy;
using base::PlatformFile;
using base::PlatformFileError;
using base::PlatformFileInfo;

// This class provides relay methods for supporting asynchronous access to
// FileSystem API operations.  (Most of necessary relay methods are provided
// by base::FileUtilProxy, but there are a few operations that are not
// covered or are slightly different from the version of base::FileUtilProxy.
class FileSystemFileUtilProxy {
 public:
  typedef base::FileUtilProxy::Entry Entry;

  typedef base::Callback<void(PlatformFileError,
                              bool /* created */
                              )> EnsureFileExistsCallback;
  typedef base::Callback<void(PlatformFileError,
                              const PlatformFileInfo&,
                              const FilePath& /* platform_path */
                              )> GetFileInfoCallback;
  typedef base::Callback<void(PlatformFileError,
                              const std::vector<Entry>&
                              )> ReadDirectoryCallback;

  typedef base::Callback<PlatformFileError(bool* /* created */
                                           )> EnsureFileExistsTask;
  typedef base::Callback<PlatformFileError(PlatformFileInfo*,
                                           FilePath*)> GetFileInfoTask;
  typedef base::Callback<PlatformFileError(std::vector<Entry>*
                                           )> ReadDirectoryTask;

  // Calls EnsureFileExistsTask |task| on the given |message_loop_proxy|.
  static bool RelayEnsureFileExists(
      scoped_refptr<MessageLoopProxy> message_loop_proxy,
      const EnsureFileExistsTask& task,
      const EnsureFileExistsCallback& callback);

  // Calls GetFileInfoTask |task| on the given |message_loop_proxy|.
  static bool RelayGetFileInfo(
      scoped_refptr<MessageLoopProxy> message_loop_proxy,
      const GetFileInfoTask& task,
      const GetFileInfoCallback& callback);

  // Calls ReadDirectoryTask |task| on the given |message_loop_proxy|.
  // TODO: this should support returning entries in multiple chunks.
  static bool RelayReadDirectory(
      scoped_refptr<MessageLoopProxy> message_loop_proxy,
      const ReadDirectoryTask& task,
      const ReadDirectoryCallback& callback);

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy);
};

}  // namespace fileapi

#endif  // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_