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

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: browser_tests compile 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::CrackFileSystemURL(
239 const FileSystemURL& url) const {
240 if (!CanHandleURL(url))
241 return FileSystemURL();
242
243 DCHECK(!url.is_cracked());
244
245 std::string mount_name;
246 FileSystemType type;
247 FilePath path;
248 if (!CrackVirtualPath(url.path(), &mount_name, &type, &path))
249 return FileSystemURL();
250
251 return FileSystemURL::CreateForCrackedURL(url, mount_name, type, path);
252 }
253
254 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const {
255 return CrackFileSystemURL(FileSystemURL(url));
256 }
257
258 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL(
259 const GURL& origin,
260 FileSystemType type,
261 const FilePath& path) const {
262 return CrackFileSystemURL(FileSystemURL(origin, type, path));
263 }
264
265
kinuko 2013/01/18 07:33:32 nit: extra line
tbarzic 2013/01/18 21:33:15 Done.
233 bool IsolatedContext::GetRegisteredPath( 266 bool IsolatedContext::GetRegisteredPath(
234 const std::string& filesystem_id, FilePath* path) const { 267 const std::string& filesystem_id, FilePath* path) const {
235 DCHECK(path); 268 DCHECK(path);
236 base::AutoLock locker(lock_); 269 base::AutoLock locker(lock_);
237 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); 270 IDToInstance::const_iterator found = instance_map_.find(filesystem_id);
238 if (found == instance_map_.end() || !found->second->IsSinglePathInstance()) 271 if (found == instance_map_.end() || !found->second->IsSinglePathInstance())
239 return false; 272 return false;
240 *path = found->second->file_info().path; 273 *path = found->second->file_info().path;
241 return true; 274 return true;
242 } 275 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 uint32 random_data[4]; 417 uint32 random_data[4];
385 std::string id; 418 std::string id;
386 do { 419 do {
387 base::RandBytes(random_data, sizeof(random_data)); 420 base::RandBytes(random_data, sizeof(random_data));
388 id = base::HexEncode(random_data, sizeof(random_data)); 421 id = base::HexEncode(random_data, sizeof(random_data));
389 } while (instance_map_.find(id) != instance_map_.end()); 422 } while (instance_map_.find(id) != instance_map_.end());
390 return id; 423 return id;
391 } 424 }
392 425
393 } // namespace fileapi 426 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698