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

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

Issue 10879002: kFileSystemTypeIsolated should be only used in the URL exposed to renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 8 years, 3 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_util.h ('k') | webkit/fileapi/isolated_context_unittest.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/isolated_context.h" 5 #include "webkit/fileapi/isolated_context.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // The given path should not contain any '..' and should be absolute. 100 // The given path should not contain any '..' and should be absolute.
101 if (path.ReferencesParent() || !path.IsAbsolute()) 101 if (path.ReferencesParent() || !path.IsAbsolute())
102 return false; 102 return false;
103 return fileset_.insert(FileInfo(name, path.NormalizePathSeparators())).second; 103 return fileset_.insert(FileInfo(name, path.NormalizePathSeparators())).second;
104 } 104 }
105 105
106 //-------------------------------------------------------------------------- 106 //--------------------------------------------------------------------------
107 107
108 class IsolatedContext::Instance { 108 class IsolatedContext::Instance {
109 public: 109 public:
110 typedef FileSystemMountType MountType; 110 typedef FileSystemType MountType;
111 111
112 // For a single-path isolated file system, which could be registered by 112 // For a single-path isolated file system, which could be registered by
113 // IsolatedContext::RegisterFileSystemForPath(). 113 // IsolatedContext::RegisterFileSystemForPath().
114 // Most of isolated file system contexts should be of this type. 114 // Most of isolated file system contexts should be of this type.
115 Instance(FileSystemType type, const FileInfo& file_info); 115 Instance(FileSystemType type, const FileInfo& file_info);
116 116
117 // For a multi-paths isolated file system. As of writing only file system 117 // For a multi-paths isolated file system. As of writing only file system
118 // type which could have multi-paths is Dragged file system, and 118 // type which could have multi-paths is Dragged file system, and
119 // could be registered by IsolatedContext::RegisterDraggedFileSystem(). 119 // could be registered by IsolatedContext::RegisterDraggedFileSystem().
120 Instance(FileSystemType type, const std::set<FileInfo>& files); 120 Instance(FileSystemType type, const std::set<FileInfo>& files);
(...skipping 29 matching lines...) Expand all
150 150
151 // Reference counts. Note that an isolated filesystem is created with ref==0 151 // Reference counts. Note that an isolated filesystem is created with ref==0
152 // and will get deleted when the ref count reaches <=0. 152 // and will get deleted when the ref count reaches <=0.
153 int ref_counts_; 153 int ref_counts_;
154 154
155 DISALLOW_COPY_AND_ASSIGN(Instance); 155 DISALLOW_COPY_AND_ASSIGN(Instance);
156 }; 156 };
157 157
158 IsolatedContext::Instance::Instance(FileSystemType type, 158 IsolatedContext::Instance::Instance(FileSystemType type,
159 const FileInfo& file_info) 159 const FileInfo& file_info)
160 : mount_type_(kFileSystemMountTypeIsolated), 160 : mount_type_(kFileSystemTypeIsolated),
161 type_(type), 161 type_(type),
162 file_info_(file_info), 162 file_info_(file_info),
163 ref_counts_(0) { 163 ref_counts_(0) {
164 DCHECK(IsSinglePathIsolatedFileSystem(type_)); 164 DCHECK(IsSinglePathIsolatedFileSystem(type_));
165 } 165 }
166 166
167 IsolatedContext::Instance::Instance(FileSystemType type, 167 IsolatedContext::Instance::Instance(FileSystemType type,
168 const std::set<FileInfo>& files) 168 const std::set<FileInfo>& files)
169 : mount_type_(kFileSystemMountTypeIsolated), 169 : mount_type_(kFileSystemTypeIsolated),
170 type_(type), 170 type_(type),
171 files_(files), 171 files_(files),
172 ref_counts_(0) { 172 ref_counts_(0) {
173 DCHECK(!IsSinglePathIsolatedFileSystem(type_)); 173 DCHECK(!IsSinglePathIsolatedFileSystem(type_));
174 } 174 }
175 175
176 IsolatedContext::Instance::Instance(FileSystemType type, 176 IsolatedContext::Instance::Instance(FileSystemType type,
177 const FilePath& path) 177 const FilePath& path)
178 : mount_type_(kFileSystemMountTypeExternal), 178 : mount_type_(kFileSystemTypeExternal),
179 type_(type), 179 type_(type),
180 file_info_(FileInfo("", path)), 180 file_info_(FileInfo("", path)),
181 ref_counts_(0) { 181 ref_counts_(0) {
182 DCHECK(IsSinglePathIsolatedFileSystem(type_)); 182 DCHECK(IsSinglePathIsolatedFileSystem(type_));
183 } 183 }
184 184
185 IsolatedContext::Instance::~Instance() {} 185 IsolatedContext::Instance::~Instance() {}
186 186
187 bool IsolatedContext::Instance::ResolvePathForName(const std::string& name, 187 bool IsolatedContext::Instance::ResolvePathForName(const std::string& name,
188 FilePath* path) const { 188 FilePath* path) const {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return true; 258 return true;
259 } 259 }
260 260
261 std::vector<IsolatedContext::FileInfo> 261 std::vector<IsolatedContext::FileInfo>
262 IsolatedContext::GetExternalMountPoints() const { 262 IsolatedContext::GetExternalMountPoints() const {
263 base::AutoLock locker(lock_); 263 base::AutoLock locker(lock_);
264 std::vector<FileInfo> files; 264 std::vector<FileInfo> files;
265 for (IDToInstance::const_iterator iter = instance_map_.begin(); 265 for (IDToInstance::const_iterator iter = instance_map_.begin();
266 iter != instance_map_.end(); 266 iter != instance_map_.end();
267 ++iter) { 267 ++iter) {
268 if (iter->second->mount_type() == kFileSystemMountTypeExternal) 268 if (iter->second->mount_type() == kFileSystemTypeExternal)
269 files.push_back(FileInfo(iter->first, iter->second->file_info().path)); 269 files.push_back(FileInfo(iter->first, iter->second->file_info().path));
270 } 270 }
271 return files; 271 return files;
272 } 272 }
273 #endif 273 #endif
274 274
275 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { 275 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) {
276 base::AutoLock locker(lock_); 276 base::AutoLock locker(lock_);
277 return UnregisterFileSystem(filesystem_id); 277 return UnregisterFileSystem(filesystem_id);
278 } 278 }
(...skipping 26 matching lines...) Expand all
305 base::AutoLock locker(lock_); 305 base::AutoLock locker(lock_);
306 // This could get called for non-existent filesystem if it has been 306 // This could get called for non-existent filesystem if it has been
307 // already deleted by RevokeFileSystemByPath. 307 // already deleted by RevokeFileSystemByPath.
308 IDToInstance::iterator found = instance_map_.find(filesystem_id); 308 IDToInstance::iterator found = instance_map_.find(filesystem_id);
309 if (found == instance_map_.end()) 309 if (found == instance_map_.end())
310 return; 310 return;
311 Instance* instance = found->second; 311 Instance* instance = found->second;
312 DCHECK(instance->ref_counts() > 0); 312 DCHECK(instance->ref_counts() > 0);
313 instance->RemoveRef(); 313 instance->RemoveRef();
314 if (instance->ref_counts() == 0 && 314 if (instance->ref_counts() == 0 &&
315 instance->mount_type() != kFileSystemMountTypeExternal) { 315 instance->mount_type() != kFileSystemTypeExternal) {
316 bool deleted = UnregisterFileSystem(filesystem_id); 316 bool deleted = UnregisterFileSystem(filesystem_id);
317 DCHECK(deleted); 317 DCHECK(deleted);
318 } 318 }
319 } 319 }
320 320
321 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, 321 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path,
322 std::string* id_or_name, 322 std::string* id_or_name,
323 FileSystemType* type, 323 FileSystemType* type,
324 FilePath* path) const { 324 FilePath* path) const {
325 DCHECK(id_or_name); 325 DCHECK(id_or_name);
(...skipping 18 matching lines...) Expand all
344 { 344 {
345 base::AutoLock locker(lock_); 345 base::AutoLock locker(lock_);
346 IDToInstance::const_iterator found_instance = instance_map_.find(fsid); 346 IDToInstance::const_iterator found_instance = instance_map_.find(fsid);
347 if (found_instance == instance_map_.end()) 347 if (found_instance == instance_map_.end())
348 return false; 348 return false;
349 *id_or_name = fsid; 349 *id_or_name = fsid;
350 const Instance* instance = found_instance->second; 350 const Instance* instance = found_instance->second;
351 if (type) 351 if (type)
352 *type = instance->type(); 352 *type = instance->type();
353 switch (instance->mount_type()) { 353 switch (instance->mount_type()) {
354 case kFileSystemMountTypeIsolated: { 354 case kFileSystemTypeIsolated: {
355 if (component_iter == components.end()) { 355 if (component_iter == components.end()) {
356 // The virtual root case. 356 // The virtual root case.
357 path->clear(); 357 path->clear();
358 return true; 358 return true;
359 } 359 }
360 // *component_iter should be a name of the registered path. 360 // *component_iter should be a name of the registered path.
361 std::string name = FilePath(*component_iter++).AsUTF8Unsafe(); 361 std::string name = FilePath(*component_iter++).AsUTF8Unsafe();
362 if (!instance->ResolvePathForName(name, &cracked_path)) 362 if (!instance->ResolvePathForName(name, &cracked_path))
363 return false; 363 return false;
364 break; 364 break;
365 } 365 }
366 case kFileSystemMountTypeExternal: 366 case kFileSystemTypeExternal:
367 cracked_path = instance->file_info().path; 367 cracked_path = instance->file_info().path;
368 break; 368 break;
369 case kFileSystemMountTypeUnknown: 369 default:
370 NOTREACHED(); 370 NOTREACHED();
371 break; 371 break;
372 } 372 }
373 } 373 }
374 374
375 for (; component_iter != components.end(); ++component_iter) 375 for (; component_iter != components.end(); ++component_iter)
376 cracked_path = cracked_path.Append(*component_iter); 376 cracked_path = cracked_path.Append(*component_iter);
377 *path = cracked_path; 377 *path = cracked_path;
378 return true; 378 return true;
379 } 379 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 uint32 random_data[4]; 440 uint32 random_data[4];
441 std::string id; 441 std::string id;
442 do { 442 do {
443 base::RandBytes(random_data, sizeof(random_data)); 443 base::RandBytes(random_data, sizeof(random_data));
444 id = base::HexEncode(random_data, sizeof(random_data)); 444 id = base::HexEncode(random_data, sizeof(random_data));
445 } while (instance_map_.find(id) != instance_map_.end()); 445 } while (instance_map_.find(id) != instance_map_.end());
446 return id; 446 return id;
447 } 447 }
448 448
449 } // namespace fileapi 449 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_util.h ('k') | webkit/fileapi/isolated_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698