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

Side by Side Diff: chrome/browser/sync_file_system/syncable_file_system_util.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 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 "storage/browser/fileapi/external_mount_points.h"
13 #include "webkit/browser/fileapi/file_observers.h" 13 #include "storage/browser/fileapi/file_observers.h"
14 #include "webkit/browser/fileapi/file_system_context.h" 14 #include "storage/browser/fileapi/file_system_context.h"
15 #include "webkit/common/fileapi/file_system_util.h" 15 #include "storage/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 // A command switch to enable V2 Sync FileSystem. 25 // A command switch to enable V2 Sync FileSystem.
26 const char kEnableSyncFileSystemV2[] = "enable-syncfs-v2"; 26 const char kEnableSyncFileSystemV2[] = "enable-syncfs-v2";
27 27
28 // A command switch to specify comma-separated app IDs to enable V2 Sync 28 // A command switch to specify comma-separated app IDs to enable V2 Sync
29 // FileSystem. 29 // FileSystem.
30 const char kSyncFileSystemV2Whitelist[] = "syncfs-v2-whitelist"; 30 const char kSyncFileSystemV2Whitelist[] = "syncfs-v2-whitelist";
31 31
32 const char kSyncableMountName[] = "syncfs"; 32 const char kSyncableMountName[] = "syncfs";
33 const char kSyncableMountNameForInternalSync[] = "syncfs-internal"; 33 const char kSyncableMountNameForInternalSync[] = "syncfs-internal";
34 34
35 const base::FilePath::CharType kSyncFileSystemDir[] = 35 const base::FilePath::CharType kSyncFileSystemDir[] =
36 FILE_PATH_LITERAL("Sync FileSystem"); 36 FILE_PATH_LITERAL("Sync FileSystem");
37 37
38 // Flags to enable features for testing. 38 // Flags to enable features for testing.
39 bool g_is_syncfs_v2_enabled = true; 39 bool g_is_syncfs_v2_enabled = true;
40 40
41 void Noop() {} 41 void Noop() {}
42 42
43 } // namespace 43 } // namespace
44 44
45 void RegisterSyncableFileSystem() { 45 void RegisterSyncableFileSystem() {
46 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 46 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
47 kSyncableMountName, 47 kSyncableMountName,
48 fileapi::kFileSystemTypeSyncable, 48 storage::kFileSystemTypeSyncable,
49 fileapi::FileSystemMountOption(), 49 storage::FileSystemMountOption(),
50 base::FilePath()); 50 base::FilePath());
51 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 51 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
52 kSyncableMountNameForInternalSync, 52 kSyncableMountNameForInternalSync,
53 fileapi::kFileSystemTypeSyncableForInternalSync, 53 storage::kFileSystemTypeSyncableForInternalSync,
54 fileapi::FileSystemMountOption(), 54 storage::FileSystemMountOption(),
55 base::FilePath()); 55 base::FilePath());
56 } 56 }
57 57
58 void RevokeSyncableFileSystem() { 58 void RevokeSyncableFileSystem() {
59 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 59 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
60 kSyncableMountName); 60 kSyncableMountName);
61 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 61 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
62 kSyncableMountNameForInternalSync); 62 kSyncableMountNameForInternalSync);
63 } 63 }
64 64
65 GURL GetSyncableFileSystemRootURI(const GURL& origin) { 65 GURL GetSyncableFileSystemRootURI(const GURL& origin) {
66 return GURL(fileapi::GetExternalFileSystemRootURIString( 66 return GURL(
67 origin, kSyncableMountName)); 67 storage::GetExternalFileSystemRootURIString(origin, kSyncableMountName));
68 } 68 }
69 69
70 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin, 70 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin,
71 const base::FilePath& path) { 71 const base::FilePath& path) {
72 base::FilePath path_for_url = path; 72 base::FilePath path_for_url = path;
73 if (fileapi::VirtualPath::IsAbsolute(path.value())) 73 if (storage::VirtualPath::IsAbsolute(path.value()))
74 path_for_url = base::FilePath(path.value().substr(1)); 74 path_for_url = base::FilePath(path.value().substr(1));
75 75
76 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL( 76 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL(
77 origin, kSyncableMountName, path_for_url); 77 origin, kSyncableMountName, path_for_url);
78 } 78 }
79 79
80 FileSystemURL CreateSyncableFileSystemURLForSync( 80 FileSystemURL CreateSyncableFileSystemURLForSync(
81 fileapi::FileSystemContext* file_system_context, 81 storage::FileSystemContext* file_system_context,
82 const FileSystemURL& syncable_url) { 82 const FileSystemURL& syncable_url) {
83 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL( 83 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL(
84 syncable_url.origin(), 84 syncable_url.origin(),
85 kSyncableMountNameForInternalSync, 85 kSyncableMountNameForInternalSync,
86 syncable_url.path()); 86 syncable_url.path());
87 } 87 }
88 88
89 bool SerializeSyncableFileSystemURL(const FileSystemURL& url, 89 bool SerializeSyncableFileSystemURL(const FileSystemURL& url,
90 std::string* serialized_url) { 90 std::string* serialized_url) {
91 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeSyncable) 91 if (!url.is_valid() || url.type() != storage::kFileSystemTypeSyncable)
92 return false; 92 return false;
93 *serialized_url = 93 *serialized_url =
94 GetSyncableFileSystemRootURI(url.origin()).spec() + 94 GetSyncableFileSystemRootURI(url.origin()).spec() +
95 url.path().AsUTF8Unsafe(); 95 url.path().AsUTF8Unsafe();
96 return true; 96 return true;
97 } 97 }
98 98
99 bool DeserializeSyncableFileSystemURL( 99 bool DeserializeSyncableFileSystemURL(
100 const std::string& serialized_url, FileSystemURL* url) { 100 const std::string& serialized_url, FileSystemURL* url) {
101 #if !defined(FILE_PATH_USES_WIN_SEPARATORS) 101 #if !defined(FILE_PATH_USES_WIN_SEPARATORS)
102 DCHECK(serialized_url.find('\\') == std::string::npos); 102 DCHECK(serialized_url.find('\\') == std::string::npos);
103 #endif // FILE_PATH_USES_WIN_SEPARATORS 103 #endif // FILE_PATH_USES_WIN_SEPARATORS
104 104
105 FileSystemURL deserialized = 105 FileSystemURL deserialized =
106 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url)); 106 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url));
107 if (!deserialized.is_valid() || 107 if (!deserialized.is_valid() ||
108 deserialized.type() != fileapi::kFileSystemTypeSyncable) { 108 deserialized.type() != storage::kFileSystemTypeSyncable) {
109 return false; 109 return false;
110 } 110 }
111 111
112 *url = deserialized; 112 *url = deserialized;
113 return true; 113 return true;
114 } 114 }
115 115
116 bool IsV2Enabled() { 116 bool IsV2Enabled() {
117 return g_is_syncfs_v2_enabled || 117 return g_is_syncfs_v2_enabled ||
118 CommandLine::ForCurrentProcess()->HasSwitch(kEnableSyncFileSystemV2); 118 CommandLine::ForCurrentProcess()->HasSwitch(kEnableSyncFileSystemV2);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 void RunSoon(const tracked_objects::Location& from_here, 165 void RunSoon(const tracked_objects::Location& from_here,
166 const base::Closure& callback) { 166 const base::Closure& callback) {
167 base::MessageLoop::current()->PostTask(from_here, callback); 167 base::MessageLoop::current()->PostTask(from_here, callback);
168 } 168 }
169 169
170 base::Closure NoopClosure() { 170 base::Closure NoopClosure() {
171 return base::Bind(&Noop); 171 return base::Bind(&Noop);
172 } 172 }
173 173
174 } // namespace sync_file_system 174 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698