| 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 #include "chrome/browser/file_system/file_system_host_context.h" | 5 #include "chrome/browser/file_system/file_system_host_context.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" | |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 14 | 14 |
| 15 const FilePath::CharType FileSystemHostContext::kFileSystemDirectory[] = | 15 const FilePath::CharType FileSystemHostContext::kFileSystemDirectory[] = |
| 16 FILE_PATH_LITERAL("FileSystem"); | 16 FILE_PATH_LITERAL("FileSystem"); |
| 17 | 17 |
| 18 const char FileSystemHostContext::kPersistentName[] = "Persistent"; | 18 const char FileSystemHostContext::kPersistentName[] = "Persistent"; |
| 19 const char FileSystemHostContext::kTemporaryName[] = "Temporary"; | 19 const char FileSystemHostContext::kTemporaryName[] = "Temporary"; |
| 20 | 20 |
| 21 FileSystemHostContext::FileSystemHostContext( | 21 FileSystemHostContext::FileSystemHostContext( |
| 22 const FilePath& data_path, bool is_incognito) | 22 const FilePath& data_path, bool is_incognito) |
| 23 : base_path_(data_path.Append(kFileSystemDirectory)), | 23 : base_path_(data_path.Append(kFileSystemDirectory)), |
| 24 is_incognito_(is_incognito) { | 24 is_incognito_(is_incognito) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool FileSystemHostContext::GetFileSystemRootPath( | 27 bool FileSystemHostContext::GetFileSystemRootPath( |
| 28 const GURL& origin_url, WebKit::WebFileSystem::Type type, | 28 const GURL& origin_url, fileapi::FileSystemType type, |
| 29 FilePath* root_path, std::string* name) const { | 29 FilePath* root_path, std::string* name) const { |
| 30 // TODO(kinuko): should return an isolated temporary file system space. | 30 // TODO(kinuko): should return an isolated temporary file system space. |
| 31 if (is_incognito_) | 31 if (is_incognito_) |
| 32 return false; | 32 return false; |
| 33 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); | 33 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); |
| 34 switch (type) { | 34 switch (type) { |
| 35 case WebKit::WebFileSystem::TypeTemporary: | 35 case fileapi::kFileSystemTypeTemporary: |
| 36 if (root_path) | 36 if (root_path) |
| 37 *root_path = base_path_.AppendASCII(storage_identifier) | 37 *root_path = base_path_.AppendASCII(storage_identifier) |
| 38 .AppendASCII(kTemporaryName); | 38 .AppendASCII(kTemporaryName); |
| 39 if (name) | 39 if (name) |
| 40 *name = storage_identifier + ":" + kTemporaryName; | 40 *name = storage_identifier + ":" + kTemporaryName; |
| 41 return true; | 41 return true; |
| 42 case WebKit::WebFileSystem::TypePersistent: | 42 case fileapi::kFileSystemTypePersistent: |
| 43 if (root_path) | 43 if (root_path) |
| 44 *root_path = base_path_.AppendASCII(storage_identifier) | 44 *root_path = base_path_.AppendASCII(storage_identifier) |
| 45 .AppendASCII(kPersistentName); | 45 .AppendASCII(kPersistentName); |
| 46 if (name) | 46 if (name) |
| 47 *name = storage_identifier + ":" + kPersistentName; | 47 *name = storage_identifier + ":" + kPersistentName; |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 LOG(WARNING) << "Unknown filesystem type is requested:" << type; | 50 LOG(WARNING) << "Unknown filesystem type is requested:" << type; |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool FileSystemHostContext::CheckValidFileSystemPath( | 54 bool FileSystemHostContext::CheckValidFileSystemPath( |
| 55 const FilePath& path) const { | 55 const FilePath& path) const { |
| 56 // Any paths that includes parent references are considered invalid. | 56 // Any paths that includes parent references are considered invalid. |
| 57 return !path.ReferencesParent() && base_path_.IsParent(path); | 57 return !path.ReferencesParent() && base_path_.IsParent(path); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::string FileSystemHostContext::GetStorageIdentifierFromURL( | 60 std::string FileSystemHostContext::GetStorageIdentifierFromURL( |
| 61 const GURL& url) { | 61 const GURL& url) { |
| 62 WebKit::WebSecurityOrigin web_security_origin = | 62 WebKit::WebSecurityOrigin web_security_origin = |
| 63 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); | 63 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); |
| 64 return web_security_origin.databaseIdentifier().utf8(); | 64 return web_security_origin.databaseIdentifier().utf8(); |
| 65 } | 65 } |
| 66 |
| 67 COMPILE_ASSERT(int(WebKit::WebFileSystem::TypeTemporary) == \ |
| 68 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
| 69 COMPILE_ASSERT(int(WebKit::WebFileSystem::TypePersistent) == \ |
| 70 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
| OLD | NEW |