blob: 80688cfbb48ae0f08a3cb8e25623521446c7e4de [file] [log] [blame]
groby@chromium.orgdcdfe7f2012-01-12 10:59:47 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
dumi@chromium.orgc980e402010-08-21 07:42:50 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
brettw@chromium.org06a553b2013-01-26 09:21:58 +09005#ifndef BASE_FILES_FILE_UTIL_PROXY_H_
6#define BASE_FILES_FILE_UTIL_PROXY_H_
kkanetkar@chromium.org3a3bdea2010-09-02 12:43:36 +09007
darin@chromium.orge585bed2011-08-06 00:34:00 +09008#include "base/base_export.h"
thestig@chromium.org98e70672012-04-24 06:23:04 +09009#include "base/callback_forward.h"
rvargas@chromium.org9e469f62014-01-28 06:36:00 +090010#include "base/files/file.h"
brettw@chromium.org59eef1f2013-02-24 14:40:52 +090011#include "base/files/file_path.h"
dumi@chromium.orgc980e402010-08-21 07:42:50 +090012
13namespace base {
14
kinuko@chromium.org20e2efc2012-04-24 03:40:57 +090015class TaskRunner;
dumi@chromium.org97ae2612010-09-03 11:28:37 +090016class Time;
dumi@chromium.orgc980e402010-08-21 07:42:50 +090017
18// This class provides asynchronous access to common file routines.
darin@chromium.orge585bed2011-08-06 00:34:00 +090019class BASE_EXPORT FileUtilProxy {
dumi@chromium.orgc980e402010-08-21 07:42:50 +090020 public:
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090021 // This callback is used by methods that report only an error code. It is
kinuko@chromium.org42e9d8c2011-11-08 18:04:16 +090022 // valid to pass a null callback to any function that takes a StatusCallback,
jhawkins@chromium.org162de392011-10-18 06:33:35 +090023 // in which case the operation will complete silently.
rvargas@chromium.org9e469f62014-01-28 06:36:00 +090024 typedef Callback<void(File::Error)> StatusCallback;
dumi@chromium.orgc980e402010-08-21 07:42:50 +090025
rvargas@chromium.org9e469f62014-01-28 06:36:00 +090026 typedef Callback<void(File::Error,
rvargas@chromium.org9e469f62014-01-28 06:36:00 +090027 const File::Info&)> GetFileInfoCallback;
dumi@chromium.orgc980e402010-08-21 07:42:50 +090028
jhawkins@chromium.orgd08a33e2011-10-18 05:44:47 +090029 // Retrieves the information about a file. It is invalid to pass a null
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090030 // callback.
kinuko@chromium.org6cce7092013-01-21 13:26:59 +090031 // This returns false if task posting to |task_runner| has failed.
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090032 static bool GetFileInfo(
kinuko@chromium.org20e2efc2012-04-24 03:40:57 +090033 TaskRunner* task_runner,
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090034 const FilePath& file_path,
jhawkins@chromium.org56771f02011-10-18 05:12:05 +090035 const GetFileInfoCallback& callback);
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090036
kinuko@chromium.org1a078042010-10-07 17:35:09 +090037 // Deletes a file or a directory.
38 // It is an error to delete a non-empty directory with recursive=false.
kinuko@chromium.org6cce7092013-01-21 13:26:59 +090039 // This returns false if task posting to |task_runner| has failed.
brettw@chromium.org220b8de2013-07-17 04:10:23 +090040 static bool DeleteFile(TaskRunner* task_runner,
41 const FilePath& file_path,
42 bool recursive,
43 const StatusCallback& callback);
kkanetkar@chromium.org3a3bdea2010-09-02 12:43:36 +090044
jhawkins@chromium.org553ef502011-10-18 05:56:52 +090045 // Touches a file. The callback can be null.
kinuko@chromium.org6cce7092013-01-21 13:26:59 +090046 // This returns false if task posting to |task_runner| has failed.
dumi@chromium.org12c2e2b2010-09-24 10:09:32 +090047 static bool Touch(
kinuko@chromium.org20e2efc2012-04-24 03:40:57 +090048 TaskRunner* task_runner,
dumi@chromium.org12c2e2b2010-09-24 10:09:32 +090049 const FilePath& file_path,
kkanetkar@chromium.org48710682010-11-03 05:36:52 +090050 const Time& last_access_time,
51 const Time& last_modified_time,
jhawkins@chromium.org162de392011-10-18 06:33:35 +090052 const StatusCallback& callback);
dumi@chromium.org12c2e2b2010-09-24 10:09:32 +090053
dumi@chromium.orgc980e402010-08-21 07:42:50 +090054 private:
55 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy);
56};
57
kkanetkar@chromium.org3a3bdea2010-09-02 12:43:36 +090058} // namespace base
dumi@chromium.orgc980e402010-08-21 07:42:50 +090059
brettw@chromium.org06a553b2013-01-26 09:21:58 +090060#endif // BASE_FILES_FILE_UTIL_PROXY_H_