1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_
#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_
#include <string>
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "webkit/browser/fileapi/file_system_url.h"
namespace fileapi {
class FileSystemContext;
class FileSystemURL;
}
namespace tracked_objects {
class Location;
}
namespace sync_file_system {
// Registers a syncable filesystem.
void RegisterSyncableFileSystem();
// Revokes the syncable filesystem.
void RevokeSyncableFileSystem();
// Returns the root URI of the syncable filesystem for |origin|.
GURL GetSyncableFileSystemRootURI(const GURL& origin);
// Creates a FileSystem URL for the |path| in a syncable filesystem for
// |origin|.
//
// Example: Assume following arguments are given:
// origin: 'http://www.example.com/',
// path: '/foo/bar',
// returns 'filesystem:http://www.example.com/external/syncfs/foo/bar'
fileapi::FileSystemURL
CreateSyncableFileSystemURL(const GURL& origin, const base::FilePath& path);
// Creates a special filesystem URL for synchronizing |syncable_url|.
fileapi::FileSystemURL CreateSyncableFileSystemURLForSync(
fileapi::FileSystemContext* file_system_context,
const fileapi::FileSystemURL& syncable_url);
// Serializes a given FileSystemURL |url| and sets the serialized string to
// |serialized_url|. If the URL does not represent a syncable filesystem,
// |serialized_url| is not filled in, and returns false. Separators of the
// path will be normalized depending on its platform.
//
// Example: Assume a following FileSystemURL object is given:
// origin() returns 'http://www.example.com/',
// type() returns the kFileSystemTypeSyncable,
// filesystem_id() returns 'syncfs',
// path() returns '/foo/bar',
// this URL will be serialized to
// (on Windows)
// 'filesystem:http://www.example.com/external/syncfs/foo\\bar'
// (on others)
// 'filesystem:http://www.example.com/external/syncfs/foo/bar'
bool SerializeSyncableFileSystemURL(
const fileapi::FileSystemURL& url, std::string* serialized_url);
// Deserializes a serialized FileSystem URL string |serialized_url| and sets the
// deserialized value to |url|. If the reconstructed object is invalid or does
// not represent a syncable filesystem, returns false.
//
// NOTE: On any platform other than Windows, this function assumes that
// |serialized_url| does not contain '\\'. If it contains '\\' on such
// platforms, '\\' may be replaced with '/' (It would not be an expected
// behavior).
//
// See the comment of SerializeSyncableFileSystemURL() for more details.
bool DeserializeSyncableFileSystemURL(
const std::string& serialized_url, fileapi::FileSystemURL* url);
// Enables or disables directory operations in Sync FileSystem API.
// TODO(nhiroki): This method should be used only for testing and should go
// away when we fully support directory operations. (http://crbug.com/161442)
void SetEnableSyncFSDirectoryOperation(bool flag);
// Returns true if we allow directory operations in Sync FileSystem API.
// It is disabled by default but can be overridden by a command-line switch
// (--enable-syncfs-directory-operations) or by calling
// SetEnableSyncFSDirectoryOperation().
// TODO(nhiroki): This method should be used only for testing and should go
// away when we fully support directory operations. (http://crbug.com/161442)
bool IsSyncFSDirectoryOperationEnabled();
// Checks the same as above, but takes |origin| and sees if directory operation
// is enabled specifically for this |origin|.
bool IsSyncFSDirectoryOperationEnabled(const GURL& origin);
// Returns true if V2 is enabled.
bool IsV2Enabled();
// Returns true if the given |origin| is supposed to run in V2 mode.
bool IsV2EnabledForOrigin(const GURL& origin);
// Returns SyncFileSystem sub-directory path.
base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir);
// Enables directory operation for syncable filesystems temporarily for testing.
class ScopedEnableSyncFSDirectoryOperation {
public:
ScopedEnableSyncFSDirectoryOperation();
~ScopedEnableSyncFSDirectoryOperation();
private:
bool was_enabled_;
DISALLOW_COPY_AND_ASSIGN(ScopedEnableSyncFSDirectoryOperation);
};
// Enables V2 backend for syncable filesystems temporarily for testing.
class ScopedEnableSyncFSV2 {
public:
ScopedEnableSyncFSV2();
~ScopedEnableSyncFSV2();
private:
bool was_enabled_;
DISALLOW_COPY_AND_ASSIGN(ScopedEnableSyncFSV2);
};
// Posts |callback| to the current thread.
void RunSoon(const tracked_objects::Location& from_here,
const base::Closure& callback);
} // namespace sync_file_system
#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_
|