| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_system_url.h" | 5 #include "webkit/fileapi/file_system_url.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const struct { | 35 const struct { |
| 36 FileSystemType type; | 36 FileSystemType type; |
| 37 const char* dir; | 37 const char* dir; |
| 38 } kValidTypes[] = { | 38 } kValidTypes[] = { |
| 39 { kFileSystemTypePersistent, kPersistentDir }, | 39 { kFileSystemTypePersistent, kPersistentDir }, |
| 40 { kFileSystemTypeTemporary, kTemporaryDir }, | 40 { kFileSystemTypeTemporary, kTemporaryDir }, |
| 41 { kFileSystemTypeIsolated, kIsolatedDir }, | 41 { kFileSystemTypeIsolated, kIsolatedDir }, |
| 42 { kFileSystemTypeExternal, kExternalDir }, | 42 { kFileSystemTypeExternal, kExternalDir }, |
| 43 { kFileSystemTypeTest, kTestDir }, | 43 { kFileSystemTypeTest, kTestDir }, |
| 44 }; | 44 }; |
| 45 |
| 45 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { | 46 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { |
| 46 if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) { | 47 if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) { |
| 47 file_system_type = kValidTypes[i].type; | 48 file_system_type = kValidTypes[i].type; |
| 48 break; | 49 break; |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 if (file_system_type == kFileSystemTypeUnknown) | 53 if (file_system_type == kFileSystemTypeUnknown) |
| 53 return false; | 54 return false; |
| 54 | 55 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 if (file_path) | 74 if (file_path) |
| 74 *file_path = converted_path.NormalizePathSeparators(). | 75 *file_path = converted_path.NormalizePathSeparators(). |
| 75 StripTrailingSeparators(); | 76 StripTrailingSeparators(); |
| 76 | 77 |
| 77 return true; | 78 return true; |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace | 81 } // namespace |
| 81 | 82 |
| 82 FileSystemURL::FileSystemURL() | 83 FileSystemURL::FileSystemURL() |
| 83 : type_(kFileSystemTypeUnknown), | 84 : is_valid_(false), |
| 84 mount_type_(kFileSystemTypeUnknown), | 85 is_cracked_(false), |
| 85 is_valid_(false) {} | 86 type_(kFileSystemTypeUnknown), |
| 87 mount_type_(kFileSystemTypeUnknown) { |
| 88 } |
| 86 | 89 |
| 87 FileSystemURL::FileSystemURL(const GURL& url) | 90 FileSystemURL::FileSystemURL(const GURL& url) |
| 88 : type_(kFileSystemTypeUnknown) { | 91 : is_cracked_(false), |
| 89 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &virtual_path_); | 92 type_(kFileSystemTypeUnknown), |
| 90 MayCrackIsolatedPath(); | 93 mount_type_(kFileSystemTypeUnknown) { |
| 94 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &path_); |
| 95 mount_type_ = type_; |
| 96 virtual_path_ = path_; |
| 91 } | 97 } |
| 92 | 98 |
| 93 FileSystemURL::FileSystemURL( | 99 FileSystemURL::FileSystemURL(const GURL& origin, |
| 94 const GURL& origin, | 100 FileSystemType type, |
| 95 FileSystemType type, | 101 const FilePath& path) |
| 96 const FilePath& path) | 102 : is_valid_(true), |
| 97 : origin_(origin), | 103 is_cracked_(false), |
| 104 origin_(origin), |
| 98 type_(type), | 105 type_(type), |
| 99 virtual_path_(path.NormalizePathSeparators()), | 106 path_(path.NormalizePathSeparators()), |
| 100 is_valid_(true) { | 107 mount_type_(type), |
| 101 MayCrackIsolatedPath(); | 108 virtual_path_(path) { |
| 109 } |
| 110 |
| 111 // static |
| 112 FileSystemURL FileSystemURL::CreateForCrackedURL( |
| 113 const FileSystemURL& original, |
| 114 const std::string& filesystem_id, |
| 115 FileSystemType cracked_type, |
| 116 const FilePath& cracked_path) { |
| 117 if (!original.is_valid()) |
| 118 return FileSystemURL(); |
| 119 return FileSystemURL(original.origin(), |
| 120 original.type(), |
| 121 original.path(), |
| 122 filesystem_id, |
| 123 cracked_type, |
| 124 cracked_path); |
| 125 } |
| 126 |
| 127 FileSystemURL::FileSystemURL(const GURL& origin, |
| 128 FileSystemType original_type, |
| 129 const FilePath& original_path, |
| 130 const std::string& filesystem_id, |
| 131 FileSystemType cracked_type, |
| 132 const FilePath& cracked_path) |
| 133 : is_valid_(true), |
| 134 is_cracked_(true), |
| 135 origin_(origin), |
| 136 type_(cracked_type), |
| 137 path_(cracked_path.NormalizePathSeparators()), |
| 138 filesystem_id_(filesystem_id), |
| 139 mount_type_(original_type), |
| 140 virtual_path_(original_path) { |
| 102 } | 141 } |
| 103 | 142 |
| 104 FileSystemURL::~FileSystemURL() {} | 143 FileSystemURL::~FileSystemURL() {} |
| 105 | 144 |
| 106 std::string FileSystemURL::DebugString() const { | 145 std::string FileSystemURL::DebugString() const { |
| 107 if (!is_valid_) | 146 if (!is_valid_) |
| 108 return "invalid filesystem: URL"; | 147 return "invalid filesystem: URL"; |
| 109 std::ostringstream ss; | 148 std::ostringstream ss; |
| 110 ss << GetFileSystemRootURI(origin_, mount_type_); | 149 ss << GetFileSystemRootURI(origin_, mount_type_); |
| 111 if (!virtual_path_.empty()) | 150 if (!virtual_path_.empty()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 DCHECK(lhs.is_valid_ && rhs.is_valid_); | 185 DCHECK(lhs.is_valid_ && rhs.is_valid_); |
| 147 if (lhs.origin_ != rhs.origin_) | 186 if (lhs.origin_ != rhs.origin_) |
| 148 return lhs.origin_ < rhs.origin_; | 187 return lhs.origin_ < rhs.origin_; |
| 149 if (lhs.type_ != rhs.type_) | 188 if (lhs.type_ != rhs.type_) |
| 150 return lhs.type_ < rhs.type_; | 189 return lhs.type_ < rhs.type_; |
| 151 if (lhs.filesystem_id_ != rhs.filesystem_id_) | 190 if (lhs.filesystem_id_ != rhs.filesystem_id_) |
| 152 return lhs.filesystem_id_ < rhs.filesystem_id_; | 191 return lhs.filesystem_id_ < rhs.filesystem_id_; |
| 153 return lhs.path_ < rhs.path_; | 192 return lhs.path_ < rhs.path_; |
| 154 } | 193 } |
| 155 | 194 |
| 156 void FileSystemURL::MayCrackIsolatedPath() { | |
| 157 path_ = virtual_path_; | |
| 158 mount_type_ = type_; | |
| 159 if (is_valid_ && IsolatedContext::IsIsolatedType(type_)) { | |
| 160 // If the type is isolated, crack the path further to get the 'real' | |
| 161 // filesystem type and path. | |
| 162 is_valid_ = ExternalMountPoints::GetSystemInstance()->CrackVirtualPath( | |
| 163 virtual_path_, &filesystem_id_, &type_, &path_); | |
| 164 if (is_valid_) | |
| 165 return; | |
| 166 is_valid_ = IsolatedContext::GetInstance()->CrackVirtualPath( | |
| 167 virtual_path_, &filesystem_id_, &type_, &path_); | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 } // namespace fileapi | 195 } // namespace fileapi |
| OLD | NEW |