| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/sync_file_system/syncable_file_system_util.h" | 5 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "webkit/browser/fileapi/external_mount_points.h" | 12 #include "webkit/browser/fileapi/external_mount_points.h" |
| 13 #include "webkit/browser/fileapi/file_observers.h" | 13 #include "webkit/browser/fileapi/file_observers.h" |
| 14 #include "webkit/browser/fileapi/file_system_context.h" | 14 #include "webkit/browser/fileapi/file_system_context.h" |
| 15 #include "webkit/common/fileapi/file_system_util.h" | 15 #include "webkit/common/fileapi/file_system_util.h" |
| 16 | 16 |
| 17 using fileapi::ExternalMountPoints; | 17 using storage::ExternalMountPoints; |
| 18 using fileapi::FileSystemContext; | 18 using storage::FileSystemContext; |
| 19 using fileapi::FileSystemURL; | 19 using storage::FileSystemURL; |
| 20 | 20 |
| 21 namespace sync_file_system { | 21 namespace sync_file_system { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kSyncableMountName[] = "syncfs"; | 25 const char kSyncableMountName[] = "syncfs"; |
| 26 const char kSyncableMountNameForInternalSync[] = "syncfs-internal"; | 26 const char kSyncableMountNameForInternalSync[] = "syncfs-internal"; |
| 27 | 27 |
| 28 const base::FilePath::CharType kSyncFileSystemDir[] = | 28 const base::FilePath::CharType kSyncFileSystemDir[] = |
| 29 FILE_PATH_LITERAL("Sync FileSystem"); | 29 FILE_PATH_LITERAL("Sync FileSystem"); |
| 30 | 30 |
| 31 void Noop() {} | 31 void Noop() {} |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 void RegisterSyncableFileSystem() { | 35 void RegisterSyncableFileSystem() { |
| 36 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 36 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 37 kSyncableMountName, | 37 kSyncableMountName, |
| 38 fileapi::kFileSystemTypeSyncable, | 38 storage::kFileSystemTypeSyncable, |
| 39 fileapi::FileSystemMountOption(), | 39 storage::FileSystemMountOption(), |
| 40 base::FilePath()); | 40 base::FilePath()); |
| 41 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 41 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 42 kSyncableMountNameForInternalSync, | 42 kSyncableMountNameForInternalSync, |
| 43 fileapi::kFileSystemTypeSyncableForInternalSync, | 43 storage::kFileSystemTypeSyncableForInternalSync, |
| 44 fileapi::FileSystemMountOption(), | 44 storage::FileSystemMountOption(), |
| 45 base::FilePath()); | 45 base::FilePath()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void RevokeSyncableFileSystem() { | 48 void RevokeSyncableFileSystem() { |
| 49 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( | 49 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
| 50 kSyncableMountName); | 50 kSyncableMountName); |
| 51 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( | 51 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
| 52 kSyncableMountNameForInternalSync); | 52 kSyncableMountNameForInternalSync); |
| 53 } | 53 } |
| 54 | 54 |
| 55 GURL GetSyncableFileSystemRootURI(const GURL& origin) { | 55 GURL GetSyncableFileSystemRootURI(const GURL& origin) { |
| 56 return GURL(fileapi::GetExternalFileSystemRootURIString( | 56 return GURL( |
| 57 origin, kSyncableMountName)); | 57 storage::GetExternalFileSystemRootURIString(origin, kSyncableMountName)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin, | 60 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin, |
| 61 const base::FilePath& path) { | 61 const base::FilePath& path) { |
| 62 base::FilePath path_for_url = path; | 62 base::FilePath path_for_url = path; |
| 63 if (fileapi::VirtualPath::IsAbsolute(path.value())) | 63 if (storage::VirtualPath::IsAbsolute(path.value())) |
| 64 path_for_url = base::FilePath(path.value().substr(1)); | 64 path_for_url = base::FilePath(path.value().substr(1)); |
| 65 | 65 |
| 66 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL( | 66 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL( |
| 67 origin, kSyncableMountName, path_for_url); | 67 origin, kSyncableMountName, path_for_url); |
| 68 } | 68 } |
| 69 | 69 |
| 70 FileSystemURL CreateSyncableFileSystemURLForSync( | 70 FileSystemURL CreateSyncableFileSystemURLForSync( |
| 71 fileapi::FileSystemContext* file_system_context, | 71 storage::FileSystemContext* file_system_context, |
| 72 const FileSystemURL& syncable_url) { | 72 const FileSystemURL& syncable_url) { |
| 73 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL( | 73 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL( |
| 74 syncable_url.origin(), | 74 syncable_url.origin(), |
| 75 kSyncableMountNameForInternalSync, | 75 kSyncableMountNameForInternalSync, |
| 76 syncable_url.path()); | 76 syncable_url.path()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool SerializeSyncableFileSystemURL(const FileSystemURL& url, | 79 bool SerializeSyncableFileSystemURL(const FileSystemURL& url, |
| 80 std::string* serialized_url) { | 80 std::string* serialized_url) { |
| 81 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeSyncable) | 81 if (!url.is_valid() || url.type() != storage::kFileSystemTypeSyncable) |
| 82 return false; | 82 return false; |
| 83 *serialized_url = | 83 *serialized_url = |
| 84 GetSyncableFileSystemRootURI(url.origin()).spec() + | 84 GetSyncableFileSystemRootURI(url.origin()).spec() + |
| 85 url.path().AsUTF8Unsafe(); | 85 url.path().AsUTF8Unsafe(); |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool DeserializeSyncableFileSystemURL( | 89 bool DeserializeSyncableFileSystemURL( |
| 90 const std::string& serialized_url, FileSystemURL* url) { | 90 const std::string& serialized_url, FileSystemURL* url) { |
| 91 #if !defined(FILE_PATH_USES_WIN_SEPARATORS) | 91 #if !defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 92 DCHECK(serialized_url.find('\\') == std::string::npos); | 92 DCHECK(serialized_url.find('\\') == std::string::npos); |
| 93 #endif // FILE_PATH_USES_WIN_SEPARATORS | 93 #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 94 | 94 |
| 95 FileSystemURL deserialized = | 95 FileSystemURL deserialized = |
| 96 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url)); | 96 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url)); |
| 97 if (!deserialized.is_valid() || | 97 if (!deserialized.is_valid() || |
| 98 deserialized.type() != fileapi::kFileSystemTypeSyncable) { | 98 deserialized.type() != storage::kFileSystemTypeSyncable) { |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 *url = deserialized; | 102 *url = deserialized; |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir) { | 106 base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir) { |
| 107 return profile_base_dir.Append(kSyncFileSystemDir); | 107 return profile_base_dir.Append(kSyncFileSystemDir); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void RunSoon(const tracked_objects::Location& from_here, | 110 void RunSoon(const tracked_objects::Location& from_here, |
| 111 const base::Closure& callback) { | 111 const base::Closure& callback) { |
| 112 base::MessageLoop::current()->PostTask(from_here, callback); | 112 base::MessageLoop::current()->PostTask(from_here, callback); |
| 113 } | 113 } |
| 114 | 114 |
| 115 base::Closure NoopClosure() { | 115 base::Closure NoopClosure() { |
| 116 return base::Bind(&Noop); | 116 return base::Bind(&Noop); |
| 117 } | 117 } |
| 118 | 118 |
| 119 } // namespace sync_file_system | 119 } // namespace sync_file_system |
| OLD | NEW |