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

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

Issue 9004019: Cleanup: Removing FileSystemPathManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/file_system_path_manager.h"
6
7 #include "base/rand_util.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_callback_factory.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h"
12 #include "base/message_loop_proxy.h"
13 #include "base/stringprintf.h"
14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h"
16 #include "googleurl/src/gurl.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h"
18 #include "webkit/fileapi/file_system_util.h"
19 #include "webkit/fileapi/sandbox_mount_point_provider.h"
20 #include "webkit/glue/webkit_glue.h"
21
22 #if defined(OS_CHROMEOS)
23 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
24 #endif
25
26 // We use some of WebKit types for conversions between origin identifiers
27 // and origin URLs.
28 using WebKit::WebFileSystem;
29
30 using base::PlatformFileError;
31
32 static const char kChromeScheme[] = "chrome";
33 static const char kExtensionScheme[] = "chrome-extension";
34
35 namespace fileapi {
36
37 FileSystemPathManager::FileSystemPathManager(
38 scoped_refptr<base::MessageLoopProxy> file_message_loop,
39 const FilePath& profile_path,
40 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy,
41 bool is_incognito,
42 bool allow_file_access_from_files)
43 : is_incognito_(is_incognito),
44 allow_file_access_from_files_(allow_file_access_from_files),
45 sandbox_provider_(
46 new SandboxMountPointProvider(
47 ALLOW_THIS_IN_INITIALIZER_LIST(this),
48 file_message_loop,
49 profile_path)) {
50 #if defined(OS_CHROMEOS)
51 external_provider_.reset(
52 new chromeos::CrosMountPointProvider(special_storage_policy));
53 #endif
54 }
55
56 FileSystemPathManager::~FileSystemPathManager() {}
57
58 void FileSystemPathManager::ValidateFileSystemRootAndGetURL(
59 const GURL& origin_url, fileapi::FileSystemType type, bool create,
60 const GetRootPathCallback& callback) {
61 FileSystemMountPointProvider* mount_point_provider =
62 GetMountPointProvider(type);
63 if (!mount_point_provider) {
64 callback.Run(false, FilePath(), std::string());
65 return;
66 }
67 mount_point_provider->ValidateFileSystemRootAndGetURL(
68 origin_url, type, create, callback);
69 }
70
71 FilePath FileSystemPathManager::ValidateFileSystemRootAndGetPathOnFileThread(
72 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path,
73 bool create) {
74 FileSystemMountPointProvider* mount_point_provider =
75 GetMountPointProvider(type);
76 if (!mount_point_provider)
77 return FilePath();
78 return mount_point_provider->ValidateFileSystemRootAndGetPathOnFileThread(
79 origin_url, type, virtual_path, create);
80 }
81
82 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const {
83 // Basically we only accept http or https. We allow file:// URLs
84 // only if --allow-file-access-from-files flag is given.
85 return url.SchemeIs("http") || url.SchemeIs("https") ||
86 url.SchemeIs(kExtensionScheme) || url.SchemeIs(kChromeScheme) ||
87 (url.SchemeIsFile() && allow_file_access_from_files_);
88 }
89
90 // static
91 std::string FileSystemPathManager::GetFileSystemTypeString(
92 fileapi::FileSystemType type) {
93 if (type == fileapi::kFileSystemTypeTemporary)
94 return fileapi::kTemporaryName;
95 else if (type == fileapi::kFileSystemTypePersistent)
96 return fileapi::kPersistentName;
97 else if (type == fileapi::kFileSystemTypeExternal)
98 return fileapi::kExternalName;
99 return std::string();
100 }
101
102 // Checks if a given |name| contains any restricted names/chars in it.
103 bool FileSystemPathManager::IsRestrictedFileName(
104 FileSystemType type, const FilePath& filename) {
105 FileSystemMountPointProvider* mount_point_provider =
106 GetMountPointProvider(type);
107 if (!mount_point_provider)
108 return true;
109 return mount_point_provider->IsRestrictedFileName(filename);
110 }
111
112 // Checks if an origin has access to a particular filesystem type.
113 bool FileSystemPathManager::IsAccessAllowed(
114 const GURL& origin, FileSystemType type, const FilePath& virtual_path) {
115 FileSystemMountPointProvider* mount_point_provider =
116 GetMountPointProvider(type);
117 DCHECK(mount_point_provider);
118 return mount_point_provider->IsAccessAllowed(origin, type, virtual_path);
119 }
120
121 FileSystemFileUtil* FileSystemPathManager::GetFileUtil(
122 FileSystemType type) const {
123 FileSystemMountPointProvider* mount_point_provider =
124 GetMountPointProvider(type);
125 DCHECK(mount_point_provider);
126 return mount_point_provider->GetFileUtil();
127 }
128
129 FileSystemMountPointProvider* FileSystemPathManager::GetMountPointProvider(
130 FileSystemType type) const {
131 switch (type) {
132 case kFileSystemTypeTemporary:
133 case kFileSystemTypePersistent:
134 return sandbox_provider();
135 case kFileSystemTypeExternal:
136 return external_provider();
137 case kFileSystemTypeUnknown:
138 default:
139 NOTREACHED();
140 return NULL;
141 }
142 }
143
144 } // namespace fileapi
145
146 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \
147 int(fileapi::kFileSystemTypeTemporary), mismatching_enums);
148 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \
149 int(fileapi::kFileSystemTypePersistent), mismatching_enums);
150 COMPILE_ASSERT(int(WebFileSystem::TypeExternal) == \
151 int(fileapi::kFileSystemTypeExternal), mismatching_enums);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698