OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_ |
| 6 #define WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "googleurl/src/gurl.h" |
| 12 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 13 |
| 14 class GURL; |
| 15 |
| 16 namespace base { |
| 17 class MessageLoopProxy; |
| 18 } |
| 19 |
| 20 namespace fileapi { |
| 21 |
| 22 class SandboxMountPointProvider : public FileSystemMountPointProvider { |
| 23 public: |
| 24 |
| 25 SandboxMountPointProvider( |
| 26 FileSystemPathManager* path_manager, |
| 27 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 28 const FilePath& profile_path); |
| 29 |
| 30 // Checks if mount point access is allowed from |origin_url|. |
| 31 virtual bool IsAccessAllowed(const GURL& origin_url); |
| 32 |
| 33 // Retrieves the root path for the given |origin_url| and |type|, and |
| 34 // calls the given |callback| with the root path and name. |
| 35 // If |create| is true this also creates the directory if it doesn't exist. |
| 36 void GetFileSystemRootPath( |
| 37 const GURL& origin_url, |
| 38 FileSystemType type, |
| 39 bool create, |
| 40 FileSystemPathManager::GetRootPathCallback* callback); |
| 41 |
| 42 // Like GetFileSystemRootPath, but synchronous, and can be called only while |
| 43 // running on the file thread. |
| 44 FilePath GetFileSystemRootPathOnFileThread( |
| 45 const GURL& origin_url, |
| 46 FileSystemType type, |
| 47 bool create); |
| 48 |
| 49 // The FileSystem directory name. |
| 50 static const FilePath::CharType kFileSystemDirectory[]; |
| 51 |
| 52 static const char kPersistentName[]; |
| 53 static const char kTemporaryName[]; |
| 54 |
| 55 const FilePath& base_path() const { |
| 56 return base_path_; |
| 57 } |
| 58 |
| 59 // Checks if a given |name| contains any restricted names/chars in it. |
| 60 virtual bool IsRestrictedFileName(const FilePath& filename) const; |
| 61 |
| 62 // Returns the origin identifier string, which is used as a part of the |
| 63 // sandboxed path component, for the given |url|. |
| 64 static std::string GetOriginIdentifierFromURL(const GURL& url); |
| 65 |
| 66 // Gets a base directory path of the sandboxed filesystem that is |
| 67 // specified by |origin_identifier| and |type|. |
| 68 // |base_path| must be pointing the FileSystem's data directory |
| 69 // under the profile directory, i.e. <profile_dir>/kFileSystemDirectory. |
| 70 // Returns an empty path if any of the given parameters are invalid. |
| 71 // Returned directory path does not contain 'unique' part, therefore |
| 72 // it is not an actual root path for the filesystem. |
| 73 static FilePath GetFileSystemBaseDirectoryForOriginAndType( |
| 74 const FilePath& base_path, |
| 75 const std::string& origin_identifier, |
| 76 fileapi::FileSystemType type); |
| 77 |
| 78 // Enumerates origins under the given |base_path|. |
| 79 // This must be used on the FILE thread. |
| 80 class OriginEnumerator { |
| 81 public: |
| 82 explicit OriginEnumerator(const FilePath& base_path); |
| 83 |
| 84 // Returns the next origin identifier. Returns empty if there are no |
| 85 // more origins. |
| 86 std::string Next(); |
| 87 |
| 88 bool HasTemporary(); |
| 89 bool HasPersistent(); |
| 90 const FilePath& path() { return current_; } |
| 91 |
| 92 private: |
| 93 file_util::FileEnumerator enumerator_; |
| 94 FilePath current_; |
| 95 }; |
| 96 |
| 97 private: |
| 98 bool GetOriginBasePathAndName( |
| 99 const GURL& origin_url, |
| 100 FilePath* base_path, |
| 101 FileSystemType type, |
| 102 std::string* name); |
| 103 |
| 104 class GetFileSystemRootPathTask; |
| 105 |
| 106 // The path_manager_ isn't owned by this instance; this instance is owned by |
| 107 // the path_manager_, and they have the same lifetime. |
| 108 FileSystemPathManager* path_manager_; |
| 109 |
| 110 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
| 111 |
| 112 const FilePath base_path_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(SandboxMountPointProvider); |
| 115 }; |
| 116 |
| 117 } // namespace fileapi |
| 118 |
| 119 #endif // WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_ |
| 120 |
OLD | NEW |