syncable_file_system_util.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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. 4 5#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 7 8#include <string> 9 10#include "base/files/file_path.h" 11#include "webkit/browser/fileapi/file_system_url.h" 12 13namespace fileapi { 14class FileSystemContext; 15class FileSystemURL; 16} 17 18namespace sync_file_system { 19 20// Registers a syncable filesystem. 21void RegisterSyncableFileSystem(); 22 23// Revokes the syncable filesystem. 24void RevokeSyncableFileSystem(); 25 26// Returns the root URI of the syncable filesystem for |origin|. 27GURL GetSyncableFileSystemRootURI(const GURL& origin); 28 29// Creates a FileSystem URL for the |path| in a syncable filesystem for 30// |origin|. 31// 32// Example: Assume following arguments are given: 33// origin: 'http://www.example.com/', 34// path: '/foo/bar', 35// returns 'filesystem:http://www.example.com/external/syncfs/foo/bar' 36fileapi::FileSystemURL 37CreateSyncableFileSystemURL(const GURL& origin, const base::FilePath& path); 38 39// Creates a special filesystem URL for synchronizing |syncable_url|. 40fileapi::FileSystemURL CreateSyncableFileSystemURLForSync( 41 fileapi::FileSystemContext* file_system_context, 42 const fileapi::FileSystemURL& syncable_url); 43 44// Serializes a given FileSystemURL |url| and sets the serialized string to 45// |serialized_url|. If the URL does not represent a syncable filesystem, 46// |serialized_url| is not filled in, and returns false. Separators of the 47// path will be normalized depending on its platform. 48// 49// Example: Assume a following FileSystemURL object is given: 50// origin() returns 'http://www.example.com/', 51// type() returns the kFileSystemTypeSyncable, 52// filesystem_id() returns 'syncfs', 53// path() returns '/foo/bar', 54// this URL will be serialized to 55// (on Windows) 56// 'filesystem:http://www.example.com/external/syncfs/foo\\bar' 57// (on others) 58// 'filesystem:http://www.example.com/external/syncfs/foo/bar' 59bool SerializeSyncableFileSystemURL( 60 const fileapi::FileSystemURL& url, std::string* serialized_url); 61 62// Deserializes a serialized FileSystem URL string |serialized_url| and sets the 63// deserialized value to |url|. If the reconstructed object is invalid or does 64// not represent a syncable filesystem, returns false. 65// 66// NOTE: On any platform other than Windows, this function assumes that 67// |serialized_url| does not contain '\\'. If it contains '\\' on such 68// platforms, '\\' may be replaced with '/' (It would not be an expected 69// behavior). 70// 71// See the comment of SerializeSyncableFileSystemURL() for more details. 72bool DeserializeSyncableFileSystemURL( 73 const std::string& serialized_url, fileapi::FileSystemURL* url); 74 75// Enables or disables directory operations in Sync FileSystem API. 76// TODO(nhiroki): This method should be used only for testing and should go 77// away when we fully support directory operations. (http://crbug.com/161442) 78void SetEnableSyncFSDirectoryOperation(bool flag); 79 80// Returns true if we allow directory operations in Sync FileSystem API. 81// It is disabled by default but can be overridden by a command-line switch 82// (--enable-syncfs-directory-operations) or by calling 83// SetEnableSyncFSDirectoryOperation(). 84// TODO(nhiroki): This method should be used only for testing and should go 85// away when we fully support directory operations. (http://crbug.com/161442) 86bool IsSyncFSDirectoryOperationEnabled(); 87 88// Returns SyncFileSystem sub-directory path. 89base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir); 90 91// Enables directory operation for syncable filesystems temporarily for testing. 92class ScopedEnableSyncFSDirectoryOperation { 93 public: 94 ScopedEnableSyncFSDirectoryOperation(); 95 ~ScopedEnableSyncFSDirectoryOperation(); 96 97 private: 98 bool was_enabled_; 99 100 DISALLOW_COPY_AND_ASSIGN(ScopedEnableSyncFSDirectoryOperation); 101}; 102 103} // namespace sync_file_system 104 105#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 106