summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/drive/fileapi_worker.h
blob: bef86f9ff869c170c07d6594680067b41671a87b (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
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
// Copyright 2013 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.
//
// This file provides the core implementation of fileapi methods.
// The functions should be called on UI thread.
// Note that most method invocation of fileapi is done on IO thread. The gap is
// filled by FileSystemProxy.
// Also, the order of arguments for the functions which take FileSystemInterface
// at the last is intentional. The instance of FileSystemInterface should be
// accessible only on UI thread, but arguments are passed on IO thread.
// So, here is an intended use case:
//   1) Bind arguments on IO thread. Then a callback instance whose type is
//      Callback<void(FileSysstemInterface*)> is created.
//   2) Post the task to the UI thread.
//   3) On UI thread, check if the instance of FileSystemInterface is alive or
//      not. If yes, Run the callback with it.

#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_
#define CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_

#include <vector>

#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "chrome/browser/chromeos/drive/file_errors.h"
#include "webkit/common/blob/scoped_file.h"

namespace base {
class FilePath;
}  // namespace base

namespace fileapi {
struct DirectoryEntry;
}  // namespace fileapi

namespace drive {

class FileSystemInterface;

namespace fileapi_internal {

typedef base::Callback<FileSystemInterface*()> FileSystemGetter;

typedef base::Callback<
    void(base::PlatformFileError result)> StatusCallback;
typedef base::Callback<
    void(base::PlatformFileError result,
         const base::PlatformFileInfo& file_info)> GetFileInfoCallback;
typedef base::Callback<
    void(base::PlatformFileError result,
         const std::vector<fileapi::DirectoryEntry>& file_list,
         bool has_more)> ReadDirectoryCallback;
typedef base::Callback<
    void(base::PlatformFileError result,
         const base::PlatformFileInfo& file_info,
         const base::FilePath& snapshot_file_path,
         webkit_blob::ScopedFile::ScopeOutPolicy scope_out_policy)>
    CreateSnapshotFileCallback;
typedef base::Callback<
    void(base::PlatformFileError result,
         const base::FilePath& snapshot_file_path,
         const base::Closure& close_callback)>
    CreateWritableSnapshotFileCallback;
typedef base::Callback<
    void(base::PlatformFileError result,
         base::PlatformFile platform_file,
         const base::Closure& close_callback)> OpenFileCallback;

// Runs |file_system_getter| to obtain the instance of FileSystemInstance,
// and then runs |callback| with it.
// If |file_system_getter| returns NULL, runs |error_callback| instead.
// This function must be called on UI thread.
// |file_system_getter| and |callback| must not be null, but
// |error_callback| can be null (if no operation is necessary for error
// case).
void RunFileSystemCallback(
    const FileSystemGetter& file_system_getter,
    const base::Callback<void(FileSystemInterface*)>& callback,
    const base::Closure& error_callback);

// Returns the metadata info of the file at |file_path|.
// Called from FileSystemProxy::GetFileInfo().
void GetFileInfo(const base::FilePath& file_path,
                 const GetFileInfoCallback& callback,
                 FileSystemInterface* file_system);

// Copies a file from |src_file_path| to |dest_file_path|.
// Called from FileSystemProxy::Copy().
void Copy(const base::FilePath& src_file_path,
          const base::FilePath& dest_file_path,
          const StatusCallback& callback,
          FileSystemInterface* file_system);

// Moves a file from |src_file_path| to |dest_file_path|.
// Called from FileSystemProxy::Move().
void Move(const base::FilePath& src_file_path,
          const base::FilePath& dest_file_path,
          const StatusCallback& callback,
          FileSystemInterface* file_system);


// Copies a file at |src_foreign_file_path|, which is not managed by Drive File
// System, to |dest_file_path|.
void CopyInForeignFile(const base::FilePath& src_foreign_file_path,
                       const base::FilePath& dest_file_path,
                       const StatusCallback& callback,
                       FileSystemInterface* file_system);

// Reads the contents of the directory at |file_path|.
// Called from FileSystemProxy::ReadDirectory().
void ReadDirectory(const base::FilePath& file_path,
                   const ReadDirectoryCallback& callback,
                   FileSystemInterface* file_system);

// Removes a file at |file_path|. Called from FileSystemProxy::Remove().
void Remove(const base::FilePath& file_path,
            bool is_recursive,
            const StatusCallback& callback,
            FileSystemInterface* file_system);

// Creates a new directory at |file_path|.
// Called from FileSystemProxy::CreateDirectory().
void CreateDirectory(const base::FilePath& file_path,
                     bool is_exclusive,
                     bool is_recursive,
                     const StatusCallback& callback,
                     FileSystemInterface* file_system);

// Creates a new file at |file_path|.
// Called from FileSystemProxy::CreateFile().
void CreateFile(const base::FilePath& file_path,
                bool is_exclusive,
                const StatusCallback& callback,
                FileSystemInterface* file_system);

// Truncates the file at |file_path| to |length| bytes.
// Called from FileSystemProxy::Truncate().
void Truncate(const base::FilePath& file_path,
              int64 length,
              const StatusCallback& callback,
              FileSystemInterface* file_system);

// Creates a snapshot for the file at |file_path|.
// Called from FileSystemProxy::CreateSnapshotFile().
void CreateSnapshotFile(const base::FilePath& file_path,
                        const CreateSnapshotFileCallback& callback,
                        FileSystemInterface* file_system);

// Creates a writable snapshot for the file at |file_path|.
// After writing operation is done, |close_callback| must be called.
void CreateWritableSnapshotFile(
    const base::FilePath& file_path,
    const CreateWritableSnapshotFileCallback& callback,
    FileSystemInterface* file_system);

// Opens the file at |file_path| with options |file_flags|.
// Called from FileSystemProxy::OpenFile.
void OpenFile(const base::FilePath& file_path,
              int file_flags,
              const OpenFileCallback& callback,
              FileSystemInterface* file_system);

// Changes timestamp of the file at |file_path| to |last_access_time| and
// |last_modified_time|. Called from FileSystemProxy::TouchFile().
void TouchFile(const base::FilePath& file_path,
               const base::Time& last_access_time,
               const base::Time& last_modified_time,
               const StatusCallback& callback,
               FileSystemInterface* file_system);

}  // namespace fileapi_internal
}  // namespace drive

#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_