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

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: fix test on Win 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
« no previous file with comments | « webkit/fileapi/file_system_url.h ('k') | webkit/fileapi/file_system_url_request_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 mount_type_(type),
100 is_valid_(true) { 113 path_(path.NormalizePathSeparators()) {
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 mount_type_(original_type),
126 path_(cracked_path.NormalizePathSeparators()),
127 filesystem_id_(filesystem_id),
128 virtual_path_(original_path.NormalizePathSeparators()) {
102 } 129 }
103 130
104 FileSystemURL::~FileSystemURL() {} 131 FileSystemURL::~FileSystemURL() {}
105 132
106 std::string FileSystemURL::DebugString() const { 133 std::string FileSystemURL::DebugString() const {
107 if (!is_valid_) 134 if (!is_valid_)
108 return "invalid filesystem: URL"; 135 return "invalid filesystem: URL";
109 std::ostringstream ss; 136 std::ostringstream ss;
110 ss << GetFileSystemRootURI(origin_, mount_type_); 137 ss << GetFileSystemRootURI(origin_, mount_type_);
111 if (!virtual_path_.empty()) 138
139 // filesystem_id_ will be non empty for (and only for) cracked URLs.
140 if (!filesystem_id_.empty()) {
112 ss << virtual_path_.value(); 141 ss << virtual_path_.value();
113 if (type_ != mount_type_ || path_ != virtual_path_) {
114 ss << " ("; 142 ss << " (";
115 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":"; 143 ss << GetFileSystemTypeString(type_) << "@" << filesystem_id_ << ":";
116 ss << path_.value(); 144 ss << path_.value();
117 ss << ")"; 145 ss << ")";
146 } else {
147 ss << path_.value();
118 } 148 }
119 return ss.str(); 149 return ss.str();
120 } 150 }
121 151
122 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { 152 FileSystemURL FileSystemURL::WithPath(const FilePath& path) const {
123 FileSystemURL url = *this; 153 FileSystemURL url = *this;
124 url.path_ = path; 154 url.path_ = path;
125 url.virtual_path_.clear(); 155 url.virtual_path_.clear();
126 return url; 156 return url;
127 } 157 }
(...skipping 18 matching lines...) Expand all
146 DCHECK(lhs.is_valid_ && rhs.is_valid_); 176 DCHECK(lhs.is_valid_ && rhs.is_valid_);
147 if (lhs.origin_ != rhs.origin_) 177 if (lhs.origin_ != rhs.origin_)
148 return lhs.origin_ < rhs.origin_; 178 return lhs.origin_ < rhs.origin_;
149 if (lhs.type_ != rhs.type_) 179 if (lhs.type_ != rhs.type_)
150 return lhs.type_ < rhs.type_; 180 return lhs.type_ < rhs.type_;
151 if (lhs.filesystem_id_ != rhs.filesystem_id_) 181 if (lhs.filesystem_id_ != rhs.filesystem_id_)
152 return lhs.filesystem_id_ < rhs.filesystem_id_; 182 return lhs.filesystem_id_ < rhs.filesystem_id_;
153 return lhs.path_ < rhs.path_; 183 return lhs.path_ < rhs.path_;
154 } 184 }
155 185
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 186 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url.h ('k') | webkit/fileapi/file_system_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698