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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/safe_numerics.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 "chrome/browser/storage_monitor/storage_monitor.h" | 12 #include "chrome/browser/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 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Appends |data| to the snapshot file specified by the |snapshot_file_path| on | 21 // Appends |data| to the snapshot file specified by the |snapshot_file_path| on |
22 // the file thread. | 22 // the file thread. |
23 // Returns the number of bytes written to the snapshot file. In case of failure, | 23 // Returns the number of bytes written to the snapshot file. In case of failure, |
24 // returns zero. | 24 // returns zero. |
25 uint32 WriteDataChunkIntoSnapshotFileOnFileThread( | 25 uint32 WriteDataChunkIntoSnapshotFileOnFileThread( |
26 const base::FilePath& snapshot_file_path, | 26 const base::FilePath& snapshot_file_path, |
27 const std::string& data) { | 27 const std::string& data) { |
28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
29 int bytes_written = | 29 int bytes_written = |
30 file_util::AppendToFile(snapshot_file_path, data.data(), | 30 file_util::AppendToFile(snapshot_file_path, data.data(), |
31 base::checked_numeric_cast<int>(data.size())); | 31 base::checked_cast<int>(data.size())); |
32 return (static_cast<int>(data.size()) == bytes_written) ? | 32 return (static_cast<int>(data.size()) == bytes_written) ? |
33 base::checked_numeric_cast<uint32>(bytes_written) : 0; | 33 base::checked_cast<uint32>(bytes_written) : 0; |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 MTPReadFileWorker::MTPReadFileWorker(const std::string& device_handle) | 38 MTPReadFileWorker::MTPReadFileWorker(const std::string& device_handle) |
39 : device_handle_(device_handle), | 39 : device_handle_(device_handle), |
40 weak_ptr_factory_(this) { | 40 weak_ptr_factory_(this) { |
41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
42 DCHECK(!device_handle_.empty()); | 42 DCHECK(!device_handle_.empty()); |
43 } | 43 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 base::PLATFORM_FILE_ERROR_FAILED)); | 131 base::PLATFORM_FILE_ERROR_FAILED)); |
132 return; | 132 return; |
133 } | 133 } |
134 content::BrowserThread::PostTask( | 134 content::BrowserThread::PostTask( |
135 content::BrowserThread::IO, | 135 content::BrowserThread::IO, |
136 FROM_HERE, | 136 FROM_HERE, |
137 base::Bind(snapshot_file_details->success_callback(), | 137 base::Bind(snapshot_file_details->success_callback(), |
138 snapshot_file_details->file_info(), | 138 snapshot_file_details->file_info(), |
139 snapshot_file_details->snapshot_file_path())); | 139 snapshot_file_details->snapshot_file_path())); |
140 } | 140 } |
OLD | NEW |