1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_TRUNCATE_H_
6#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_TRUNCATE_H_
7
8#include "base/files/file.h"
9#include "base/memory/scoped_ptr.h"
10#include "chrome/browser/chromeos/file_system_provider/operations/operation.h"
11#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
12#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
13#include "chrome/browser/chromeos/file_system_provider/request_value.h"
14#include "storage/browser/fileapi/async_file_util.h"
15
16namespace base {
17class FilePath;
18}  // namespace base
19
20namespace extensions {
21class EventRouter;
22}  // namespace extensions
23
24namespace chromeos {
25namespace file_system_provider {
26namespace operations {
27
28// Creates a file. If the file already exists, then the operation will fail with
29// the FILE_ERROR_EXISTS error. Created per request.
30class Truncate : public Operation {
31 public:
32  Truncate(extensions::EventRouter* event_router,
33           const ProvidedFileSystemInfo& file_system_info,
34           const base::FilePath& file_path,
35           int64 length,
36           const storage::AsyncFileUtil::StatusCallback& callback);
37  virtual ~Truncate();
38
39  // Operation overrides.
40  virtual bool Execute(int request_id) OVERRIDE;
41  virtual void OnSuccess(int request_id,
42                         scoped_ptr<RequestValue> result,
43                         bool has_more) OVERRIDE;
44  virtual void OnError(int request_id,
45                       scoped_ptr<RequestValue> result,
46                       base::File::Error error) OVERRIDE;
47
48 private:
49  base::FilePath file_path_;
50  int64 length_;
51  const storage::AsyncFileUtil::StatusCallback callback_;
52
53  DISALLOW_COPY_AND_ASSIGN(Truncate);
54};
55
56}  // namespace operations
57}  // namespace file_system_provider
58}  // namespace chromeos
59
60#endif  // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_TRUNCATE_H_
61