Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: webkit/fileapi/file_system_url.cc

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Couple of nits I noticed Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "webkit/fileapi/external_mount_points.h" 12 #include "webkit/fileapi/external_mount_points.h"
13 #include "webkit/fileapi/file_system_types.h" 13 #include "webkit/fileapi/file_system_types.h"
14 #include "webkit/fileapi/file_system_util.h" 14 #include "webkit/fileapi/file_system_util.h"
15 #include "webkit/fileapi/isolated_context.h" 15 #include "webkit/fileapi/isolated_context.h"
16 16
17 namespace fileapi { 17 namespace fileapi {
18 18
19 namespace { 19 namespace {
20 20
21 bool CrackFileSystemURL( 21 bool ParseFileSystemURL(const GURL& url,
22 const GURL& url, 22 GURL* origin_url,
23 GURL* origin_url, 23 FileSystemType* type,
24 FileSystemType* type, 24 FilePath* file_path) {
25 FilePath* file_path) {
26 GURL origin; 25 GURL origin;
27 FileSystemType file_system_type = kFileSystemTypeUnknown; 26 FileSystemType file_system_type = kFileSystemTypeUnknown;
28 27
29 if (!url.is_valid() || !url.SchemeIsFileSystem()) 28 if (!url.is_valid() || !url.SchemeIsFileSystem())
30 return false; 29 return false;
31 DCHECK(url.inner_url()); 30 DCHECK(url.inner_url());
32 31
33 std::string inner_path = url.inner_url()->path(); 32 std::string inner_path = url.inner_url()->path();
34 33
35 const struct { 34 const struct {
36 FileSystemType type; 35 FileSystemType type;
37 const char* dir; 36 const char* dir;
38 } kValidTypes[] = { 37 } kValidTypes[] = {
39 { kFileSystemTypePersistent, kPersistentDir }, 38 { kFileSystemTypePersistent, kPersistentDir },
40 { kFileSystemTypeTemporary, kTemporaryDir }, 39 { kFileSystemTypeTemporary, kTemporaryDir },
41 { kFileSystemTypeIsolated, kIsolatedDir }, 40 { kFileSystemTypeIsolated, kIsolatedDir },
42 { kFileSystemTypeExternal, kExternalDir }, 41 { kFileSystemTypeExternal, kExternalDir },
43 { kFileSystemTypeTest, kTestDir }, 42 { kFileSystemTypeTest, kTestDir },
44 }; 43 };
44
45 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { 45 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) {
46 if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) { 46 if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) {
47 file_system_type = kValidTypes[i].type; 47 file_system_type = kValidTypes[i].type;
48 break; 48 break;
49 } 49 }
50 } 50 }
51 51
52 if (file_system_type == kFileSystemTypeUnknown) 52 if (file_system_type == kFileSystemTypeUnknown)
53 return false; 53 return false;
54 54
(...skipping 18 matching lines...) Expand all
73 if (file_path) 73 if (file_path)
74 *file_path = converted_path.NormalizePathSeparators(). 74 *file_path = converted_path.NormalizePathSeparators().
75 StripTrailingSeparators(); 75 StripTrailingSeparators();
76 76
77 return true; 77 return true;
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
82 FileSystemURL::FileSystemURL() 82 FileSystemURL::FileSystemURL()
83 : type_(kFileSystemTypeUnknown), 83 : is_valid_(false),
84 mount_type_(kFileSystemTypeUnknown), 84 type_(kFileSystemTypeUnknown),
85 is_valid_(false) {} 85 mount_type_(kFileSystemTypeUnknown) {
86 }
87
88 // static
89 FileSystemURL FileSystemURL::CreateForTest(const GURL& url) {
90 return FileSystemURL(url);
91 }
92
93 FileSystemURL FileSystemURL::CreateForTest(const GURL& origin,
94 FileSystemType type,
95 const FilePath& path) {
96 return FileSystemURL(origin, type, path);
97 }
86 98
87 FileSystemURL::FileSystemURL(const GURL& url) 99 FileSystemURL::FileSystemURL(const GURL& url)
88 : type_(kFileSystemTypeUnknown) { 100 : type_(kFileSystemTypeUnknown),
89 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &virtual_path_); 101 mount_type_(kFileSystemTypeUnknown) {
90 MayCrackIsolatedPath(); 102 is_valid_ = ParseFileSystemURL(url, &origin_, &type_, &path_);
103 mount_type_ = type_;
91 } 104 }
92 105
93 FileSystemURL::FileSystemURL( 106 FileSystemURL::FileSystemURL(const GURL& origin,
94 const GURL& origin, 107 FileSystemType type,
95 FileSystemType type, 108 const FilePath& path)
96 const FilePath& path) 109 : is_valid_(true),
97 : origin_(origin), 110 origin_(origin),
98 type_(type), 111 type_(type),
99 virtual_path_(path.NormalizePathSeparators()), 112 path_(path.NormalizePathSeparators()),
100 is_valid_(true) { 113 mount_type_(type) {
101 MayCrackIsolatedPath(); 114 }
115
116 FileSystemURL::FileSystemURL(const GURL& origin,
117 FileSystemType original_type,
118 const FilePath& original_path,
119 const std::string& filesystem_id,
120 FileSystemType cracked_type,
121 const FilePath& cracked_path)
122 : is_valid_(true),
123 origin_(origin),
124 type_(cracked_type),
125 path_(cracked_path.NormalizePathSeparators()),
126 filesystem_id_(filesystem_id),
127 mount_type_(original_type),
128 virtual_path_(original_path) {
102 } 129 }
103 130
104 FileSystemURL::~FileSystemURL() {} 131 FileSystemURL::~FileSystemURL() {}
105 132
133 // static
134 FileSystemURL FileSystemURL::CreateForCrackedURL(
135 const FileSystemURL& original,
136 const std::string& filesystem_id,
137 FileSystemType cracked_type,
138 const FilePath& cracked_path) {
139 if (!original.is_valid())
140 return FileSystemURL();
141 return FileSystemURL(original.origin(),
142 original.type(),
143 original.path(),
144 filesystem_id,
145 cracked_type,
146 cracked_path);
147 }
148
106 std::string FileSystemURL::DebugString() const { 149 std::string FileSystemURL::DebugString() const {
107 if (!is_valid_) 150 if (!is_valid_)
108 return "invalid filesystem: URL"; 151 return "invalid filesystem: URL";
109 std::ostringstream ss; 152 std::ostringstream ss;
110 ss << GetFileSystemRootURI(origin_, mount_type_); 153 ss << GetFileSystemRootURI(origin_, mount_type_);
111 if (!virtual_path_.empty()) 154
155 // filesystem_id_ will be non empty for (and only for) cracked URLs.
156 if (!filesystem_id_.empty()) {
112 ss << virtual_path_.value(); 157 ss << virtual_path_.value();
113 if (type_ != mount_type_ || path_ != virtual_path_) {
114 ss << " ("; 158 ss << " (";
115 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; 159 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":";
116 ss << path_.value(); 160 ss << path_.value();
117 ss << ")"; 161 ss << ")";
162 } else {
163 ss << path_.value();
118 } 164 }
119 return ss.str(); 165 return ss.str();
120 } 166 }
121 167
122 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { 168 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const {
123 FileSystemURL url = *this; 169 FileSystemURL url = *this;
124 url.path_ = path; 170 url.path_ = path;
125 url.virtual_path_.clear(); 171 url.virtual_path_.clear();
126 return url; 172 return url;
127 } 173 }
(...skipping 18 matching lines...) Expand all
146 DCHECK(lhs.is_valid_ && rhs.is_valid_); 192 DCHECK(lhs.is_valid_ && rhs.is_valid_);
147 if (lhs.origin_ != rhs.origin_) 193 if (lhs.origin_ != rhs.origin_)
148 return lhs.origin_ < rhs.origin_; 194 return lhs.origin_ < rhs.origin_;
149 if (lhs.type_ != rhs.type_) 195 if (lhs.type_ != rhs.type_)
150 return lhs.type_ < rhs.type_; 196 return lhs.type_ < rhs.type_;
151 if (lhs.filesystem_id_ != rhs.filesystem_id_) 197 if (lhs.filesystem_id_ != rhs.filesystem_id_)
152 return lhs.filesystem_id_ < rhs.filesystem_id_; 198 return lhs.filesystem_id_ < rhs.filesystem_id_;
153 return lhs.path_ < rhs.path_; 199 return lhs.path_ < rhs.path_;
154 } 200 }
155 201
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 202 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698