| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "webkit/fileapi/external_mount_points.h" | |
| 9 #include "webkit/fileapi/file_observers.h" | |
| 10 #include "webkit/fileapi/file_system_context.h" | |
| 11 #include "webkit/fileapi/file_system_util.h" | |
| 12 #include "webkit/fileapi/sandbox_mount_point_provider.h" | |
| 13 | |
| 14 using fileapi::ExternalMountPoints; | |
| 15 using fileapi::FileSystemContext; | |
| 16 using fileapi::FileSystemURL; | |
| 17 using fileapi::LocalFileSystemOperation; | |
| 18 | |
| 19 namespace sync_file_system { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // A command switch to enable syncing directory operations in Sync FileSystem | |
| 24 // API. (http://crbug.com/161442) | |
| 25 // TODO(kinuko): this command-line switch should be temporary. | |
| 26 const char kEnableSyncDirectoryOperation[] = | |
| 27 "enable-syncfs-directory-operation"; | |
| 28 | |
| 29 bool is_directory_operation_enabled = false; | |
| 30 | |
| 31 } | |
| 32 | |
| 33 bool RegisterSyncableFileSystem(const std::string& service_name) { | |
| 34 return ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | |
| 35 service_name, fileapi::kFileSystemTypeSyncable, base::FilePath()); | |
| 36 } | |
| 37 | |
| 38 bool RevokeSyncableFileSystem(const std::string& service_name) { | |
| 39 return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( | |
| 40 service_name); | |
| 41 } | |
| 42 | |
| 43 GURL GetSyncableFileSystemRootURI(const GURL& origin, | |
| 44 const std::string& service_name) { | |
| 45 const GURL url = GetFileSystemRootURI(origin, | |
| 46 fileapi::kFileSystemTypeExternal); | |
| 47 const std::string path = service_name + "/"; | |
| 48 url_canon::Replacements<char> replacements; | |
| 49 replacements.SetPath(path.c_str(), url_parse::Component(0, path.length())); | |
| 50 return url.ReplaceComponents(replacements); | |
| 51 } | |
| 52 | |
| 53 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin, | |
| 54 const std::string& service_name, | |
| 55 const base::FilePath& path) { | |
| 56 // Avoid using FilePath::Append as path may be an absolute path. | |
| 57 base::FilePath::StringType virtual_path = | |
| 58 base::FilePath::FromUTF8Unsafe(service_name + "/").value() + | |
| 59 path.value(); | |
| 60 return ExternalMountPoints::GetSystemInstance()->CreateCrackedFileSystemURL( | |
| 61 origin, | |
| 62 fileapi::kFileSystemTypeExternal, | |
| 63 base::FilePath(virtual_path)); | |
| 64 } | |
| 65 | |
| 66 bool SerializeSyncableFileSystemURL(const FileSystemURL& url, | |
| 67 std::string* serialized_url) { | |
| 68 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeSyncable) | |
| 69 return false; | |
| 70 *serialized_url = | |
| 71 GetSyncableFileSystemRootURI(url.origin(), url.filesystem_id()).spec() + | |
| 72 url.path().AsUTF8Unsafe(); | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 bool DeserializeSyncableFileSystemURL( | |
| 77 const std::string& serialized_url, FileSystemURL* url) { | |
| 78 #if !defined(FILE_PATH_USES_WIN_SEPARATORS) | |
| 79 DCHECK(serialized_url.find('\\') == std::string::npos); | |
| 80 #endif // FILE_PATH_USES_WIN_SEPARATORS | |
| 81 | |
| 82 FileSystemURL deserialized = | |
| 83 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url)); | |
| 84 if (!deserialized.is_valid() || | |
| 85 deserialized.type() != fileapi::kFileSystemTypeSyncable) { | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 *url = deserialized; | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 LocalFileSystemOperation* CreateFileSystemOperationForSync( | |
| 94 FileSystemContext* file_system_context) { | |
| 95 DCHECK(file_system_context); | |
| 96 return file_system_context->sandbox_provider()-> | |
| 97 CreateFileSystemOperationForSync(file_system_context); | |
| 98 } | |
| 99 | |
| 100 void SetEnableSyncDirectoryOperation(bool flag) { | |
| 101 is_directory_operation_enabled = flag; | |
| 102 } | |
| 103 | |
| 104 bool IsSyncDirectoryOperationEnabled() { | |
| 105 return is_directory_operation_enabled || | |
| 106 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 107 kEnableSyncDirectoryOperation); | |
| 108 } | |
| 109 | |
| 110 } // namespace sync_file_system | |
| OLD | NEW |