Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / truncate_operation.h
blobf27b485d45b57f534b79dc66e6e2fe752c56bcd5
1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TRUNCATE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TRUNCATE_OPERATION_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
14 namespace base {
15 class FilePath;
16 class SequencedTaskRunner;
17 } // namespace base
19 namespace drive {
21 class JobScheduler;
22 class ResourceEntry;
24 namespace internal {
25 class FileCache;
26 class ResourceMetadata;
27 } // namespace internal
29 namespace file_system {
31 class OperationObserver;
32 class DownloadOperation;
34 // This class encapsulates the drive Truncate function. It is responsible for
35 // fetching the content from the Drive server if necessary, truncating the
36 // file content actually, and then notifying the file is locally modified and
37 // that it is necessary to upload the file to the server.
38 class TruncateOperation {
39 public:
40 TruncateOperation(base::SequencedTaskRunner* blocking_task_runner,
41 OperationObserver* observer,
42 JobScheduler* scheduler,
43 internal::ResourceMetadata* metadata,
44 internal::FileCache* cache,
45 const base::FilePath& temporary_file_directory);
46 ~TruncateOperation();
48 // Performs the truncate operation on the file at drive path |file_path| to
49 // |length| bytes. Invokes |callback| when finished with the result of the
50 // operation. |callback| must not be null.
51 void Truncate(const base::FilePath& file_path,
52 int64 length,
53 const FileOperationCallback& callback);
54 private:
55 // Part of Truncate(). Called after EnsureFileDownloadedByPath() is complete.
56 void TruncateAfterEnsureFileDownloadedByPath(
57 int64 length,
58 const FileOperationCallback& callback,
59 FileError error,
60 const base::FilePath& local_file_path,
61 scoped_ptr<ResourceEntry> resource_entry);
63 // Part of Truncate(). Called after TruncateOnBlockingPool() is complete.
64 void TruncateAfterTruncateOnBlockingPool(
65 const std::string& local_id,
66 const FileOperationCallback& callback,
67 FileError error);
69 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
70 OperationObserver* observer_;
71 internal::ResourceMetadata* metadata_;
72 internal::FileCache* cache_;
74 scoped_ptr<DownloadOperation> download_operation_;
76 // Note: This should remain the last member so it'll be destroyed and
77 // invalidate the weak pointers before any other members are destroyed.
78 base::WeakPtrFactory<TruncateOperation> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(TruncateOperation);
82 } // namespace file_system
83 } // namespace drive
85 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TRUNCATE_OPERATION_H_