OLD | NEW |
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 "chrome/browser/chromeos/drive/file_system/truncate_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/truncate_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 private: | 41 private: |
42 base::PlatformFile* platform_file_; | 42 base::PlatformFile* platform_file_; |
43 | 43 |
44 DISALLOW_COPY_AND_ASSIGN(ScopedPlatformFileCloser); | 44 DISALLOW_COPY_AND_ASSIGN(ScopedPlatformFileCloser); |
45 }; | 45 }; |
46 | 46 |
47 // Truncates the local file at |local_cache_path| to the |length| bytes, | 47 // Truncates the local file at |local_cache_path| to the |length| bytes, |
48 // then marks the resource is dirty on |cache|. | 48 // then marks the resource is dirty on |cache|. |
49 FileError TruncateOnBlockingPool(internal::FileCache* cache, | 49 FileError TruncateOnBlockingPool(internal::FileCache* cache, |
50 const std::string& resource_id, | 50 const std::string& resource_id, |
51 const std::string& md5, | |
52 const base::FilePath& local_cache_path, | 51 const base::FilePath& local_cache_path, |
53 int64 length) { | 52 int64 length) { |
54 DCHECK(cache); | 53 DCHECK(cache); |
55 | 54 |
56 FileError error = cache->MarkDirty(resource_id, md5); | 55 FileError error = cache->MarkDirty(resource_id); |
57 if (error != FILE_ERROR_OK) | 56 if (error != FILE_ERROR_OK) |
58 return error; | 57 return error; |
59 | 58 |
60 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 59 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; |
61 base::PlatformFile file = base::CreatePlatformFile( | 60 base::PlatformFile file = base::CreatePlatformFile( |
62 local_cache_path, | 61 local_cache_path, |
63 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | 62 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, |
64 NULL, | 63 NULL, |
65 &result); | 64 &result); |
66 if (result != base::PLATFORM_FILE_OK) | 65 if (result != base::PLATFORM_FILE_OK) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (entry->file_specific_info().is_hosted_document()) { | 141 if (entry->file_specific_info().is_hosted_document()) { |
143 callback.Run(FILE_ERROR_INVALID_OPERATION); | 142 callback.Run(FILE_ERROR_INVALID_OPERATION); |
144 return; | 143 return; |
145 } | 144 } |
146 | 145 |
147 base::PostTaskAndReplyWithResult( | 146 base::PostTaskAndReplyWithResult( |
148 blocking_task_runner_.get(), | 147 blocking_task_runner_.get(), |
149 FROM_HERE, | 148 FROM_HERE, |
150 base::Bind(&TruncateOnBlockingPool, | 149 base::Bind(&TruncateOnBlockingPool, |
151 base::Unretained(cache_), | 150 base::Unretained(cache_), |
152 entry->resource_id(), entry->file_specific_info().md5(), | 151 entry->resource_id(), |
153 local_file_path, length), | 152 local_file_path, length), |
154 base::Bind( | 153 base::Bind( |
155 &TruncateOperation::TruncateAfterTruncateOnBlockingPool, | 154 &TruncateOperation::TruncateAfterTruncateOnBlockingPool, |
156 weak_ptr_factory_.GetWeakPtr(), entry->resource_id(), callback)); | 155 weak_ptr_factory_.GetWeakPtr(), entry->resource_id(), callback)); |
157 } | 156 } |
158 | 157 |
159 void TruncateOperation::TruncateAfterTruncateOnBlockingPool( | 158 void TruncateOperation::TruncateAfterTruncateOnBlockingPool( |
160 const std::string& resource_id, | 159 const std::string& resource_id, |
161 const FileOperationCallback& callback, | 160 const FileOperationCallback& callback, |
162 FileError error) { | 161 FileError error) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 DCHECK(!callback.is_null()); | 163 DCHECK(!callback.is_null()); |
165 | 164 |
166 observer_->OnCacheFileUploadNeededByOperation(resource_id); | 165 observer_->OnCacheFileUploadNeededByOperation(resource_id); |
167 | 166 |
168 callback.Run(error); | 167 callback.Run(error); |
169 } | 168 } |
170 | 169 |
171 } // namespace file_system | 170 } // namespace file_system |
172 } // namespace drive | 171 } // namespace drive |
OLD | NEW |