[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / syncable_file_system_util.cc
blob4e6e04bb167faaabfe1c3b064d38c7f03daf63fe
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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
7 #include <vector>
9 #include "base/command_line.h"
10 #include "base/location.h"
11 #include "base/strings/string_util.h"
12 #include "storage/browser/fileapi/external_mount_points.h"
13 #include "storage/browser/fileapi/file_observers.h"
14 #include "storage/browser/fileapi/file_system_context.h"
15 #include "storage/common/fileapi/file_system_util.h"
17 using storage::ExternalMountPoints;
18 using storage::FileSystemContext;
19 using storage::FileSystemURL;
21 namespace sync_file_system {
23 namespace {
25 const char kSyncableMountName[] = "syncfs";
26 const char kSyncableMountNameForInternalSync[] = "syncfs-internal";
28 const base::FilePath::CharType kSyncFileSystemDir[] =
29 FILE_PATH_LITERAL("Sync FileSystem");
31 void Noop() {}
33 } // namespace
35 void RegisterSyncableFileSystem() {
36 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
37 kSyncableMountName,
38 storage::kFileSystemTypeSyncable,
39 storage::FileSystemMountOption(),
40 base::FilePath());
41 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
42 kSyncableMountNameForInternalSync,
43 storage::kFileSystemTypeSyncableForInternalSync,
44 storage::FileSystemMountOption(),
45 base::FilePath());
48 void RevokeSyncableFileSystem() {
49 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
50 kSyncableMountName);
51 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
52 kSyncableMountNameForInternalSync);
55 GURL GetSyncableFileSystemRootURI(const GURL& origin) {
56 return GURL(
57 storage::GetExternalFileSystemRootURIString(origin, kSyncableMountName));
60 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin,
61 const base::FilePath& path) {
62 base::FilePath path_for_url = path;
63 if (storage::VirtualPath::IsAbsolute(path.value()))
64 path_for_url = base::FilePath(path.value().substr(1));
66 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL(
67 origin, kSyncableMountName, path_for_url);
70 FileSystemURL CreateSyncableFileSystemURLForSync(
71 storage::FileSystemContext* file_system_context,
72 const FileSystemURL& syncable_url) {
73 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL(
74 syncable_url.origin(),
75 kSyncableMountNameForInternalSync,
76 syncable_url.path());
79 bool SerializeSyncableFileSystemURL(const FileSystemURL& url,
80 std::string* serialized_url) {
81 if (!url.is_valid() || url.type() != storage::kFileSystemTypeSyncable)
82 return false;
83 *serialized_url =
84 GetSyncableFileSystemRootURI(url.origin()).spec() +
85 url.path().AsUTF8Unsafe();
86 return true;
89 bool DeserializeSyncableFileSystemURL(
90 const std::string& serialized_url, FileSystemURL* url) {
91 #if !defined(FILE_PATH_USES_WIN_SEPARATORS)
92 DCHECK(serialized_url.find('\\') == std::string::npos);
93 #endif // FILE_PATH_USES_WIN_SEPARATORS
95 FileSystemURL deserialized =
96 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url));
97 if (!deserialized.is_valid() ||
98 deserialized.type() != storage::kFileSystemTypeSyncable) {
99 return false;
102 *url = deserialized;
103 return true;
106 base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir) {
107 return profile_base_dir.Append(kSyncFileSystemDir);
110 void RunSoon(const tracked_objects::Location& from_here,
111 const base::Closure& callback) {
112 base::MessageLoop::current()->PostTask(from_here, callback);
115 base::Closure NoopClosure() {
116 return base::Bind(&Noop);
119 } // namespace sync_file_system