15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 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) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef WEBKIT_BROWSER_FILEAPI_NATIVE_FILE_UTIL_H_ 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define WEBKIT_BROWSER_FILEAPI_NATIVE_FILE_UTIL_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_util_proxy.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/platform_file.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/browser/fileapi/file_system_file_util.h" 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "webkit/browser/webkit_storage_browser_export.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Time; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace fileapi { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A thin wrapper class for accessing the OS native filesystem. 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This performs common error checks necessary to implement FileUtil family 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// in addition to perform native filesystem operations. 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// For the error checks it performs please see the comment for 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// FileSystemFileUtil interface 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// (webkit/browser/fileapi/file_system_file_util.h). 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Note that all the methods of this class are static and this does NOT 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// inherit from FileSystemFileUtil. 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE NativeFileUtil { 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 33d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) enum CopyOrMoveMode { 34d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) COPY_NOSYNC, 35d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) COPY_SYNC, 36d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) MOVE 37d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) }; 38d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) static CopyOrMoveMode CopyOrMoveModeForDestination( 39d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) const FileSystemURL& dest_url, bool copy); 40d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError CreateOrOpen( 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& path, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int file_flags, 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::PlatformFile* file_handle, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* created); 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError Close(base::PlatformFile file); 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError EnsureFileExists(const base::FilePath& path, 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool* created); 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError CreateDirectory(const base::FilePath& path, 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool exclusive, 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool recursive); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError GetFileInfo(const base::FilePath& path, 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::PlatformFileInfo* file_info); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateFileEnumerator(const base::FilePath& root_path, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool recursive); 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError Touch(const base::FilePath& path, 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Time& last_access_time, 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Time& last_modified_time); 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static base::PlatformFileError Truncate(const base::FilePath& path, 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int64 length); 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool PathExists(const base::FilePath& path); 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool DirectoryExists(const base::FilePath& path); 6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) static base::PlatformFileError CopyOrMoveFile( 6568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const base::FilePath& src_path, 6668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const base::FilePath& dest_path, 6768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) FileSystemOperation::CopyOrMoveOption option, 68d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) CopyOrMoveMode mode); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError DeleteFile(const base::FilePath& path); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::PlatformFileError DeleteDirectory(const base::FilePath& path); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_IMPLICIT_CONSTRUCTORS(NativeFileUtil); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace fileapi 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // WEBKIT_BROWSER_FILEAPI_NATIVE_FILE_UTIL_H_ 79