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

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

Issue 4054003: FileSystem code cleanup 2nd cut - introduce SandboxedFileSystemOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 10 years, 1 month 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_FILEAPI_SANDBOXED_FILE_SYSTEM_OPERATION_H_
6 #define WEBKIT_FILEAPI_SANDBOXED_FILE_SYSTEM_OPERATION_H_
7
8 #include "base/scoped_callback_factory.h"
9 #include "webkit/fileapi/file_system_operation.h"
10 #include "webkit/fileapi/file_system_types.h"
11
12 namespace fileapi {
13
14 class SandboxedFileSystemContext;
15
16 // This class provides a 'sandboxed' access to the underlying file system,
17 // that is:
18 // 1. provides OpenFileSystem method that returns a (hidden) root path
19 // that is given by |file_system_context|.
20 // 2. enforces quota and file names/paths restrictions on each operation
21 // via |file_system_context|.
22 class SandboxedFileSystemOperation : public FileSystemOperation {
23 public:
24 // This class doesn't hold a reference or ownership of |file_system_context|.
25 // It is the caller's responsibility to keep the pointer alive *until*
26 // it calls any of the operation methods. The |file_system_context| won't be
27 // used in the callback path and can be deleted after the operation is
28 // made (e.g. after one of CreateFile, CreateDirectory, Copy, etc is called).
29 SandboxedFileSystemOperation(FileSystemCallbackDispatcher* dispatcher,
30 scoped_refptr<base::MessageLoopProxy> proxy,
31 SandboxedFileSystemContext* file_system_context);
32
33 void OpenFileSystem(const GURL& origin_url,
34 fileapi::FileSystemType type,
35 bool create);
36
37 // FileSystemOperation's methods.
38 virtual void CreateFile(const FilePath& path,
39 bool exclusive);
40 virtual void CreateDirectory(const FilePath& path,
41 bool exclusive,
42 bool recursive);
43 virtual void Copy(const FilePath& src_path,
44 const FilePath& dest_path);
45 virtual void Move(const FilePath& src_path,
46 const FilePath& dest_path);
47 virtual void DirectoryExists(const FilePath& path);
48 virtual void FileExists(const FilePath& path);
49 virtual void GetMetadata(const FilePath& path);
50 virtual void ReadDirectory(const FilePath& path);
51 virtual void Remove(const FilePath& path, bool recursive);
52 virtual void Write(
53 scoped_refptr<URLRequestContext> url_request_context,
54 const FilePath& path, const GURL& blob_url, int64 offset);
55 virtual void Truncate(const FilePath& path, int64 length);
56 virtual void TouchFile(const FilePath& path,
57 const base::Time& last_access_time,
58 const base::Time& last_modified_time);
59
60 private:
61 enum SandboxedFileSystemOperationType {
62 kOperationOpenFileSystem = 100,
63 };
64
65 // A callback used for OpenFileSystem.
66 void DidGetRootPath(bool success,
67 const FilePath& path,
68 const std::string& name);
69
70 // Checks the validity of a given |path| for reading.
71 // Returns true if the given |path| is a valid FileSystem path.
72 // Otherwise it calls dispatcher's DidFail method with
73 // PLATFORM_FILE_ERROR_SECURITY and returns false.
74 bool VerifyFileSystemPathForRead(const FilePath& path);
75
76 // Checks the validity of a given |path| for writing.
77 // Returns true if the given |path| is a valid FileSystem path, and
78 // its origin embedded in the path has the right to write as much as
79 // the given |growth|.
80 // Otherwise it fires dispatcher's DidFail method with
81 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing,
82 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to
83 // increase the usage by |growth|.
84 // In either case it returns false after firing DidFail.
85 // If |create| flag is true this also checks if the |path| contains
86 // any restricted names and chars. If it does, the call fires dispatcher's
87 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false.
88 bool VerifyFileSystemPathForWrite(const FilePath& path,
89 bool create,
90 int64 growth);
91
92 // Checks if a given |path| does not contain any restricted names/chars
93 // for new files. Returns true if the given |path| is safe.
94 // Otherwise it fires dispatcher's DidFail method with
95 // PLATFORM_FILE_ERROR_SECURITY and returns false.
96 bool CheckIfFilePathIsSafe(const FilePath& path);
97
98 // Not owned. See the comment at the constructor.
99 SandboxedFileSystemContext* file_system_context_;
100
101 base::ScopedCallbackFactory<SandboxedFileSystemOperation> callback_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(SandboxedFileSystemOperation);
104 };
105
106 } // namespace fileapi
107
108 #endif // WEBKIT_FILEAPI_SANDBOXED_FILE_SYSTEM_OPERATION_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/sandboxed_file_system_context.cc ('k') | webkit/fileapi/sandboxed_file_system_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698