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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reader.cc

Issue 513683002: [fsp] Add support for providing thumbnails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr for EntryMetadata. Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/file_system_provider/fileapi/file_stream_reade r.h" 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reade r.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi le_util.h" 10 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi le_util.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // |callback| is executed. Must be called on UI thread. 107 // |callback| is executed. Must be called on UI thread.
108 void GetMetadataOnUIThread( 108 void GetMetadataOnUIThread(
109 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { 109 const ProvidedFileSystemInterface::GetMetadataCallback& callback) {
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); 110 DCHECK_CURRENTLY_ON(BrowserThread::UI);
111 111
112 // If the file system got unmounted, then abort the get length operation. 112 // If the file system got unmounted, then abort the get length operation.
113 if (!file_system_.get()) { 113 if (!file_system_.get()) {
114 BrowserThread::PostTask( 114 BrowserThread::PostTask(
115 BrowserThread::IO, 115 BrowserThread::IO,
116 FROM_HERE, 116 FROM_HERE,
117 base::Bind(callback, EntryMetadata(), base::File::FILE_ERROR_ABORT)); 117 base::Bind(callback,
118 base::Passed(make_scoped_ptr<EntryMetadata>(NULL)),
119 base::File::FILE_ERROR_ABORT));
118 return; 120 return;
119 } 121 }
120 122
121 abort_callback_ = file_system_->GetMetadata( 123 abort_callback_ = file_system_->GetMetadata(
122 file_path_, 124 file_path_,
125 ProvidedFileSystemInterface::METADATA_FIELD_DEFAULT,
123 base::Bind(&OperationRunner::OnGetMetadataCompletedOnUIThread, 126 base::Bind(&OperationRunner::OnGetMetadataCompletedOnUIThread,
124 this, 127 this,
125 callback)); 128 callback));
126 } 129 }
127 130
128 // Aborts the most recent operation (if exists), and calls the callback. 131 // Aborts the most recent operation (if exists), and calls the callback.
129 void AbortOnUIThread(const storage::AsyncFileUtil::StatusCallback& callback) { 132 void AbortOnUIThread(const storage::AsyncFileUtil::StatusCallback& callback) {
130 DCHECK_CURRENTLY_ON(BrowserThread::UI); 133 DCHECK_CURRENTLY_ON(BrowserThread::UI);
131 134
132 if (abort_callback_.is_null()) { 135 if (abort_callback_.is_null()) {
(...skipping 26 matching lines...) Expand all
159 DCHECK_CURRENTLY_ON(BrowserThread::UI); 162 DCHECK_CURRENTLY_ON(BrowserThread::UI);
160 163
161 file_handle_ = file_handle; 164 file_handle_ = file_handle;
162 BrowserThread::PostTask( 165 BrowserThread::PostTask(
163 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); 166 BrowserThread::IO, FROM_HERE, base::Bind(callback, result));
164 } 167 }
165 168
166 // Forwards a metadata to the IO thread. 169 // Forwards a metadata to the IO thread.
167 void OnGetMetadataCompletedOnUIThread( 170 void OnGetMetadataCompletedOnUIThread(
168 const ProvidedFileSystemInterface::GetMetadataCallback& callback, 171 const ProvidedFileSystemInterface::GetMetadataCallback& callback,
169 const EntryMetadata& metadata, 172 scoped_ptr<EntryMetadata> metadata,
170 base::File::Error result) { 173 base::File::Error result) {
171 DCHECK_CURRENTLY_ON(BrowserThread::UI); 174 DCHECK_CURRENTLY_ON(BrowserThread::UI);
172 BrowserThread::PostTask( 175 BrowserThread::PostTask(
173 BrowserThread::IO, FROM_HERE, base::Bind(callback, metadata, result)); 176 BrowserThread::IO,
177 FROM_HERE,
178 base::Bind(callback, base::Passed(&metadata), result));
174 } 179 }
175 180
176 // Forwards a response of reading from a file to the IO thread. 181 // Forwards a response of reading from a file to the IO thread.
177 void OnReadFileCompletedOnUIThread( 182 void OnReadFileCompletedOnUIThread(
178 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& 183 const ProvidedFileSystemInterface::ReadChunkReceivedCallback&
179 chunk_received_callback, 184 chunk_received_callback,
180 int chunk_length, 185 int chunk_length,
181 bool has_more, 186 bool has_more,
182 base::File::Error result) { 187 base::File::Error result) {
183 DCHECK_CURRENTLY_ON(BrowserThread::UI); 188 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 runner_, 280 runner_,
276 base::Bind(&FileStreamReader::OnInitializeCompleted, 281 base::Bind(&FileStreamReader::OnInitializeCompleted,
277 weak_ptr_factory_.GetWeakPtr(), 282 weak_ptr_factory_.GetWeakPtr(),
278 pending_closure, 283 pending_closure,
279 error_callback))); 284 error_callback)));
280 } 285 }
281 286
282 void FileStreamReader::OnInitializeCompleted( 287 void FileStreamReader::OnInitializeCompleted(
283 const base::Closure& pending_closure, 288 const base::Closure& pending_closure,
284 const net::Int64CompletionCallback& error_callback, 289 const net::Int64CompletionCallback& error_callback,
285 const EntryMetadata& metadata, 290 scoped_ptr<EntryMetadata> metadata,
286 base::File::Error result) { 291 base::File::Error result) {
287 DCHECK_CURRENTLY_ON(BrowserThread::IO); 292 DCHECK_CURRENTLY_ON(BrowserThread::IO);
288 DCHECK_EQ(INITIALIZING, state_); 293 DCHECK_EQ(INITIALIZING, state_);
289 294
290 // In case of an error, abort. 295 // In case of an error, abort.
291 if (result != base::File::FILE_OK) { 296 if (result != base::File::FILE_OK) {
292 state_ = FAILED; 297 state_ = FAILED;
293 error_callback.Run(net::FileErrorToNetError(result)); 298 error_callback.Run(net::FileErrorToNetError(result));
294 return; 299 return;
295 } 300 }
296 301
297 // If the file modification time has changed, then abort. Note, that the file 302 // If the file modification time has changed, then abort. Note, that the file
298 // may be changed without affecting the modification time. 303 // may be changed without affecting the modification time.
304 DCHECK(metadata.get());
299 if (!expected_modification_time_.is_null() && 305 if (!expected_modification_time_.is_null() &&
300 metadata.modification_time != expected_modification_time_) { 306 metadata->modification_time != expected_modification_time_) {
301 state_ = FAILED; 307 state_ = FAILED;
302 error_callback.Run(net::ERR_UPLOAD_FILE_CHANGED); 308 error_callback.Run(net::ERR_UPLOAD_FILE_CHANGED);
303 return; 309 return;
304 } 310 }
305 311
306 DCHECK_EQ(base::File::FILE_OK, result); 312 DCHECK_EQ(base::File::FILE_OK, result);
307 state_ = INITIALIZED; 313 state_ = INITIALIZED;
308 314
309 // Run the task waiting for the initialization to be completed. 315 // Run the task waiting for the initialization to be completed.
310 pending_closure.Run(); 316 pending_closure.Run();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 callback.Run(net::FileErrorToNetError(result)); 460 callback.Run(net::FileErrorToNetError(result));
455 return; 461 return;
456 } 462 }
457 463
458 // More data is about to come, so do not call the callback yet. 464 // More data is about to come, so do not call the callback yet.
459 DCHECK(has_more); 465 DCHECK(has_more);
460 } 466 }
461 467
462 void FileStreamReader::OnGetMetadataForGetLengthReceived( 468 void FileStreamReader::OnGetMetadataForGetLengthReceived(
463 const net::Int64CompletionCallback& callback, 469 const net::Int64CompletionCallback& callback,
464 const EntryMetadata& metadata, 470 scoped_ptr<EntryMetadata> metadata,
465 base::File::Error result) { 471 base::File::Error result) {
466 DCHECK_CURRENTLY_ON(BrowserThread::IO); 472 DCHECK_CURRENTLY_ON(BrowserThread::IO);
467 DCHECK_EQ(INITIALIZED, state_); 473 DCHECK_EQ(INITIALIZED, state_);
468 474
469 // In case of an error, abort. 475 // In case of an error, abort.
470 if (result != base::File::FILE_OK) { 476 if (result != base::File::FILE_OK) {
471 state_ = FAILED; 477 state_ = FAILED;
472 callback.Run(net::FileErrorToNetError(result)); 478 callback.Run(net::FileErrorToNetError(result));
473 return; 479 return;
474 } 480 }
475 481
476 // If the file modification time has changed, then abort. Note, that the file 482 // If the file modification time has changed, then abort. Note, that the file
477 // may be changed without affecting the modification time. 483 // may be changed without affecting the modification time.
484 DCHECK(metadata.get());
478 if (!expected_modification_time_.is_null() && 485 if (!expected_modification_time_.is_null() &&
479 metadata.modification_time != expected_modification_time_) { 486 metadata->modification_time != expected_modification_time_) {
480 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); 487 callback.Run(net::ERR_UPLOAD_FILE_CHANGED);
481 return; 488 return;
482 } 489 }
483 490
484 DCHECK_EQ(base::File::FILE_OK, result); 491 DCHECK_EQ(base::File::FILE_OK, result);
485 callback.Run(metadata.size); 492 callback.Run(metadata->size);
486 } 493 }
487 494
488 } // namespace file_system_provider 495 } // namespace file_system_provider
489 } // namespace chromeos 496 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698