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

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

Issue 12717014: Launch packaged app with files on Drive on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment of the new fs type. Created 7 years, 9 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/external_mount_points.h" 5 #include "webkit/fileapi/external_mount_points.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return false; 122 return false;
123 123
124 instance_map_[mount_name] = new Instance(type, path, remote_proxy); 124 instance_map_[mount_name] = new Instance(type, path, remote_proxy);
125 if (!path.empty()) 125 if (!path.empty())
126 path_to_name_map_.insert(std::make_pair(path, mount_name)); 126 path_to_name_map_.insert(std::make_pair(path, mount_name));
127 return true; 127 return true;
128 } 128 }
129 129
130 bool ExternalMountPoints::HandlesFileSystemMountType( 130 bool ExternalMountPoints::HandlesFileSystemMountType(
131 FileSystemType type) const { 131 FileSystemType type) const {
132 return type == kFileSystemTypeExternal; 132 return type == kFileSystemTypeExternal ||
133 type == kFileSystemTypeNativeForPlatformApp;
133 } 134 }
134 135
135 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) { 136 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) {
136 base::AutoLock locker(lock_); 137 base::AutoLock locker(lock_);
137 NameToInstance::iterator found = instance_map_.find(mount_name); 138 NameToInstance::iterator found = instance_map_.find(mount_name);
138 if (found == instance_map_.end()) 139 if (found == instance_map_.end())
139 return false; 140 return false;
140 Instance* instance = found->second; 141 Instance* instance = found->second;
141 path_to_name_map_.erase(NormalizeFilePath(instance->path())); 142 path_to_name_map_.erase(NormalizeFilePath(instance->path()));
142 delete found->second; 143 delete found->second;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 for (; component_iter != components.end(); ++component_iter) 197 for (; component_iter != components.end(); ++component_iter)
197 cracked_path = cracked_path.Append(*component_iter); 198 cracked_path = cracked_path.Append(*component_iter);
198 *path = cracked_path; 199 *path = cracked_path;
199 return true; 200 return true;
200 } 201 }
201 202
202 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const { 203 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const {
203 FileSystemURL filesystem_url = FileSystemURL(url); 204 FileSystemURL filesystem_url = FileSystemURL(url);
204 if (!filesystem_url.is_valid()) 205 if (!filesystem_url.is_valid())
205 return FileSystemURL(); 206 return FileSystemURL();
206 return CreateCrackedFileSystemURL(filesystem_url.origin(), 207 return CrackFileSystemURL(filesystem_url);
207 filesystem_url.mount_type(), 208 }
208 filesystem_url.path()); 209
210 FileSystemURL ExternalMountPoints::CrackFileSystemURL(
kinuko 2013/03/21 16:47:51 can you match the method order in .cc and in .h?
kinaba 2013/03/22 04:58:33 Done.
211 const FileSystemURL& url) const {
212 if (!HandlesFileSystemMountType(url.type()))
213 return FileSystemURL();
214
215 base::FilePath virtual_path = url.path();
216 if (url.type() == kFileSystemTypeNativeForPlatformApp) {
217 #if defined(OS_CHROMEOS)
218 // On Chrome OS, find a mount point and virtual path for the external fs.
219 if (!GetVirtualPath(url.path(), &virtual_path))
220 return FileSystemURL();
221 #else
222 // On other OS, it is simply a native local path.
223 return FileSystemURL(
224 url.origin(), url.mount_type(), url.virtual_path(),
225 url.mount_filesystem_id(), kFileSystemTypeNativeLocal,
226 url.path(), url.filesystem_id());
227 #endif
228 }
229
230 std::string mount_name;
231 FileSystemType cracked_type;
232 base::FilePath cracked_path;
233
234 if (!CrackVirtualPath(virtual_path, &mount_name, &cracked_type,
235 &cracked_path)) {
236 return FileSystemURL();
237 }
238
239 return FileSystemURL(
240 url.origin(), url.mount_type(), url.virtual_path(),
241 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name,
242 cracked_type, cracked_path, mount_name);
209 } 243 }
210 244
211 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL( 245 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL(
212 const GURL& origin, 246 const GURL& origin,
213 FileSystemType type, 247 FileSystemType type,
214 const base::FilePath& path) const { 248 const base::FilePath& path) const {
215 if (!HandlesFileSystemMountType(type)) 249 return CrackFileSystemURL(FileSystemURL(origin, type, path));
216 return FileSystemURL();
217
218 std::string mount_name;
219 FileSystemType cracked_type;
220 base::FilePath cracked_path;
221 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path))
222 return FileSystemURL();
223
224 return FileSystemURL(origin, type, path,
225 mount_name, cracked_type, cracked_path);
226 } 250 }
227 251
228 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( 252 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy(
229 const std::string& mount_name) const { 253 const std::string& mount_name) const {
230 base::AutoLock locker(lock_); 254 base::AutoLock locker(lock_);
231 NameToInstance::const_iterator found = instance_map_.find(mount_name); 255 NameToInstance::const_iterator found = instance_map_.find(mount_name);
232 if (found == instance_map_.end()) 256 if (found == instance_map_.end())
233 return NULL; 257 return NULL;
234 return found->second->remote_proxy(); 258 return found->second->remote_proxy();
235 } 259 }
236 260
237 void ExternalMountPoints::AddMountPointInfosTo( 261 void ExternalMountPoints::AddMountPointInfosTo(
238 std::vector<MountPointInfo>* mount_points) const { 262 std::vector<MountPointInfo>* mount_points) const {
239 base::AutoLock locker(lock_); 263 base::AutoLock locker(lock_);
240 DCHECK(mount_points); 264 DCHECK(mount_points);
241 for (NameToInstance::const_iterator iter = instance_map_.begin(); 265 for (NameToInstance::const_iterator iter = instance_map_.begin();
242 iter != instance_map_.end(); ++iter) { 266 iter != instance_map_.end(); ++iter) {
243 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); 267 mount_points->push_back(MountPointInfo(iter->first, iter->second->path()));
244 } 268 }
245 } 269 }
246 270
247 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in, 271 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in,
248 base::FilePath* virtual_path) { 272 base::FilePath* virtual_path) const {
249 DCHECK(virtual_path); 273 DCHECK(virtual_path);
250 274
251 base::AutoLock locker(lock_); 275 base::AutoLock locker(lock_);
252 276
253 base::FilePath path = NormalizeFilePath(path_in); 277 base::FilePath path = NormalizeFilePath(path_in);
254 std::map<base::FilePath, std::string>::reverse_iterator iter( 278 std::map<base::FilePath, std::string>::const_reverse_iterator iter(
255 path_to_name_map_.upper_bound(path)); 279 path_to_name_map_.upper_bound(path));
256 if (iter == path_to_name_map_.rend()) 280 if (iter == path_to_name_map_.rend())
257 return false; 281 return false;
258 282
259 *virtual_path = CreateVirtualRootPath(iter->second); 283 *virtual_path = CreateVirtualRootPath(iter->second);
260 if (iter->first == path) 284 if (iter->first == path)
261 return true; 285 return true;
262 return iter->first.AppendRelativePath(path, virtual_path); 286 return iter->first.AppendRelativePath(path, virtual_path);
263 } 287 }
264 288
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { 349 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const {
326 return ExternalMountPoints::GetSystemInstance()-> 350 return ExternalMountPoints::GetSystemInstance()->
327 CreateVirtualRootPath(mount_name_); 351 CreateVirtualRootPath(mount_name_);
328 } 352 }
329 353
330 ScopedExternalFileSystem::~ScopedExternalFileSystem() { 354 ScopedExternalFileSystem::~ScopedExternalFileSystem() {
331 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); 355 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_);
332 } 356 }
333 357
334 } // namespace fileapi 358 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698