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"
17 class SequencedTaskRunner
;
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
{
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
);
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
,
54 const FileOperationCallback
& callback
);
56 // Part of Truncate(). Called after EnsureFileDownloadedByPath() is complete.
57 void TruncateAfterEnsureFileDownloadedByPath(
59 const FileOperationCallback
& callback
,
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
,
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
88 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_TRUNCATE_OPERATION_H_