Support SizeClassIdiom on iOS7.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / syncable_file_system_util.cc
blob6f2aaf2360fdf44d7993d112e31e72af3a5b3ae8
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/single_thread_task_runner.h"
12 #include "base/strings/string_util.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "storage/browser/fileapi/external_mount_points.h"
15 #include "storage/browser/fileapi/file_observers.h"
16 #include "storage/browser/fileapi/file_system_context.h"
17 #include "storage/common/fileapi/file_system_util.h"
19 using storage::ExternalMountPoints;
20 using storage::FileSystemContext;
21 using storage::FileSystemURL;
23 namespace sync_file_system {
25 namespace {
27 const char kSyncableMountName[] = "syncfs";
28 const char kSyncableMountNameForInternalSync[] = "syncfs-internal";
30 const base::FilePath::CharType kSyncFileSystemDir[] =
31 FILE_PATH_LITERAL("Sync FileSystem");
33 void Noop() {}
35 } // namespace
37 void RegisterSyncableFileSystem() {
38 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
39 kSyncableMountName,
40 storage::kFileSystemTypeSyncable,
41 storage::FileSystemMountOption(),
42 base::FilePath());
43 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
44 kSyncableMountNameForInternalSync,
45 storage::kFileSystemTypeSyncableForInternalSync,
46 storage::FileSystemMountOption(),
47 base::FilePath());
50 void RevokeSyncableFileSystem() {
51 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
52 kSyncableMountName);
53 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
54 kSyncableMountNameForInternalSync);
57 GURL GetSyncableFileSystemRootURI(const GURL& origin) {
58 return GURL(
59 storage::GetExternalFileSystemRootURIString(origin, kSyncableMountName));
62 FileSystemURL CreateSyncableFileSystemURL(const GURL& origin,
63 const base::FilePath& path) {
64 base::FilePath path_for_url = path;
65 if (storage::VirtualPath::IsAbsolute(path.value()))
66 path_for_url = base::FilePath(path.value().substr(1));
68 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL(
69 origin, kSyncableMountName, path_for_url);
72 FileSystemURL CreateSyncableFileSystemURLForSync(
73 storage::FileSystemContext* file_system_context,
74 const FileSystemURL& syncable_url) {
75 return ExternalMountPoints::GetSystemInstance()->CreateExternalFileSystemURL(
76 syncable_url.origin(),
77 kSyncableMountNameForInternalSync,
78 syncable_url.path());
81 bool SerializeSyncableFileSystemURL(const FileSystemURL& url,
82 std::string* serialized_url) {
83 if (!url.is_valid() || url.type() != storage::kFileSystemTypeSyncable)
84 return false;
85 *serialized_url =
86 GetSyncableFileSystemRootURI(url.origin()).spec() +
87 url.path().AsUTF8Unsafe();
88 return true;
91 bool DeserializeSyncableFileSystemURL(
92 const std::string& serialized_url, FileSystemURL* url) {
93 #if !defined(FILE_PATH_USES_WIN_SEPARATORS)
94 DCHECK(serialized_url.find('\\') == std::string::npos);
95 #endif // FILE_PATH_USES_WIN_SEPARATORS
97 FileSystemURL deserialized =
98 ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(serialized_url));
99 if (!deserialized.is_valid() ||
100 deserialized.type() != storage::kFileSystemTypeSyncable) {
101 return false;
104 *url = deserialized;
105 return true;
108 base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir) {
109 return profile_base_dir.Append(kSyncFileSystemDir);
112 void RunSoon(const tracked_objects::Location& from_here,
113 const base::Closure& callback) {
114 base::ThreadTaskRunnerHandle::Get()->PostTask(from_here, callback);
117 base::Closure NoopClosure() {
118 return base::Bind(&Noop);
121 } // namespace sync_file_system