syncable_file_system_util.h revision 2385ea399aae016c0806a4f9ef3c9cfe3d2a39df
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 62385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/browser/fileapi/file_system_url.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace fileapi { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemContext; 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FileSystemURL; 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace sync_file_system { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Registers a syncable filesystem. 212385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochvoid RegisterSyncableFileSystem(); 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Revokes the syncable filesystem. 242385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochvoid RevokeSyncableFileSystem(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Returns the root URI of the syncable filesystem for |origin|. 272385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen MurdochGURL GetSyncableFileSystemRootURI(const GURL& origin); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Creates a FileSystem URL for the |path| in a syncable filesystem for 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// |origin|. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Example: Assume following arguments are given: 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// origin: 'http://www.example.com/', 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// path: '/foo/bar', 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// returns 'filesystem:http://www.example.com/external/syncfs/foo/bar' 362385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochfileapi::FileSystemURL 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CreateSyncableFileSystemURL(const GURL& origin, const base::FilePath& path); 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Creates a special filesystem URL for synchronizing |syncable_url|. 402385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochfileapi::FileSystemURL CreateSyncableFileSystemURLForSync( 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) fileapi::FileSystemContext* file_system_context, 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const fileapi::FileSystemURL& syncable_url); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Serializes a given FileSystemURL |url| and sets the serialized string to 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |serialized_url|. If the URL does not represent a syncable filesystem, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |serialized_url| is not filled in, and returns false. Separators of the 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// path will be normalized depending on its platform. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Example: Assume a following FileSystemURL object is given: 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// origin() returns 'http://www.example.com/', 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// type() returns the kFileSystemTypeSyncable, 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// filesystem_id() returns 'syncfs', 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// path() returns '/foo/bar', 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this URL will be serialized to 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (on Windows) 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// 'filesystem:http://www.example.com/external/syncfs/foo\\bar' 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (on others) 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// 'filesystem:http://www.example.com/external/syncfs/foo/bar' 592385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochbool SerializeSyncableFileSystemURL( 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const fileapi::FileSystemURL& url, std::string* serialized_url); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Deserializes a serialized FileSystem URL string |serialized_url| and sets the 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// deserialized value to |url|. If the reconstructed object is invalid or does 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// not represent a syncable filesystem, returns false. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: On any platform other than Windows, this function assumes that 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |serialized_url| does not contain '\\'. If it contains '\\' on such 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// platforms, '\\' may be replaced with '/' (It would not be an expected 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// behavior). 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See the comment of SerializeSyncableFileSystemURL() for more details. 722385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochbool DeserializeSyncableFileSystemURL( 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& serialized_url, fileapi::FileSystemURL* url); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Enables or disables directory operations in Sync FileSystem API. 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(nhiroki): This method should be used only for testing and should go 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// away when we fully support directory operations. (http://crbug.com/161442) 782385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochvoid SetEnableSyncFSDirectoryOperation(bool flag); 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Returns true if we allow directory operations in Sync FileSystem API. 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// It is disabled by default but can be overridden by a command-line switch 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// (--enable-syncfs-directory-operations) or by calling 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// SetEnableSyncFSDirectoryOperation(). 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(nhiroki): This method should be used only for testing and should go 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// away when we fully support directory operations. (http://crbug.com/161442) 862385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochbool IsSyncFSDirectoryOperationEnabled(); 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Enables directory operation for syncable filesystems temporarily for testing. 892385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochclass ScopedEnableSyncFSDirectoryOperation { 90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch public: 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ScopedEnableSyncFSDirectoryOperation(); 92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ~ScopedEnableSyncFSDirectoryOperation(); 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private: 95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool was_enabled_; 96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DISALLOW_COPY_AND_ASSIGN(ScopedEnableSyncFSDirectoryOperation); 98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace sync_file_system 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1022385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 103