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

Side by Side Diff: webkit/fileapi/syncable/syncable_file_system_util.cc

Issue 15806012: Move webkit/fileapi/syncable/* code to webkit/browser/fileapi (final!) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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) 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/browser/fileapi/external_mount_points.h"
9 #include "webkit/browser/fileapi/file_observers.h"
10 #include "webkit/browser/fileapi/file_system_context.h"
11 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h"
12 #include "webkit/common/fileapi/file_system_util.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 kEnableSyncFSDirectoryOperation[] =
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 SetEnableSyncFSDirectoryOperation(bool flag) {
101 is_directory_operation_enabled = flag;
102 }
103
104 bool IsSyncFSDirectoryOperationEnabled() {
105 return is_directory_operation_enabled ||
106 CommandLine::ForCurrentProcess()->HasSwitch(
107 kEnableSyncFSDirectoryOperation);
108 }
109
110 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/syncable_file_system_util.h ('k') | webkit/fileapi/syncable/syncable_file_system_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698