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 } | |
89 | |
90 // static | |
91 FileSystemURL FileSystemURL::CreateForTest(const GURL& url) { | |
92 return FileSystemURL(url); | |
93 } | |
94 | |
95 FileSystemURL FileSystemURL::CreateForTest(const GURL& origin, | |
96 FileSystemType type, | |
97 const FilePath& path) { | |
98 return FileSystemURL(origin, type, path); | |
99 } | |
86 | 100 |
87 FileSystemURL::FileSystemURL(const GURL& url) | 101 FileSystemURL::FileSystemURL(const GURL& url) |
88 : type_(kFileSystemTypeUnknown) { | 102 : is_cracked_(false), |
89 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &virtual_path_); | 103 type_(kFileSystemTypeUnknown), |
90 MayCrackIsolatedPath(); | 104 mount_type_(kFileSystemTypeUnknown) { |
105 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &path_); | |
kinuko
2013/01/18 07:33:32
This overloaded verb 'crack' is now getting seriou
tbarzic
2013/01/18 21:33:15
Done.
| |
106 mount_type_ = type_; | |
91 } | 107 } |
92 | 108 |
93 FileSystemURL::FileSystemURL( | 109 FileSystemURL::FileSystemURL(const GURL& origin, |
94 const GURL& origin, | 110 FileSystemType type, |
95 FileSystemType type, | 111 const FilePath& path) |
96 const FilePath& path) | 112 : is_valid_(true), |
97 : origin_(origin), | 113 is_cracked_(false), |
114 origin_(origin), | |
98 type_(type), | 115 type_(type), |
99 virtual_path_(path.NormalizePathSeparators()), | 116 path_(path.NormalizePathSeparators()), |
100 is_valid_(true) { | 117 mount_type_(type) { |
101 MayCrackIsolatedPath(); | 118 } |
119 | |
120 FileSystemURL::FileSystemURL(const GURL& origin, | |
121 FileSystemType original_type, | |
122 const FilePath& original_path, | |
123 const std::string& filesystem_id, | |
124 FileSystemType cracked_type, | |
125 const FilePath& cracked_path) | |
126 : is_valid_(true), | |
127 is_cracked_(true), | |
128 origin_(origin), | |
129 type_(cracked_type), | |
130 path_(cracked_path.NormalizePathSeparators()), | |
131 filesystem_id_(filesystem_id), | |
132 mount_type_(original_type), | |
133 virtual_path_(original_path) { | |
102 } | 134 } |
103 | 135 |
104 FileSystemURL::~FileSystemURL() {} | 136 FileSystemURL::~FileSystemURL() {} |
105 | 137 |
138 // static | |
139 FileSystemURL FileSystemURL::CreateForCrackedURL( | |
140 const FileSystemURL& original, | |
141 const std::string& filesystem_id, | |
142 FileSystemType cracked_type, | |
143 const FilePath& cracked_path) { | |
144 if (!original.is_valid()) | |
145 return FileSystemURL(); | |
146 return FileSystemURL(original.origin(), | |
147 original.type(), | |
148 original.path(), | |
149 filesystem_id, | |
150 cracked_type, | |
151 cracked_path); | |
152 } | |
153 | |
106 std::string FileSystemURL::DebugString() const { | 154 std::string FileSystemURL::DebugString() const { |
107 if (!is_valid_) | 155 if (!is_valid_) |
108 return "invalid filesystem: URL"; | 156 return "invalid filesystem: URL"; |
109 std::ostringstream ss; | 157 std::ostringstream ss; |
110 ss << GetFileSystemRootURI(origin_, mount_type_); | 158 ss << GetFileSystemRootURI(origin_, mount_type_); |
111 if (!virtual_path_.empty()) | 159 if (!is_cracked_ && !path_.empty()) |
160 ss << path_.value(); | |
161 | |
162 if (is_cracked_) { | |
112 ss << virtual_path_.value(); | 163 ss << virtual_path_.value(); |
113 if (type_ != mount_type_ || path_ != virtual_path_) { | |
114 ss << " ("; | 164 ss << " ("; |
115 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; | 165 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; |
116 ss << path_.value(); | 166 ss << path_.value(); |
117 ss << ")"; | 167 ss << ")"; |
118 } | 168 } |
119 return ss.str(); | 169 return ss.str(); |
120 } | 170 } |
121 | 171 |
122 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { | 172 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { |
123 FileSystemURL url = *this; | 173 FileSystemURL url = *this; |
(...skipping 22 matching lines...) Expand all Loading... | |
146 DCHECK(lhs.is_valid_ && rhs.is_valid_); | 196 DCHECK(lhs.is_valid_ && rhs.is_valid_); |
147 if (lhs.origin_ != rhs.origin_) | 197 if (lhs.origin_ != rhs.origin_) |
148 return lhs.origin_ < rhs.origin_; | 198 return lhs.origin_ < rhs.origin_; |
149 if (lhs.type_ != rhs.type_) | 199 if (lhs.type_ != rhs.type_) |
150 return lhs.type_ < rhs.type_; | 200 return lhs.type_ < rhs.type_; |
151 if (lhs.filesystem_id_ != rhs.filesystem_id_) | 201 if (lhs.filesystem_id_ != rhs.filesystem_id_) |
152 return lhs.filesystem_id_ < rhs.filesystem_id_; | 202 return lhs.filesystem_id_ < rhs.filesystem_id_; |
153 return lhs.path_ < rhs.path_; | 203 return lhs.path_ < rhs.path_; |
154 } | 204 } |
155 | 205 |
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 | 206 } // namespace fileapi |
OLD | NEW |