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) 104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/callback_forward.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_url.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemContext; 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FileSystemURL; 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace tracked_objects { 204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class Location; 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace sync_file_system { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Registers a syncable filesystem. 262385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochvoid RegisterSyncableFileSystem(); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Revokes the syncable filesystem. 292385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochvoid RevokeSyncableFileSystem(); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Returns the root URI of the syncable filesystem for |origin|. 322385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen MurdochGURL GetSyncableFileSystemRootURI(const GURL& origin); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Creates a FileSystem URL for the |path| in a syncable filesystem for 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// |origin|. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Example: Assume following arguments are given: 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// origin: 'http://www.example.com/', 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// path: '/foo/bar', 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// returns 'filesystem:http://www.example.com/external/syncfs/foo/bar' 4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)storage::FileSystemURL CreateSyncableFileSystemURL(const GURL& origin, 4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const base::FilePath& path); 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Creates a special filesystem URL for synchronizing |syncable_url|. 4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)storage::FileSystemURL CreateSyncableFileSystemURLForSync( 4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemContext* file_system_context, 4703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const storage::FileSystemURL& syncable_url); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Serializes a given FileSystemURL |url| and sets the serialized string to 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |serialized_url|. If the URL does not represent a syncable filesystem, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |serialized_url| is not filled in, and returns false. Separators of the 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// path will be normalized depending on its platform. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Example: Assume a following FileSystemURL object is given: 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// origin() returns 'http://www.example.com/', 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// type() returns the kFileSystemTypeSyncable, 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// filesystem_id() returns 'syncfs', 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// path() returns '/foo/bar', 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this URL will be serialized to 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (on Windows) 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// 'filesystem:http://www.example.com/external/syncfs/foo\\bar' 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (on others) 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// 'filesystem:http://www.example.com/external/syncfs/foo/bar' 6403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)bool SerializeSyncableFileSystemURL(const storage::FileSystemURL& url, 6503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) std::string* serialized_url); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Deserializes a serialized FileSystem URL string |serialized_url| and sets the 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// deserialized value to |url|. If the reconstructed object is invalid or does 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// not represent a syncable filesystem, returns false. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: On any platform other than Windows, this function assumes that 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |serialized_url| does not contain '\\'. If it contains '\\' on such 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// platforms, '\\' may be replaced with '/' (It would not be an expected 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// behavior). 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See the comment of SerializeSyncableFileSystemURL() for more details. 7703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)bool DeserializeSyncableFileSystemURL(const std::string& serialized_url, 7803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemURL* url); 79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Returns SyncFileSystem sub-directory path. 81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)base::FilePath GetSyncFileSystemDir(const base::FilePath& profile_base_dir); 82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Posts |callback| to the current thread. 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void RunSoon(const tracked_objects::Location& from_here, 854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const base::Closure& callback); 864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)base::Closure NoopClosure(); 885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace sync_file_system 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 912385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNCABLE_FILE_SYSTEM_UTIL_H_ 92