BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / components / drive / file_system / truncate_operation.h
blobff22806e479d526a5e3fbc840b5380dbbe9e90dd
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 COMPONENTS_DRIVE_FILE_SYSTEM_TRUNCATE_OPERATION_H_
6 #define COMPONENTS_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 "base/threading/thread_checker.h"
13 #include "components/drive/file_errors.h"
15 namespace base {
16 class FilePath;
17 class SequencedTaskRunner;
18 } // namespace base
20 namespace drive {
22 class JobScheduler;
23 class ResourceEntry;
25 namespace internal {
26 class FileCache;
27 class ResourceMetadata;
28 } // namespace internal
30 namespace file_system {
32 class OperationDelegate;
33 class DownloadOperation;
35 // This class encapsulates the drive Truncate function. It is responsible for
36 // fetching the content from the Drive server if necessary, truncating the
37 // file content actually, and then notifying the file is locally modified and
38 // that it is necessary to upload the file to the server.
39 class TruncateOperation {
40 public:
41 TruncateOperation(base::SequencedTaskRunner* blocking_task_runner,
42 OperationDelegate* delegate,
43 JobScheduler* scheduler,
44 internal::ResourceMetadata* metadata,
45 internal::FileCache* cache,
46 const base::FilePath& temporary_file_directory);
47 ~TruncateOperation();
49 // Performs the truncate operation on the file at drive path |file_path| to
50 // |length| bytes. Invokes |callback| when finished with the result of the
51 // operation. |callback| must not be null.
52 void Truncate(const base::FilePath& file_path,
53 int64 length,
54 const FileOperationCallback& callback);
55 private:
56 // Part of Truncate(). Called after EnsureFileDownloadedByPath() is complete.
57 void TruncateAfterEnsureFileDownloadedByPath(
58 int64 length,
59 const FileOperationCallback& callback,
60 FileError error,
61 const base::FilePath& local_file_path,
62 scoped_ptr<ResourceEntry> resource_entry);
64 // Part of Truncate(). Called after TruncateOnBlockingPool() is complete.
65 void TruncateAfterTruncateOnBlockingPool(
66 const std::string& local_id,
67 const FileOperationCallback& callback,
68 FileError error);
70 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
71 OperationDelegate* delegate_;
72 internal::ResourceMetadata* metadata_;
73 internal::FileCache* cache_;
75 scoped_ptr<DownloadOperation> download_operation_;
77 base::ThreadChecker thread_checker_;
79 // Note: This should remain the last member so it'll be destroyed and
80 // invalidate the weak pointers before any other members are destroyed.
81 base::WeakPtrFactory<TruncateOperation> weak_ptr_factory_;
82 DISALLOW_COPY_AND_ASSIGN(TruncateOperation);
85 } // namespace file_system
86 } // namespace drive
88 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_TRUNCATE_OPERATION_H_