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

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

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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/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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "webkit/fileapi/file_system_url.h"
15 16
16 namespace fileapi { 17 namespace fileapi {
17 18
18 namespace { 19 namespace {
19 20
20 FilePath::StringType GetRegisterNameForPath(const FilePath& path) { 21 FilePath::StringType GetRegisterNameForPath(const FilePath& path) {
21 // If it's not a root path simply return a base name. 22 // If it's not a root path simply return a base name.
22 if (path.DirName() != path) 23 if (path.DirName() != path)
23 return path.BaseName().value(); 24 return path.BaseName().value();
24 25
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 instance_map_[filesystem_id] = new Instance(type, MountPointInfo(name, path)); 224 instance_map_[filesystem_id] = new Instance(type, MountPointInfo(name, path));
224 path_to_id_map_[path].insert(filesystem_id); 225 path_to_id_map_[path].insert(filesystem_id);
225 return filesystem_id; 226 return filesystem_id;
226 } 227 }
227 228
228 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { 229 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) {
229 base::AutoLock locker(lock_); 230 base::AutoLock locker(lock_);
230 return UnregisterFileSystem(filesystem_id); 231 return UnregisterFileSystem(filesystem_id);
231 } 232 }
232 233
234 bool IsolatedContext::CanHandleURL(const FileSystemURL& url) const {
235 return url.is_valid() && url.type() == kFileSystemTypeIsolated;
236 }
237
238 FileSystemURL IsolatedContext::CrackURL(const FileSystemURL& url) const {
239 if (!CanHandleURL(url))
240 return FileSystemURL();
241
242 DCHECK(!url.is_cracked());
243
244 std::string mount_name;
245 FileSystemType type;
246 FilePath path;
247 if (!CrackVirtualPath(url.path(), &mount_name, &type, &path))
248 return FileSystemURL();
249
250 return FileSystemURL::CreateForCrackedURL(url, mount_name, type, path);
251 }
252
233 bool IsolatedContext::GetRegisteredPath( 253 bool IsolatedContext::GetRegisteredPath(
234 const std::string& filesystem_id, FilePath* path) const { 254 const std::string& filesystem_id, FilePath* path) const {
235 DCHECK(path); 255 DCHECK(path);
236 base::AutoLock locker(lock_); 256 base::AutoLock locker(lock_);
237 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); 257 IDToInstance::const_iterator found = instance_map_.find(filesystem_id);
238 if (found == instance_map_.end() || !found->second->IsSinglePathInstance()) 258 if (found == instance_map_.end() || !found->second->IsSinglePathInstance())
239 return false; 259 return false;
240 *path = found->second->file_info().path; 260 *path = found->second->file_info().path;
241 return true; 261 return true;
242 } 262 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 uint32 random_data[4]; 404 uint32 random_data[4];
385 std::string id; 405 std::string id;
386 do { 406 do {
387 base::RandBytes(random_data, sizeof(random_data)); 407 base::RandBytes(random_data, sizeof(random_data));
388 id = base::HexEncode(random_data, sizeof(random_data)); 408 id = base::HexEncode(random_data, sizeof(random_data));
389 } while (instance_map_.find(id) != instance_map_.end()); 409 } while (instance_map_.find(id) != instance_map_.end());
390 return id; 410 return id;
391 } 411 }
392 412
393 } // namespace fileapi 413 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698