OLD | NEW |
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/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 file_system_ = parser.file_system()->GetWeakPtr(); | 56 file_system_ = parser.file_system()->GetWeakPtr(); |
57 file_path_ = parser.file_path(); | 57 file_path_ = parser.file_path(); |
58 file_opener_.reset(new ScopedFileOpener( | 58 file_opener_.reset(new ScopedFileOpener( |
59 parser.file_system(), parser.file_path(), OPEN_FILE_MODE_READ, | 59 parser.file_system(), parser.file_path(), OPEN_FILE_MODE_READ, |
60 base::Bind(&OperationRunner::OnOpenFileCompletedOnUIThread, this, | 60 base::Bind(&OperationRunner::OnOpenFileCompletedOnUIThread, this, |
61 callback))); | 61 callback))); |
62 } | 62 } |
63 | 63 |
64 // Requests reading contents of a file. In case of either success or a failure | 64 // Requests reading contents of a file. |callback| will always run eventually. |
65 // |callback| is executed. It can be called many times, until |has_more| is | 65 // It can be called many times, until |has_more| is set to false. This |
66 // set to false. This function guarantees that it will succeed only if the | 66 // function guarantees that it will succeed only if the file has not been |
67 // file has not been changed while reading. Must be called on UI thread. | 67 // changed while reading. Must be called on UI thread. |
68 void ReadFileOnUIThread( | 68 void ReadFileOnUIThread( |
69 scoped_refptr<net::IOBuffer> buffer, | 69 scoped_refptr<net::IOBuffer> buffer, |
70 int64_t offset, | 70 int64_t offset, |
71 int length, | 71 int length, |
72 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { | 72 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { |
73 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
74 DCHECK(abort_callback_.is_null()); | 74 DCHECK(abort_callback_.is_null()); |
75 | 75 |
76 // If the file system got unmounted, then abort the reading operation. | 76 // If the file system got unmounted, then abort the reading operation. |
77 if (!file_system_.get()) { | 77 if (!file_system_.get()) { |
78 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
79 BrowserThread::IO, | 79 BrowserThread::IO, |
80 FROM_HERE, | 80 FROM_HERE, |
81 base::Bind( | 81 base::Bind( |
82 callback, 0, false /* has_more */, base::File::FILE_ERROR_ABORT)); | 82 callback, 0, false /* has_more */, base::File::FILE_ERROR_ABORT)); |
83 return; | 83 return; |
84 } | 84 } |
85 | 85 |
86 abort_callback_ = file_system_->ReadFile( | 86 abort_callback_ = file_system_->ReadFile( |
87 file_handle_, | 87 file_handle_, |
88 buffer.get(), | 88 buffer.get(), |
89 offset, | 89 offset, |
90 length, | 90 length, |
91 base::Bind( | 91 base::Bind( |
92 &OperationRunner::OnReadFileCompletedOnUIThread, this, callback)); | 92 &OperationRunner::OnReadFileCompletedOnUIThread, this, callback)); |
93 } | 93 } |
94 | 94 |
95 // Requests metadata of a file. In case of either succes or a failure, | 95 // Requests metadata of a file. |callback| will always run eventually. |
96 // |callback| is executed. Must be called on UI thread. | 96 // Must be called on UI thread. |
97 void GetMetadataOnUIThread( | 97 void GetMetadataOnUIThread( |
98 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { | 98 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
100 DCHECK(abort_callback_.is_null()); | 100 DCHECK(abort_callback_.is_null()); |
101 | 101 |
102 // If the file system got unmounted, then abort the get length operation. | 102 // If the file system got unmounted, then abort the get length operation. |
103 if (!file_system_.get()) { | 103 if (!file_system_.get()) { |
104 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
105 BrowserThread::IO, FROM_HERE, | 105 BrowserThread::IO, FROM_HERE, |
106 base::Bind(callback, | 106 base::Bind(callback, |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 470 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
471 return; | 471 return; |
472 } | 472 } |
473 | 473 |
474 DCHECK_EQ(base::File::FILE_OK, result); | 474 DCHECK_EQ(base::File::FILE_OK, result); |
475 callback.Run(*metadata->size); | 475 callback.Run(*metadata->size); |
476 } | 476 } |
477 | 477 |
478 } // namespace file_system_provider | 478 } // namespace file_system_provider |
479 } // namespace chromeos | 479 } // namespace chromeos |
OLD | NEW |