Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: components/drive/file_system/truncate_operation.cc

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/drive/file_system/truncate_operation.h" 5 #include "components/drive/file_system/truncate_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 11 matching lines...) Expand all
22 namespace drive { 22 namespace drive {
23 namespace file_system { 23 namespace file_system {
24 namespace { 24 namespace {
25 25
26 // Truncates the local file at |local_cache_path| to the |length| bytes, 26 // Truncates the local file at |local_cache_path| to the |length| bytes,
27 // then marks the resource is dirty on |cache|. 27 // then marks the resource is dirty on |cache|.
28 FileError TruncateOnBlockingPool(internal::ResourceMetadata* metadata, 28 FileError TruncateOnBlockingPool(internal::ResourceMetadata* metadata,
29 internal::FileCache* cache, 29 internal::FileCache* cache,
30 const std::string& local_id, 30 const std::string& local_id,
31 const base::FilePath& local_cache_path, 31 const base::FilePath& local_cache_path,
32 int64 length) { 32 int64_t length) {
33 DCHECK(metadata); 33 DCHECK(metadata);
34 DCHECK(cache); 34 DCHECK(cache);
35 35
36 scoped_ptr<base::ScopedClosureRunner> file_closer; 36 scoped_ptr<base::ScopedClosureRunner> file_closer;
37 FileError error = cache->OpenForWrite(local_id, &file_closer); 37 FileError error = cache->OpenForWrite(local_id, &file_closer);
38 if (error != FILE_ERROR_OK) 38 if (error != FILE_ERROR_OK)
39 return error; 39 return error;
40 40
41 base::File file(local_cache_path, 41 base::File file(local_cache_path,
42 base::File::FLAG_OPEN | base::File::FLAG_WRITE); 42 base::File::FLAG_OPEN | base::File::FLAG_WRITE);
(...skipping 25 matching lines...) Expand all
68 metadata, 68 metadata,
69 cache, 69 cache,
70 temporary_file_directory)), 70 temporary_file_directory)),
71 weak_ptr_factory_(this) { 71 weak_ptr_factory_(this) {
72 } 72 }
73 73
74 TruncateOperation::~TruncateOperation() { 74 TruncateOperation::~TruncateOperation() {
75 } 75 }
76 76
77 void TruncateOperation::Truncate(const base::FilePath& file_path, 77 void TruncateOperation::Truncate(const base::FilePath& file_path,
78 int64 length, 78 int64_t length,
79 const FileOperationCallback& callback) { 79 const FileOperationCallback& callback) {
80 DCHECK(thread_checker_.CalledOnValidThread()); 80 DCHECK(thread_checker_.CalledOnValidThread());
81 DCHECK(!callback.is_null()); 81 DCHECK(!callback.is_null());
82 82
83 if (length < 0) { 83 if (length < 0) {
84 base::ThreadTaskRunnerHandle::Get()->PostTask( 84 base::ThreadTaskRunnerHandle::Get()->PostTask(
85 FROM_HERE, 85 FROM_HERE,
86 base::Bind(callback, FILE_ERROR_INVALID_OPERATION)); 86 base::Bind(callback, FILE_ERROR_INVALID_OPERATION));
87 return; 87 return;
88 } 88 }
89 89
90 // TODO(kinaba): http://crbug.com/132780. 90 // TODO(kinaba): http://crbug.com/132780.
91 // Optimize the cases for small |length|, at least for |length| == 0. 91 // Optimize the cases for small |length|, at least for |length| == 0.
92 download_operation_->EnsureFileDownloadedByPath( 92 download_operation_->EnsureFileDownloadedByPath(
93 file_path, 93 file_path,
94 ClientContext(USER_INITIATED), 94 ClientContext(USER_INITIATED),
95 GetFileContentInitializedCallback(), 95 GetFileContentInitializedCallback(),
96 google_apis::GetContentCallback(), 96 google_apis::GetContentCallback(),
97 base::Bind(&TruncateOperation::TruncateAfterEnsureFileDownloadedByPath, 97 base::Bind(&TruncateOperation::TruncateAfterEnsureFileDownloadedByPath,
98 weak_ptr_factory_.GetWeakPtr(), length, callback)); 98 weak_ptr_factory_.GetWeakPtr(), length, callback));
99 } 99 }
100 100
101 void TruncateOperation::TruncateAfterEnsureFileDownloadedByPath( 101 void TruncateOperation::TruncateAfterEnsureFileDownloadedByPath(
102 int64 length, 102 int64_t length,
103 const FileOperationCallback& callback, 103 const FileOperationCallback& callback,
104 FileError error, 104 FileError error,
105 const base::FilePath& local_file_path, 105 const base::FilePath& local_file_path,
106 scoped_ptr<ResourceEntry> entry) { 106 scoped_ptr<ResourceEntry> entry) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 107 DCHECK(thread_checker_.CalledOnValidThread());
108 DCHECK(!callback.is_null()); 108 DCHECK(!callback.is_null());
109 109
110 if (error != FILE_ERROR_OK) { 110 if (error != FILE_ERROR_OK) {
111 callback.Run(error); 111 callback.Run(error);
112 return; 112 return;
(...skipping 23 matching lines...) Expand all
136 DCHECK(thread_checker_.CalledOnValidThread()); 136 DCHECK(thread_checker_.CalledOnValidThread());
137 DCHECK(!callback.is_null()); 137 DCHECK(!callback.is_null());
138 138
139 delegate_->OnEntryUpdatedByOperation(ClientContext(USER_INITIATED), local_id); 139 delegate_->OnEntryUpdatedByOperation(ClientContext(USER_INITIATED), local_id);
140 140
141 callback.Run(error); 141 callback.Run(error);
142 } 142 }
143 143
144 } // namespace file_system 144 } // namespace file_system
145 } // namespace drive 145 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/file_system/truncate_operation.h ('k') | components/drive/file_system/truncate_operation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698