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

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

Issue 6426001: Add 1st cut of FileSystemUsageTracker that tracks the usage changes in FileSystem API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix for win Created 9 years, 10 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_path_manager.h ('k') | webkit/fileapi/file_system_usage_tracker.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_path_manager.h" 5 #include "webkit/fileapi/file_system_path_manager.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( 70 static const FilePath::CharType letters[] = FILE_PATH_LITERAL(
71 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); 71 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
72 FilePath::StringType unique(kFileSystemUniqueNamePrefix); 72 FilePath::StringType unique(kFileSystemUniqueNamePrefix);
73 for (int i = 0; i < kFileSystemUniqueLength; ++i) 73 for (int i = 0; i < kFileSystemUniqueLength; ++i)
74 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; 74 unique += letters[base::RandInt(0, arraysize(letters) - 2)];
75 return unique; 75 return unique;
76 } 76 }
77 77
78 static const char kExtensionScheme[] = "chrome-extension"; 78 static const char kExtensionScheme[] = "chrome-extension";
79 79
80 inline std::string GetFileSystemTypeString(fileapi::FileSystemType type) {
81 if (type == fileapi::kFileSystemTypeTemporary)
82 return fileapi::FileSystemPathManager::kTemporaryName;
83 else if (type == fileapi::kFileSystemTypePersistent)
84 return fileapi::FileSystemPathManager::kPersistentName;
85 return std::string();
86 }
87
80 } // anonymous namespace 88 } // anonymous namespace
81 89
82 class FileSystemPathManager::GetFileSystemRootPathTask 90 class FileSystemPathManager::GetFileSystemRootPathTask
83 : public base::RefCountedThreadSafe< 91 : public base::RefCountedThreadSafe<
84 FileSystemPathManager::GetFileSystemRootPathTask> { 92 FileSystemPathManager::GetFileSystemRootPathTask> {
85 public: 93 public:
86 GetFileSystemRootPathTask( 94 GetFileSystemRootPathTask(
87 scoped_refptr<base::MessageLoopProxy> file_message_loop, 95 scoped_refptr<base::MessageLoopProxy> file_message_loop,
88 const std::string& name, 96 const std::string& name,
89 FileSystemPathManager::GetRootPathCallback* callback) 97 FileSystemPathManager::GetRootPathCallback* callback)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // TODO(kinuko): return an isolated temporary directory. 199 // TODO(kinuko): return an isolated temporary directory.
192 callback->Run(false, FilePath(), std::string()); 200 callback->Run(false, FilePath(), std::string());
193 return; 201 return;
194 } 202 }
195 203
196 if (!IsAllowedScheme(origin_url)) { 204 if (!IsAllowedScheme(origin_url)) {
197 callback->Run(false, FilePath(), std::string()); 205 callback->Run(false, FilePath(), std::string());
198 return; 206 return;
199 } 207 }
200 208
201 if (type != fileapi::kFileSystemTypeTemporary && 209 FilePath origin_base_path = GetFileSystemBaseDirectoryForOriginAndType(
202 type != fileapi::kFileSystemTypePersistent) { 210 base_path(), origin_url, type);
203 LOG(WARNING) << "Unknown filesystem type is requested:" << type; 211 if (origin_base_path.empty()) {
204 callback->Run(false, FilePath(), std::string()); 212 callback->Run(false, FilePath(), std::string());
205 return; 213 return;
206 } 214 }
207 215
208 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url);
209
210 std::string type_string;
211 if (type == fileapi::kFileSystemTypeTemporary)
212 type_string = kTemporaryName;
213 else if (type == fileapi::kFileSystemTypePersistent)
214 type_string = kPersistentName;
215 DCHECK(!type_string.empty());
216
217 FilePath origin_base_path = base_path_.AppendASCII(storage_identifier)
218 .AppendASCII(type_string);
219 std::string name = storage_identifier + ":" + type_string;
220
221 scoped_refptr<GetFileSystemRootPathTask> task( 216 scoped_refptr<GetFileSystemRootPathTask> task(
222 new GetFileSystemRootPathTask(file_message_loop_, 217 new GetFileSystemRootPathTask(file_message_loop_,
223 name, callback.release())); 218 GetFileSystemName(origin_url, type),
219 callback.release()));
224 task->Start(origin_url, origin_base_path, create); 220 task->Start(origin_url, origin_base_path, create);
225 } 221 }
226 222
227 bool FileSystemPathManager::CrackFileSystemPath( 223 bool FileSystemPathManager::CrackFileSystemPath(
228 const FilePath& path, GURL* origin_url, FileSystemType* type, 224 const FilePath& path, GURL* origin_url, FileSystemType* type,
229 FilePath* virtual_path) const { 225 FilePath* virtual_path) const {
230 // Any paths that includes parent references are considered invalid. 226 // Any paths that includes parent references are considered invalid.
231 if (path.ReferencesParent()) 227 if (path.ReferencesParent())
232 return false; 228 return false;
233 229
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 315 }
320 316
321 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { 317 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const {
322 // Basically we only accept http or https. We allow file:// URLs 318 // Basically we only accept http or https. We allow file:// URLs
323 // only if --allow-file-access-from-files flag is given. 319 // only if --allow-file-access-from-files flag is given.
324 return url.SchemeIs("http") || url.SchemeIs("https") || 320 return url.SchemeIs("http") || url.SchemeIs("https") ||
325 url.SchemeIs(kExtensionScheme) || 321 url.SchemeIs(kExtensionScheme) ||
326 (url.SchemeIsFile() && allow_file_access_from_files_); 322 (url.SchemeIsFile() && allow_file_access_from_files_);
327 } 323 }
328 324
325 // static
326 std::string FileSystemPathManager::GetFileSystemName(
327 const GURL& origin_url, fileapi::FileSystemType type) {
328 return GetStorageIdentifierFromURL(origin_url)
329 .append(":").append(GetFileSystemTypeString(type));
330 }
331
332 // static
329 std::string FileSystemPathManager::GetStorageIdentifierFromURL( 333 std::string FileSystemPathManager::GetStorageIdentifierFromURL(
330 const GURL& url) { 334 const GURL& url) {
331 WebKit::WebSecurityOrigin web_security_origin = 335 WebKit::WebSecurityOrigin web_security_origin =
332 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); 336 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec()));
333 return web_security_origin.databaseIdentifier().utf8(); 337 return web_security_origin.databaseIdentifier().utf8();
334 } 338 }
335 339
340 // static
341 FilePath FileSystemPathManager::GetFileSystemBaseDirectoryForOriginAndType(
342 const FilePath& base_path, const GURL& origin_url,
343 fileapi::FileSystemType type) {
344 if (!origin_url.is_valid())
345 return FilePath();
346 std::string type_string = GetFileSystemTypeString(type);
347 if (type_string.empty()) {
348 LOG(WARNING) << "Unknown filesystem type is requested:" << type;
349 return FilePath();
350 }
351 return base_path.AppendASCII(GetStorageIdentifierFromURL(origin_url))
352 .AppendASCII(type_string);
353 }
354
336 } // namespace fileapi 355 } // namespace fileapi
337 356
338 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ 357 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \
339 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); 358 int(fileapi::kFileSystemTypeTemporary), mismatching_enums);
340 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ 359 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \
341 int(fileapi::kFileSystemTypePersistent), mismatching_enums); 360 int(fileapi::kFileSystemTypePersistent), mismatching_enums);
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_path_manager.h ('k') | webkit/fileapi/file_system_usage_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698