OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media_galleries/linux/mtp_read_file_worker.h" | 5 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" | 11 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" |
12 #include "components/storage_monitor/storage_monitor.h" | 12 #include "components/storage_monitor/storage_monitor.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 14 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 using storage_monitor::StorageMonitor; | 18 using storage_monitor::StorageMonitor; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Appends |data| to the snapshot file specified by the |snapshot_file_path| on | 22 // Appends |data| to the snapshot file specified by the |snapshot_file_path| on |
23 // the file thread. | 23 // the file thread. |
24 // Returns the number of bytes written to the snapshot file. In case of failure, | 24 // Returns the number of bytes written to the snapshot file. In case of failure, |
25 // returns zero. | 25 // returns zero. |
26 uint32 WriteDataChunkIntoSnapshotFileOnFileThread( | 26 uint32_t WriteDataChunkIntoSnapshotFileOnFileThread( |
27 const base::FilePath& snapshot_file_path, | 27 const base::FilePath& snapshot_file_path, |
28 const std::string& data) { | 28 const std::string& data) { |
29 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 29 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
30 return base::AppendToFile(snapshot_file_path, data.c_str(), data.size()) | 30 return base::AppendToFile(snapshot_file_path, data.c_str(), data.size()) |
31 ? base::checked_cast<uint32>(data.size()) | 31 ? base::checked_cast<uint32_t>(data.size()) |
32 : 0; | 32 : 0; |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 MTPReadFileWorker::MTPReadFileWorker(const std::string& device_handle) | 37 MTPReadFileWorker::MTPReadFileWorker(const std::string& device_handle) |
38 : device_handle_(device_handle), | 38 : device_handle_(device_handle), |
39 weak_ptr_factory_(this) { | 39 weak_ptr_factory_(this) { |
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
41 DCHECK(!device_handle_.empty()); | 41 DCHECK(!device_handle_.empty()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 base::Bind(&WriteDataChunkIntoSnapshotFileOnFileThread, | 96 base::Bind(&WriteDataChunkIntoSnapshotFileOnFileThread, |
97 snapshot_file_details_ptr->snapshot_file_path(), | 97 snapshot_file_details_ptr->snapshot_file_path(), |
98 data), | 98 data), |
99 base::Bind(&MTPReadFileWorker::OnDidWriteDataChunkIntoSnapshotFile, | 99 base::Bind(&MTPReadFileWorker::OnDidWriteDataChunkIntoSnapshotFile, |
100 weak_ptr_factory_.GetWeakPtr(), | 100 weak_ptr_factory_.GetWeakPtr(), |
101 base::Passed(&snapshot_file_details))); | 101 base::Passed(&snapshot_file_details))); |
102 } | 102 } |
103 | 103 |
104 void MTPReadFileWorker::OnDidWriteDataChunkIntoSnapshotFile( | 104 void MTPReadFileWorker::OnDidWriteDataChunkIntoSnapshotFile( |
105 scoped_ptr<SnapshotFileDetails> snapshot_file_details, | 105 scoped_ptr<SnapshotFileDetails> snapshot_file_details, |
106 uint32 bytes_written) { | 106 uint32_t bytes_written) { |
107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
108 DCHECK(snapshot_file_details.get()); | 108 DCHECK(snapshot_file_details.get()); |
109 if (snapshot_file_details->AddBytesWritten(bytes_written)) { | 109 if (snapshot_file_details->AddBytesWritten(bytes_written)) { |
110 if (!snapshot_file_details->IsSnapshotFileWriteComplete()) { | 110 if (!snapshot_file_details->IsSnapshotFileWriteComplete()) { |
111 ReadDataChunkFromDeviceFile(snapshot_file_details.Pass()); | 111 ReadDataChunkFromDeviceFile(snapshot_file_details.Pass()); |
112 return; | 112 return; |
113 } | 113 } |
114 } else { | 114 } else { |
115 snapshot_file_details->set_error_occurred(true); | 115 snapshot_file_details->set_error_occurred(true); |
116 } | 116 } |
(...skipping 13 matching lines...) Expand all Loading... |
130 base::File::FILE_ERROR_FAILED)); | 130 base::File::FILE_ERROR_FAILED)); |
131 return; | 131 return; |
132 } | 132 } |
133 content::BrowserThread::PostTask( | 133 content::BrowserThread::PostTask( |
134 content::BrowserThread::IO, | 134 content::BrowserThread::IO, |
135 FROM_HERE, | 135 FROM_HERE, |
136 base::Bind(snapshot_file_details->success_callback(), | 136 base::Bind(snapshot_file_details->success_callback(), |
137 snapshot_file_details->file_info(), | 137 snapshot_file_details->file_info(), |
138 snapshot_file_details->snapshot_file_path())); | 138 snapshot_file_details->snapshot_file_path())); |
139 } | 139 } |
OLD | NEW |