Chromium Code Reviews| 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 WEBKIT_FILEAPI_FILE_SYSTEM_PATH_MANAGER_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_PATH_MANAGER_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_PATH_MANAGER_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_PATH_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "webkit/fileapi/file_system_types.h" | 12 #include "webkit/fileapi/file_system_types.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class MessageLoopProxy; | 17 class MessageLoopProxy; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace fileapi { | 20 namespace fileapi { |
| 21 | 21 |
| 22 class SandboxMountPointProvider; | |
| 23 | |
| 22 // TODO(kinuko): Probably this module must be called FileSystemPathUtil | 24 // TODO(kinuko): Probably this module must be called FileSystemPathUtil |
| 23 // or something similar. | 25 // or something similar. |
| 24 | 26 |
| 25 // An interface to construct or crack sandboxed filesystem paths. | 27 // An interface to construct or crack sandboxed filesystem paths. |
| 26 // Currently each sandboxed filesystem path looks like: | 28 // Currently each sandboxed filesystem path looks like: |
| 27 // | 29 // |
| 28 // <profile_dir>/FileSystem/<origin_identifier>/<type>/chrome-<unique>/... | 30 // <profile_dir>/FileSystem/<origin_identifier>/<type>/chrome-<unique>/... |
| 29 // | 31 // |
| 30 // <type> is either one of "Temporary" or "Persistent". | 32 // <type> is either one of "Temporary" or "Persistent". |
| 31 class FileSystemPathManager { | 33 class FileSystemPathManager { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 42 // If the request is accepted, |create| is specified for | 44 // If the request is accepted, |create| is specified for |
| 43 // GetFileSystemRootPath, and the root directory does not exist, it creates | 45 // GetFileSystemRootPath, and the root directory does not exist, it creates |
| 44 // a new one and calls back with success=true if the creation has succeeded. | 46 // a new one and calls back with success=true if the creation has succeeded. |
| 45 typedef Callback3<bool /* success */, | 47 typedef Callback3<bool /* success */, |
| 46 const FilePath& /* root_path */, | 48 const FilePath& /* root_path */, |
| 47 const std::string& /* name */>::Type GetRootPathCallback; | 49 const std::string& /* name */>::Type GetRootPathCallback; |
| 48 | 50 |
| 49 // Retrieves the root path for the given |origin_url| and |type|, and | 51 // Retrieves the root path for the given |origin_url| and |type|, and |
| 50 // calls the given |callback| with the root path and name. | 52 // calls the given |callback| with the root path and name. |
| 51 // If |create| is true this also creates the directory if it doesn't exist. | 53 // If |create| is true this also creates the directory if it doesn't exist. |
| 52 void GetFileSystemRootPath(const GURL& origin_url, | 54 virtual void GetFileSystemRootPath(const GURL& origin_url, |
| 53 fileapi::FileSystemType type, | 55 FileSystemType type, |
| 54 bool create, | 56 bool create, |
| 55 GetRootPathCallback* callback); | 57 FileSystemPathManager::GetRootPathCallback* |
| 58 callback); | |
| 56 | 59 |
| 60 // Like GetFileSystemRootPath, but synchronous, and can be called only while | |
| 61 // running on the file thread. | |
| 62 virtual FilePath GetFileSystemRootPathOnFileThread(const GURL& origin_url, | |
| 63 FileSystemType type, | |
| 64 bool create); | |
| 57 // Cracks the given |path|, retrieves the information embedded in the path | 65 // Cracks the given |path|, retrieves the information embedded in the path |
| 58 // and populates |origin_url|, |type| and |virtual_path|. The |virtual_path| | 66 // and populates |origin_url|, |type| and |virtual_path|. The |virtual_path| |
| 59 // is a sandboxed path in the file system, i.e. the relative path to the | 67 // is a sandboxed path in the file system, i.e. the relative path to the |
| 60 // filesystem root for the given domain and type. | 68 // filesystem root for the given domain and type. |
| 61 bool CrackFileSystemPath(const FilePath& path, | 69 bool CrackFileSystemPath(const FilePath& path, |
| 62 GURL* origin_url, | 70 GURL* origin_url, |
| 63 FileSystemType* type, | 71 FileSystemType* type, |
| 64 FilePath* virtual_path) const; | 72 FilePath* virtual_path) const; |
| 65 | 73 |
| 66 // Returns true if the given |url|'s scheme is allowed to access | 74 // Returns true if the given |url|'s scheme is allowed to access |
| 67 // filesystem. | 75 // filesystem. |
| 68 bool IsAllowedScheme(const GURL& url) const; | 76 bool IsAllowedScheme(const GURL& url) const; |
| 69 | 77 |
| 70 // The FileSystem directory name. | |
| 71 static const FilePath::CharType kFileSystemDirectory[]; | |
| 72 | |
| 73 static const char kPersistentName[]; | |
| 74 static const char kTemporaryName[]; | |
| 75 | |
| 76 const FilePath& base_path() const { | |
| 77 return base_path_; | |
| 78 } | |
| 79 | |
| 80 // Checks if a given |name| contains any restricted names/chars in it. | |
| 81 static bool IsRestrictedFileName(const FilePath& filename); | |
| 82 | |
| 83 // Returns the string for the given |type|. | 78 // Returns the string for the given |type|. |
| 84 // Returns an empty string if the |type| is invalid. | 79 // Returns an empty string if the |type| is invalid. |
| 85 static std::string GetFileSystemTypeString(fileapi::FileSystemType type); | 80 static std::string GetFileSystemTypeString(fileapi::FileSystemType type); |
| 86 | 81 |
| 87 // Returns the origin identifier string, which is used as a part of the | 82 // Checks if a given |name| contains any restricted names/chars in it. |
| 88 // sandboxed path component, for the given |url|. | 83 bool IsRestrictedFileName(FileSystemType type, |
| 89 static std::string GetOriginIdentifierFromURL(const GURL& url); | 84 const FilePath& filename); |
| 90 | 85 |
| 91 // Gets a base directory path of the sandboxed filesystem that is | 86 SandboxMountPointProvider* sandbox_provider() const { |
| 92 // specified by |origin_identifier| and |type|. | 87 return sandbox_provider_.get(); |
| 93 // |base_path| must be pointing the FileSystem's data directory | 88 } |
| 94 // under the profile directory, i.e. <profile_dir>/kFileSystemDirectory. | |
| 95 // Returns an empty path if any of the given parameters are invalid. | |
| 96 // Returned directory path does not contain 'unique' part, therefore | |
| 97 // it is not an actural root path for the filesystem. | |
| 98 static FilePath GetFileSystemBaseDirectoryForOriginAndType( | |
| 99 const FilePath& base_path, | |
| 100 const std::string& origin_identifier, | |
| 101 fileapi::FileSystemType type); | |
| 102 | 89 |
| 103 // Enumerates origins under the given |base_path|. | 90 bool is_incognito() const { |
| 104 // This must be used on the FILE thread. | 91 return is_incognito_; |
| 105 class OriginEnumerator { | 92 } |
| 106 public: | |
| 107 OriginEnumerator(const FilePath& base_path); | |
| 108 | |
| 109 // Returns the next origin identifier. Returns empty if there are no | |
| 110 // more origins. | |
| 111 std::string Next(); | |
| 112 | |
| 113 bool HasTemporary(); | |
| 114 bool HasPersistent(); | |
| 115 const FilePath& path() { return current_; } | |
| 116 | |
| 117 private: | |
| 118 file_util::FileEnumerator enumerator_; | |
| 119 FilePath current_; | |
| 120 }; | |
| 121 | 93 |
| 122 private: | 94 private: |
| 123 class GetFileSystemRootPathTask; | |
| 124 | |
| 125 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | |
| 126 | |
| 127 const FilePath base_path_; | |
| 128 const bool is_incognito_; | 95 const bool is_incognito_; |
| 129 const bool allow_file_access_from_files_; | 96 const bool allow_file_access_from_files_; |
| 97 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; | |
|
kinuko
2011/03/14 11:03:57
Is it supposed to be a pointer to FSMountPointProv
ericu
2011/03/15 02:43:11
Currently it's important that this be a SandboxMou
kinuko
2011/03/16 19:33:38
It's a bit blur how we should separate the roles b
| |
| 130 | 98 |
| 131 DISALLOW_COPY_AND_ASSIGN(FileSystemPathManager); | 99 DISALLOW_COPY_AND_ASSIGN(FileSystemPathManager); |
| 132 }; | 100 }; |
| 133 | 101 |
| 134 } // namespace fileapi | 102 } // namespace fileapi |
| 135 | 103 |
| 136 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_PATH_MANAGER_H_ | 104 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_PATH_MANAGER_H_ |
| OLD | NEW |