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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 *type = file_system_type; | 93 *type = file_system_type; |
94 if (file_path) | 94 if (file_path) |
95 *file_path = converted_path.NormalizePathSeparators(). | 95 *file_path = converted_path.NormalizePathSeparators(). |
96 StripTrailingSeparators(); | 96 StripTrailingSeparators(); |
97 | 97 |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 FileSystemURL::FileSystemURL(const GURL& url) | 101 FileSystemURL::FileSystemURL(const GURL& url) |
102 : type_(kFileSystemTypeUnknown), | 102 : type_(kFileSystemTypeUnknown), |
103 mount_type_(kFileSystemTypeUnknown) { | 103 mount_type_(kFileSystemTypeUnknown), |
| 104 has_underlying_url_(false) { |
104 is_valid_ = ParseFileSystemSchemeURL(url, &origin_, &type_, &path_); | 105 is_valid_ = ParseFileSystemSchemeURL(url, &origin_, &type_, &path_); |
105 virtual_path_ = path_; | 106 virtual_path_ = path_; |
106 mount_type_ = type_; | 107 mount_type_ = type_; |
107 } | 108 } |
108 | 109 |
109 FileSystemURL::FileSystemURL(const GURL& origin, | 110 FileSystemURL::FileSystemURL(const GURL& origin, |
110 FileSystemType type, | 111 FileSystemType type, |
111 const base::FilePath& path) | 112 const base::FilePath& path) |
112 : is_valid_(true), | 113 : is_valid_(true), |
113 origin_(origin), | 114 origin_(origin), |
114 type_(type), | 115 type_(type), |
115 mount_type_(type), | 116 mount_type_(type), |
116 path_(path.NormalizePathSeparators()), | 117 path_(path.NormalizePathSeparators()), |
117 virtual_path_(path.NormalizePathSeparators()) { | 118 virtual_path_(path.NormalizePathSeparators()), |
| 119 has_underlying_url_(false) { |
118 } | 120 } |
119 | 121 |
120 FileSystemURL::FileSystemURL(const GURL& origin, | 122 FileSystemURL::FileSystemURL(const GURL& origin, |
121 FileSystemType mount_type, | 123 FileSystemType mount_type, |
122 const base::FilePath& virtual_path, | 124 const base::FilePath& virtual_path, |
123 const std::string& filesystem_id, | 125 const std::string& filesystem_id, |
124 FileSystemType cracked_type, | 126 FileSystemType cracked_type, |
125 const base::FilePath& cracked_path) | 127 const base::FilePath& cracked_path) |
126 : is_valid_(true), | 128 : is_valid_(true), |
127 origin_(origin), | 129 origin_(origin), |
128 type_(cracked_type), | 130 type_(cracked_type), |
129 mount_type_(mount_type), | 131 mount_type_(mount_type), |
130 path_(cracked_path.NormalizePathSeparators()), | 132 path_(cracked_path.NormalizePathSeparators()), |
131 filesystem_id_(filesystem_id), | 133 filesystem_id_(filesystem_id), |
132 virtual_path_(virtual_path.NormalizePathSeparators()) { | 134 virtual_path_(virtual_path.NormalizePathSeparators()), |
| 135 has_underlying_url_(false) { |
133 } | 136 } |
134 | 137 |
135 FileSystemURL::~FileSystemURL() {} | 138 FileSystemURL::~FileSystemURL() {} |
136 | 139 |
| 140 void FileSystemURL::SetUnderlyingURL(const FileSystemURL& underlying_url) { |
| 141 has_underlying_url_ = true; |
| 142 underlying_filesystem_id_ = underlying_url.filesystem_id(); |
| 143 underlying_type_ = underlying_url.type(); |
| 144 underlying_virtual_path_ = underlying_url.virtual_path(); |
| 145 } |
| 146 |
137 std::string FileSystemURL::DebugString() const { | 147 std::string FileSystemURL::DebugString() const { |
138 if (!is_valid_) | 148 if (!is_valid_) |
139 return "invalid filesystem: URL"; | 149 return "invalid filesystem: URL"; |
140 std::ostringstream ss; | 150 std::ostringstream ss; |
141 ss << GetFileSystemRootURI(origin_, mount_type_); | 151 ss << GetFileSystemRootURI(origin_, mount_type_); |
142 | 152 |
143 // filesystem_id_ will be non empty for (and only for) cracked URLs. | 153 // filesystem_id_ will be non empty for (and only for) cracked URLs. |
144 if (!filesystem_id_.empty()) { | 154 if (!filesystem_id_.empty()) { |
145 ss << virtual_path_.value(); | 155 ss << virtual_path_.value(); |
146 ss << " ("; | 156 ss << " ("; |
147 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; | 157 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; |
148 ss << path_.value(); | 158 ss << path_.value(); |
149 ss << ")"; | 159 ss << ")"; |
150 } else { | 160 } else { |
151 ss << path_.value(); | 161 ss << path_.value(); |
152 } | 162 } |
153 return ss.str(); | 163 return ss.str(); |
154 } | 164 } |
155 | 165 |
156 bool FileSystemURL::IsParent(const FileSystemURL& child) const { | 166 bool FileSystemURL::IsParent(const FileSystemURL& child) const { |
157 return origin() == child.origin() && | 167 return origin() == child.origin() && |
158 type() == child.type() && | 168 type() == child.type() && |
159 filesystem_id() == child.filesystem_id() && | 169 filesystem_id() == child.filesystem_id() && |
160 path().IsParent(child.path()); | 170 path().IsParent(child.path()); |
161 } | 171 } |
162 | 172 |
| 173 FileSystemURL FileSystemURL::GetForOperations() const { |
| 174 if (!has_underlying_url_) |
| 175 return *this; |
| 176 return FileSystemURL(origin_, |
| 177 mount_type_, |
| 178 underlying_virtual_path_, |
| 179 underlying_filesystem_id_, |
| 180 underlying_type_, |
| 181 path_); |
| 182 } |
| 183 |
163 bool FileSystemURL::operator==(const FileSystemURL& that) const { | 184 bool FileSystemURL::operator==(const FileSystemURL& that) const { |
164 return origin_ == that.origin_ && | 185 return origin_ == that.origin_ && |
165 type_ == that.type_ && | 186 type_ == that.type_ && |
166 path_ == that.path_ && | 187 path_ == that.path_ && |
167 filesystem_id_ == that.filesystem_id_ && | 188 filesystem_id_ == that.filesystem_id_ && |
168 is_valid_ == that.is_valid_; | 189 is_valid_ == that.is_valid_; |
169 } | 190 } |
170 | 191 |
171 bool FileSystemURL::Comparator::operator()(const FileSystemURL& lhs, | 192 bool FileSystemURL::Comparator::operator()(const FileSystemURL& lhs, |
172 const FileSystemURL& rhs) const { | 193 const FileSystemURL& rhs) const { |
173 DCHECK(lhs.is_valid_ && rhs.is_valid_); | 194 DCHECK(lhs.is_valid_ && rhs.is_valid_); |
174 if (lhs.origin_ != rhs.origin_) | 195 if (lhs.origin_ != rhs.origin_) |
175 return lhs.origin_ < rhs.origin_; | 196 return lhs.origin_ < rhs.origin_; |
176 if (lhs.type_ != rhs.type_) | 197 if (lhs.type_ != rhs.type_) |
177 return lhs.type_ < rhs.type_; | 198 return lhs.type_ < rhs.type_; |
178 if (lhs.filesystem_id_ != rhs.filesystem_id_) | 199 if (lhs.filesystem_id_ != rhs.filesystem_id_) |
179 return lhs.filesystem_id_ < rhs.filesystem_id_; | 200 return lhs.filesystem_id_ < rhs.filesystem_id_; |
180 return lhs.path_ < rhs.path_; | 201 return lhs.path_ < rhs.path_; |
181 } | 202 } |
182 | 203 |
183 } // namespace fileapi | 204 } // namespace fileapi |
OLD | NEW |