Chromium Code Reviews| 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 "webkit/fileapi/file_system_types.h" | 7 #include "webkit/fileapi/file_system_types.h" |
| 8 #include "webkit/fileapi/file_system_util.h" | 8 #include "webkit/fileapi/file_system_util.h" |
| 9 #include "webkit/fileapi/isolated_context.h" | 9 #include "webkit/fileapi/isolated_context.h" |
| 10 | 10 |
| 11 namespace fileapi { | 11 namespace fileapi { |
| 12 | 12 |
| 13 FileSystemURL::FileSystemURL() | 13 FileSystemURL::FileSystemURL() |
| 14 : type_(kFileSystemTypeUnknown), is_valid_(false) {} | 14 : type_(kFileSystemTypeUnknown), is_valid_(false) {} |
| 15 | 15 |
| 16 FileSystemURL::FileSystemURL(const GURL& url) | 16 FileSystemURL::FileSystemURL(const GURL& url) |
| 17 : type_(kFileSystemTypeUnknown) { | 17 : type_(kFileSystemTypeUnknown) { |
| 18 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &path_); | 18 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &virtual_path_); |
| 19 MayCrackIsolatedPath(); | 19 MayCrackIsolatedPath(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 FileSystemURL::FileSystemURL( | 22 FileSystemURL::FileSystemURL( |
| 23 const GURL& origin, | 23 const GURL& origin, |
| 24 FileSystemType type, | 24 FileSystemType type, |
| 25 const FilePath& path) | 25 const FilePath& path) |
| 26 : origin_(origin), | 26 : origin_(origin), |
| 27 type_(type), | 27 type_(type), |
| 28 path_(path), | 28 virtual_path_(path), |
| 29 is_valid_(true) { | 29 is_valid_(true) { |
| 30 MayCrackIsolatedPath(); | 30 MayCrackIsolatedPath(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 FileSystemURL::~FileSystemURL() {} | 33 FileSystemURL::~FileSystemURL() {} |
| 34 | 34 |
| 35 std::string FileSystemURL::spec() const { | 35 std::string FileSystemURL::spec() const { |
| 36 if (!is_valid_) | 36 if (!is_valid_) |
| 37 return std::string(); | 37 return std::string(); |
| 38 return GetFileSystemRootURI(origin_, type_).spec() + "/" + | 38 return GetFileSystemRootURI(origin_, type_).spec() + "/" + |
| 39 path_.AsUTF8Unsafe(); | 39 virtual_path_.AsUTF8Unsafe(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { | 42 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { |
| 43 return FileSystemURL(origin(), type(), path); | 43 FileSystemURL url(*this); |
| 44 url.path_ = path; | |
|
tzik
2012/08/20 03:58:50
Could you invalidate virtual_path here?
kinuko
2012/08/20 08:54:35
Done.
| |
| 45 return url; | |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool FileSystemURL::operator==(const FileSystemURL& that) const { | 48 bool FileSystemURL::operator==(const FileSystemURL& that) const { |
| 47 return origin_ == that.origin_ && | 49 return origin_ == that.origin_ && |
| 48 type_ == that.type_ && | 50 type_ == that.type_ && |
| 49 path_ == that.path_ && | 51 path_ == that.path_ && |
| 52 virtual_path_ == that.virtual_path_ && | |
| 50 filesystem_id_ == that.filesystem_id_ && | 53 filesystem_id_ == that.filesystem_id_ && |
| 51 is_valid_ == that.is_valid_; | 54 is_valid_ == that.is_valid_; |
| 52 } | 55 } |
| 53 | 56 |
| 54 void FileSystemURL::MayCrackIsolatedPath() { | 57 void FileSystemURL::MayCrackIsolatedPath() { |
| 55 if (is_valid_ && type_ == kFileSystemTypeIsolated) { | 58 path_ = virtual_path_; |
| 59 if (is_valid_ && IsolatedContext::IsIsolatedType(type_)) { | |
| 56 // If the type is isolated, crack the path further to get the 'real' | 60 // If the type is isolated, crack the path further to get the 'real' |
| 57 // filesystem type and path. | 61 // filesystem type and path. |
| 58 is_valid_ = IsolatedContext::GetInstance()->CrackIsolatedPath( | 62 is_valid_ = IsolatedContext::GetInstance()->CrackIsolatedPath( |
| 59 path_, &filesystem_id_, &type_, &path_); | 63 virtual_path_, &filesystem_id_, &type_, &path_); |
| 60 } | 64 } |
| 61 } | 65 } |
| 62 | 66 |
| 63 } // namespace fileapi | 67 } // namespace fileapi |
| OLD | NEW |