summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/file_system_provider/scoped_file_opener.h
blob: 1baba58c39e46a1ef53e9d137560e7bc33aee377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SCOPED_FILE_OPENER_H_
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SCOPED_FILE_OPENER_H_

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"

namespace base {
class FilePath;
}  // namespace base

namespace chromeos {
namespace file_system_provider {

// Opens files and guarantees that they will be closed when the object gets out
// of scope. Use instead of manually calling OpenFile and CloseFile, as aborting
// of the OpenFile operation is racey and the operation may or may not be
// aborted.
class ScopedFileOpener {
 public:
  ScopedFileOpener(
      ProvidedFileSystemInterface* file_system,
      const base::FilePath& file_path,
      OpenFileMode mode,
      const ProvidedFileSystemInterface::OpenFileCallback& callback);
  ~ScopedFileOpener();

 private:
  class Runner;
  scoped_refptr<Runner> runner_;
};

}  // namespace file_system_provider
}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SCOPED_FILE_OPENER_H_