Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: webkit/fileapi/file_system_operation.h

Issue 6603034: Stop returning the true root path of each filesystem from openFileSystem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util_proxy.h" 11 #include "base/file_util_proxy.h"
12 #include "base/gtest_prod_util.h"
12 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
13 #include "base/platform_file.h" 14 #include "base/platform_file.h"
14 #include "base/ref_counted.h" 15 #include "base/ref_counted.h"
15 #include "base/scoped_callback_factory.h" 16 #include "base/scoped_callback_factory.h"
16 #include "base/scoped_ptr.h" 17 #include "base/scoped_ptr.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 #include "webkit/fileapi/file_system_types.h" 19 #include "webkit/fileapi/file_system_types.h"
19 #include "webkit/fileapi/file_system_operation_context.h" 20 #include "webkit/fileapi/file_system_operation_context.h"
20 21
21 namespace base { 22 namespace base {
22 class Time; 23 class Time;
23 } 24 }
24 25
25 namespace net { 26 namespace net {
26 class URLRequest; 27 class URLRequest;
27 class URLRequestContext; 28 class URLRequestContext;
28 } // namespace net 29 } // namespace net
29 30
30 class GURL; 31 class GURL;
31 32
32 namespace fileapi { 33 namespace fileapi {
33 34
34 class FileSystemCallbackDispatcher; 35 class FileSystemCallbackDispatcher;
35 class FileSystemContext; 36 class FileSystemContext;
36 class FileWriterDelegate; 37 class FileWriterDelegate;
38 class FileSystemOperationTest;
37 39
38 // This class is designed to serve one-time file system operation per instance. 40 // This class is designed to serve one-time file system operation per instance.
39 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, 41 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists,
40 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of 42 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of
41 // this object and it should be called no more than once. 43 // this object and it should be called no more than once.
42 // This class is self-destructed and an instance automatically gets deleted 44 // This class is self-destructed and an instance automatically gets deleted
43 // when its operation is finished. 45 // when its operation is finished.
44 class FileSystemOperation { 46 class FileSystemOperation {
45 public: 47 public:
46 // |dispatcher| will be owned by this class. 48 // |dispatcher| will be owned by this class.
49 // |file_system_file_util| is optional; if supplied, it will not be deleted by
50 // the class. It's expecting a pointer to a singleton.
47 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, 51 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher,
48 scoped_refptr<base::MessageLoopProxy> proxy, 52 scoped_refptr<base::MessageLoopProxy> proxy,
49 FileSystemContext* file_system_context); 53 FileSystemContext* file_system_context,
54 FileSystemFileUtil* file_system_file_util);
50 virtual ~FileSystemOperation(); 55 virtual ~FileSystemOperation();
51 56
52 void OpenFileSystem(const GURL& origin_url, 57 void OpenFileSystem(const GURL& origin_url,
53 fileapi::FileSystemType type, 58 fileapi::FileSystemType type,
54 bool create); 59 bool create);
55 void CreateFile(const FilePath& path, 60 void CreateFile(const FilePath& path,
56 bool exclusive); 61 bool exclusive);
57 void CreateDirectory(const FilePath& path, 62 void CreateDirectory(const FilePath& path,
58 bool exclusive, 63 bool exclusive,
59 bool recursive); 64 bool recursive);
(...skipping 14 matching lines...) Expand all
74 void TouchFile(const FilePath& path, 79 void TouchFile(const FilePath& path,
75 const base::Time& last_access_time, 80 const base::Time& last_access_time,
76 const base::Time& last_modified_time); 81 const base::Time& last_modified_time);
77 82
78 // Try to cancel the current operation [we support cancelling write or 83 // Try to cancel the current operation [we support cancelling write or
79 // truncate only]. Report failure for the current operation, then tell the 84 // truncate only]. Report failure for the current operation, then tell the
80 // passed-in operation to report success. 85 // passed-in operation to report success.
81 void Cancel(FileSystemOperation* cancel_operation); 86 void Cancel(FileSystemOperation* cancel_operation);
82 87
83 private: 88 private:
89 FileSystemContext* file_system_context() const {
90 return file_system_operation_context_.file_system_context();
91 }
92
93 FileSystemOperationContext* file_system_operation_context() {
94 return &file_system_operation_context_;
95 }
96 friend class FileSystemOperationTest;
97
84 // A callback used for OpenFileSystem. 98 // A callback used for OpenFileSystem.
85 void DidGetRootPath(bool success, 99 void DidGetRootPath(bool success,
86 const FilePath& path, 100 const FilePath& path,
87 const std::string& name); 101 const std::string& name);
88 102
89 // Callback for CreateFile for |exclusive|=true cases. 103 // Callback for CreateFile for |exclusive|=true cases.
90 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, 104 void DidEnsureFileExistsExclusive(base::PlatformFileError rv,
91 bool created); 105 bool created);
92 106
93 // Callback for CreateFile for |exclusive|=false cases. 107 // Callback for CreateFile for |exclusive|=false cases.
(...skipping 17 matching lines...) Expand all
111 int64 bytes, 125 int64 bytes,
112 bool complete); 126 bool complete);
113 void DidTouchFile(base::PlatformFileError rv); 127 void DidTouchFile(base::PlatformFileError rv);
114 128
115 // Helper for Write(). 129 // Helper for Write().
116 void OnFileOpenedForWrite( 130 void OnFileOpenedForWrite(
117 base::PlatformFileError rv, 131 base::PlatformFileError rv,
118 base::PassPlatformFile file, 132 base::PassPlatformFile file,
119 bool created); 133 bool created);
120 134
121 // Checks the validity of a given |path| for reading. 135 // Checks the validity of a given |path| for reading, and cracks the path into
136 // root URL and virtual path components.
122 // Returns true if the given |path| is a valid FileSystem path. 137 // Returns true if the given |path| is a valid FileSystem path.
123 // Otherwise it calls dispatcher's DidFail method with 138 // Otherwise it calls dispatcher's DidFail method with
124 // PLATFORM_FILE_ERROR_SECURITY and returns false. 139 // PLATFORM_FILE_ERROR_SECURITY and returns false.
125 // (Note: this doesn't delete this when it calls DidFail and returns false; 140 // (Note: this doesn't delete this when it calls DidFail and returns false;
126 // it's the caller's responsibility.) 141 // it's the caller's responsibility.)
127 bool VerifyFileSystemPathForRead(const FilePath& path); 142 bool VerifyFileSystemPathForRead(const FilePath& path,
143 GURL* root_url,
144 FileSystemType* type,
145 FilePath* virtual_path);
128 146
129 // Checks the validity of a given |path| for writing. 147 // Checks the validity of a given |path| for writing, and cracks the path into
148 // root URL and virtual path components.
130 // Returns true if the given |path| is a valid FileSystem path, and 149 // Returns true if the given |path| is a valid FileSystem path, and
131 // its origin embedded in the path has the right to write. 150 // its origin embedded in the path has the right to write.
132 // Otherwise it fires dispatcher's DidFail method with 151 // Otherwise it fires dispatcher's DidFail method with
133 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, 152 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing,
134 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to 153 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to
135 // write to the storage. 154 // write to the storage.
136 // In either case it returns false after firing DidFail. 155 // In either case it returns false after firing DidFail.
137 // If |create| flag is true this also checks if the |path| contains 156 // If |create| flag is true this also checks if the |path| contains
138 // any restricted names and chars. If it does, the call fires dispatcher's 157 // any restricted names and chars. If it does, the call fires dispatcher's
139 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. 158 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false.
140 // (Note: this doesn't delete this when it calls DidFail and returns false; 159 // (Note: this doesn't delete this when it calls DidFail and returns false;
141 // it's the caller's responsibility.) 160 // it's the caller's responsibility.)
142 bool VerifyFileSystemPathForWrite(const FilePath& path, 161 bool VerifyFileSystemPathForWrite(const FilePath& path,
143 bool create); 162 bool create,
163 GURL* root_url,
164 FileSystemType* type,
165 FilePath* virtual_path);
144 166
145 #ifndef NDEBUG 167 #ifndef NDEBUG
146 enum OperationType { 168 enum OperationType {
147 kOperationNone, 169 kOperationNone,
148 kOperationOpenFileSystem, 170 kOperationOpenFileSystem,
149 kOperationCreateFile, 171 kOperationCreateFile,
150 kOperationCreateDirectory, 172 kOperationCreateDirectory,
151 kOperationCopy, 173 kOperationCopy,
152 kOperationMove, 174 kOperationMove,
153 kOperationDirectoryExists, 175 kOperationDirectoryExists,
154 kOperationFileExists, 176 kOperationFileExists,
155 kOperationGetMetadata, 177 kOperationGetMetadata,
156 kOperationReadDirectory, 178 kOperationReadDirectory,
157 kOperationRemove, 179 kOperationRemove,
158 kOperationWrite, 180 kOperationWrite,
159 kOperationTruncate, 181 kOperationTruncate,
160 kOperationTouchFile, 182 kOperationTouchFile,
161 kOperationCancel, 183 kOperationCancel,
162 }; 184 };
163 185
164 // A flag to make sure we call operation only once per instance. 186 // A flag to make sure we call operation only once per instance.
165 OperationType pending_operation_; 187 OperationType pending_operation_;
166 #endif 188 #endif
167 189
168 // Proxy for calling file_util_proxy methods. 190 // Proxy for calling file_util_proxy methods.
169 scoped_refptr<base::MessageLoopProxy> proxy_; 191 scoped_refptr<base::MessageLoopProxy> proxy_;
170 192
171 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; 193 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_;
172 194
173 scoped_refptr<FileSystemContext> file_system_context_;
174 FileSystemOperationContext file_system_operation_context_; 195 FileSystemOperationContext file_system_operation_context_;
175 196
176 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; 197 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_;
177 198
178 // These are all used only by Write(). 199 // These are all used only by Write().
179 friend class FileWriterDelegate; 200 friend class FileWriterDelegate;
180 scoped_ptr<FileWriterDelegate> file_writer_delegate_; 201 scoped_ptr<FileWriterDelegate> file_writer_delegate_;
181 scoped_ptr<net::URLRequest> blob_request_; 202 scoped_ptr<net::URLRequest> blob_request_;
182 scoped_ptr<FileSystemOperation> cancel_operation_; 203 scoped_ptr<FileSystemOperation> cancel_operation_;
183 204
184 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); 205 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation);
185 }; 206 };
186 207
187 } // namespace fileapi 208 } // namespace fileapi
188 209
189 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 210 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_mount_point_provider.h ('k') | webkit/fileapi/file_system_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698