OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ |
6 #define CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ |
7 | 7 |
| 8 #include <set> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/file_util.h" | |
10 #include "base/id_map.h" | 11 #include "base/id_map.h" |
11 #include "base/nullable_string16.h" | |
12 #include "base/process.h" | 12 #include "base/process.h" |
13 #include "base/platform_file.h" | |
14 #include "base/scoped_callback_factory.h" | |
15 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
16 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
17 #include "webkit/fileapi/file_system_operation.h" | |
18 #include "webkit/fileapi/file_system_types.h" | 15 #include "webkit/fileapi/file_system_types.h" |
19 | 16 |
20 namespace base { | 17 namespace base { |
21 class Time; | 18 class Time; |
22 } | 19 } |
23 | 20 |
24 class ChromeURLRequestContext; | 21 class ChromeURLRequestContext; |
25 class BrowserFileSystemContext; | 22 class BrowserFileSystemContext; |
| 23 class FilePath; |
26 class GURL; | 24 class GURL; |
27 class HostContentSettingsMap; | 25 class HostContentSettingsMap; |
28 class Profile; | 26 class Profile; |
29 class Receiver; | 27 class Receiver; |
30 class ResourceMessageFilter; | 28 class ResourceMessageFilter; |
| 29 class URLRequestContext; |
31 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
32 | 31 |
| 32 namespace fileapi { |
| 33 class SandboxedFileSystemOperation; |
| 34 } |
| 35 |
33 class FileSystemDispatcherHost | 36 class FileSystemDispatcherHost |
34 : public base::RefCountedThreadSafe<FileSystemDispatcherHost> { | 37 : public base::RefCountedThreadSafe<FileSystemDispatcherHost> { |
35 public: | 38 public: |
36 // Used by the renderer. | 39 // Used by the renderer. |
37 FileSystemDispatcherHost(IPC::Message::Sender* sender, | 40 FileSystemDispatcherHost(IPC::Message::Sender* sender, |
38 Profile* profile); | 41 Profile* profile); |
39 // Used by the worker, since it has the context handy already. | 42 // Used by the worker, since it has the context handy already. |
40 FileSystemDispatcherHost(IPC::Message::Sender* sender, | 43 FileSystemDispatcherHost(IPC::Message::Sender* sender, |
41 ChromeURLRequestContext* context); | 44 ChromeURLRequestContext* context); |
42 ~FileSystemDispatcherHost(); | 45 ~FileSystemDispatcherHost(); |
(...skipping 29 matching lines...) Expand all Loading... |
72 void OnTruncate(int request_id, const FilePath& path, int64 length); | 75 void OnTruncate(int request_id, const FilePath& path, int64 length); |
73 void OnTouchFile(int request_id, | 76 void OnTouchFile(int request_id, |
74 const FilePath& path, | 77 const FilePath& path, |
75 const base::Time& last_access_time, | 78 const base::Time& last_access_time, |
76 const base::Time& last_modified_time); | 79 const base::Time& last_modified_time); |
77 void OnCancel(int request_id, int request_to_cancel); | 80 void OnCancel(int request_id, int request_to_cancel); |
78 void Send(IPC::Message* message); | 81 void Send(IPC::Message* message); |
79 void RemoveCompletedOperation(int request_id); | 82 void RemoveCompletedOperation(int request_id); |
80 | 83 |
81 private: | 84 private: |
82 // Creates a new FileSystemOperation. | 85 // Creates a new SandboxedFileSystemOperation. |
83 fileapi::FileSystemOperation* GetNewOperation(int request_id); | 86 fileapi::SandboxedFileSystemOperation* GetNewOperation(int request_id); |
84 | |
85 // Checks the validity of a given |path| for reading. | |
86 // Returns true if the given |path| is a valid FileSystem path. | |
87 // Otherwise it sends back PLATFORM_FILE_ERROR_SECURITY to the | |
88 // dispatcher and returns false. | |
89 bool VerifyFileSystemPathForRead(const FilePath& path, int request_id); | |
90 | |
91 // Checks the validity of a given |path| for writing. | |
92 // Returns true if the given |path| is a valid FileSystem path, and | |
93 // its origin embedded in the path has the right to write as much as | |
94 // the given |growth|. | |
95 // Otherwise it sends back PLATFORM_FILE_ERROR_SECURITY if the path | |
96 // is not valid for writing, or sends back PLATFORM_FILE_ERROR_NO_SPACE | |
97 // if the origin is not allowed to increase the usage by |growth|. | |
98 // If |create| flag is true this also checks if the |path| contains | |
99 // any restricted names and chars. If it does, the call sends back | |
100 // PLATFORM_FILE_ERROR_SECURITY to the dispatcher. | |
101 bool VerifyFileSystemPathForWrite(const FilePath& path, | |
102 int request_id, | |
103 bool create, | |
104 int64 growth); | |
105 | |
106 class OpenFileSystemTask; | |
107 | |
108 // Checks if a given |path| does not contain any restricted names/chars | |
109 // for new files. Returns true if the given |path| is safe. | |
110 // Otherwise it sends back a security error code to the dispatcher and | |
111 // returns false. | |
112 bool CheckIfFilePathIsSafe(const FilePath& path, int request_id); | |
113 | 87 |
114 // The sender to be used for sending out IPC messages. | 88 // The sender to be used for sending out IPC messages. |
115 IPC::Message::Sender* message_sender_; | 89 IPC::Message::Sender* message_sender_; |
116 | 90 |
117 // The handle of this process. | 91 // The handle of this process. |
118 base::ProcessHandle process_handle_; | 92 base::ProcessHandle process_handle_; |
119 | 93 |
120 bool shutdown_; | 94 bool shutdown_; |
121 | 95 |
122 scoped_refptr<BrowserFileSystemContext> context_; | 96 scoped_refptr<BrowserFileSystemContext> context_; |
123 | 97 |
124 // Used to look up permissions. | 98 // Used to look up permissions. |
125 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 99 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
126 | 100 |
127 // Keeps ongoing file system operations. | 101 // Keeps ongoing file system operations. |
128 typedef IDMap<fileapi::FileSystemOperation, IDMapOwnPointer> OperationsMap; | 102 typedef IDMap<fileapi::SandboxedFileSystemOperation, IDMapOwnPointer> |
| 103 OperationsMap; |
129 OperationsMap operations_; | 104 OperationsMap operations_; |
130 | 105 |
131 // This holds the URLRequestContextGetter until Init() can be called from the | 106 // This holds the URLRequestContextGetter until Init() can be called from the |
132 // IO thread, which will extract the URLRequestContext from it. | 107 // IO thread, which will extract the URLRequestContext from it. |
133 scoped_refptr<URLRequestContextGetter> request_context_getter_; | 108 scoped_refptr<URLRequestContextGetter> request_context_getter_; |
134 scoped_refptr<URLRequestContext> request_context_; | 109 scoped_refptr<URLRequestContext> request_context_; |
135 | 110 |
136 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcherHost); | 111 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcherHost); |
137 }; | 112 }; |
138 | 113 |
139 #endif // CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ | 114 #endif // CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ |
OLD | NEW |