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

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

Powered by Google App Engine
This is Rietveld 408576698