| OLD | NEW |
| 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 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 return root; | 104 return root; |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // anonymous namespace | 107 } // anonymous namespace |
| 108 | 108 |
| 109 namespace fileapi { | 109 namespace fileapi { |
| 110 | 110 |
| 111 const FilePath::CharType SandboxMountPointProvider::kFileSystemDirectory[] = | 111 const FilePath::CharType SandboxMountPointProvider::kFileSystemDirectory[] = |
| 112 FILE_PATH_LITERAL("FileSystem"); | 112 FILE_PATH_LITERAL("FileSystem"); |
| 113 | 113 |
| 114 const char SandboxMountPointProvider::kPersistentName[] = "Persistent"; | |
| 115 const char SandboxMountPointProvider::kTemporaryName[] = "Temporary"; | |
| 116 | |
| 117 SandboxMountPointProvider::SandboxMountPointProvider( | 114 SandboxMountPointProvider::SandboxMountPointProvider( |
| 118 FileSystemPathManager* path_manager, | 115 FileSystemPathManager* path_manager, |
| 119 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 116 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 120 const FilePath& profile_path) | 117 const FilePath& profile_path) |
| 121 : path_manager_(path_manager), | 118 : path_manager_(path_manager), |
| 122 file_message_loop_(file_message_loop), | 119 file_message_loop_(file_message_loop), |
| 123 base_path_(profile_path.Append(kFileSystemDirectory)) { | 120 base_path_(profile_path.Append(kFileSystemDirectory)) { |
| 124 } | 121 } |
| 125 | 122 |
| 126 SandboxMountPointProvider::~SandboxMountPointProvider() { | 123 SandboxMountPointProvider::~SandboxMountPointProvider() { |
| 127 } | 124 } |
| 128 | 125 |
| 129 bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url) { | 126 bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
| 127 const FilePath& unused) { |
| 130 // We essentially depend on quota to do our access controls. | 128 // We essentially depend on quota to do our access controls. |
| 131 return path_manager_->IsAllowedScheme(origin_url); | 129 return path_manager_->IsAllowedScheme(origin_url); |
| 132 } | 130 } |
| 133 | 131 |
| 134 class SandboxMountPointProvider::GetFileSystemRootPathTask | 132 class SandboxMountPointProvider::GetFileSystemRootPathTask |
| 135 : public base::RefCountedThreadSafe< | 133 : public base::RefCountedThreadSafe< |
| 136 SandboxMountPointProvider::GetFileSystemRootPathTask> { | 134 SandboxMountPointProvider::GetFileSystemRootPathTask> { |
| 137 public: | 135 public: |
| 138 GetFileSystemRootPathTask( | 136 GetFileSystemRootPathTask( |
| 139 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 137 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 202 |
| 205 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { | 203 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { |
| 206 if (filename.value().find(kRestrictedChars[i]) != | 204 if (filename.value().find(kRestrictedChars[i]) != |
| 207 FilePath::StringType::npos) | 205 FilePath::StringType::npos) |
| 208 return true; | 206 return true; |
| 209 } | 207 } |
| 210 | 208 |
| 211 return false; | 209 return false; |
| 212 } | 210 } |
| 213 | 211 |
| 212 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { |
| 213 NOTREACHED(); |
| 214 // TODO(ericu): Implement this method and check for access permissions as |
| 215 // fileBrowserPrivate extension API does. We currently have another mechanism, |
| 216 // but we should switch over. |
| 217 return std::vector<FilePath>(); |
| 218 } |
| 219 |
| 214 void SandboxMountPointProvider::GetFileSystemRootPath( | 220 void SandboxMountPointProvider::GetFileSystemRootPath( |
| 215 const GURL& origin_url, fileapi::FileSystemType type, | 221 const GURL& origin_url, fileapi::FileSystemType type, |
| 216 bool create, FileSystemPathManager::GetRootPathCallback* callback_ptr) { | 222 bool create, FileSystemPathManager::GetRootPathCallback* callback_ptr) { |
| 217 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback(callback_ptr); | 223 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback(callback_ptr); |
| 218 std::string name; | 224 std::string name; |
| 219 FilePath origin_base_path; | 225 FilePath origin_base_path; |
| 220 | 226 |
| 221 if (!GetOriginBasePathAndName(origin_url, &origin_base_path, type, &name)) { | 227 if (!GetOriginBasePathAndName(origin_url, &origin_base_path, type, &name)) { |
| 222 callback->Run(false, FilePath(), std::string()); | 228 callback->Run(false, FilePath(), std::string()); |
| 223 return; | 229 return; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 file_util::FileEnumerator::DIRECTORIES) { | 277 file_util::FileEnumerator::DIRECTORIES) { |
| 272 } | 278 } |
| 273 | 279 |
| 274 std::string SandboxMountPointProvider::OriginEnumerator::Next() { | 280 std::string SandboxMountPointProvider::OriginEnumerator::Next() { |
| 275 current_ = enumerator_.Next(); | 281 current_ = enumerator_.Next(); |
| 276 return FilePathStringToASCII(current_.BaseName().value()); | 282 return FilePathStringToASCII(current_.BaseName().value()); |
| 277 } | 283 } |
| 278 | 284 |
| 279 bool SandboxMountPointProvider::OriginEnumerator::HasTemporary() { | 285 bool SandboxMountPointProvider::OriginEnumerator::HasTemporary() { |
| 280 return !current_.empty() && file_util::DirectoryExists(current_.AppendASCII( | 286 return !current_.empty() && file_util::DirectoryExists(current_.AppendASCII( |
| 281 SandboxMountPointProvider::kTemporaryName)); | 287 fileapi::kTemporaryName)); |
| 282 } | 288 } |
| 283 | 289 |
| 284 bool SandboxMountPointProvider::OriginEnumerator::HasPersistent() { | 290 bool SandboxMountPointProvider::OriginEnumerator::HasPersistent() { |
| 285 return !current_.empty() && file_util::DirectoryExists(current_.AppendASCII( | 291 return !current_.empty() && file_util::DirectoryExists(current_.AppendASCII( |
| 286 SandboxMountPointProvider::kPersistentName)); | 292 fileapi::kPersistentName)); |
| 287 } | 293 } |
| 288 | 294 |
| 289 bool SandboxMountPointProvider::GetOriginBasePathAndName( | 295 bool SandboxMountPointProvider::GetOriginBasePathAndName( |
| 290 const GURL& origin_url, | 296 const GURL& origin_url, |
| 291 FilePath* origin_base_path, | 297 FilePath* origin_base_path, |
| 292 FileSystemType type, | 298 FileSystemType type, |
| 293 std::string* name) { | 299 std::string* name) { |
| 294 | 300 |
| 295 if (path_manager_->is_incognito()) | 301 if (path_manager_->is_incognito()) |
| 296 // TODO(kinuko): return an isolated temporary directory. | 302 // TODO(kinuko): return an isolated temporary directory. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 307 | 313 |
| 308 std::string type_string = | 314 std::string type_string = |
| 309 FileSystemPathManager::GetFileSystemTypeString(type); | 315 FileSystemPathManager::GetFileSystemTypeString(type); |
| 310 DCHECK(!type_string.empty()); | 316 DCHECK(!type_string.empty()); |
| 311 if (name) | 317 if (name) |
| 312 *name = origin_identifier + ":" + type_string; | 318 *name = origin_identifier + ":" + type_string; |
| 313 return true; | 319 return true; |
| 314 } | 320 } |
| 315 | 321 |
| 316 } // namespace fileapi | 322 } // namespace fileapi |
| OLD | NEW |