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

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_task_helper.cc

Issue 1432403003: Do not call stat() when reading directories via File API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Whitespace cleanup. Created 5 years, 1 month 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 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/media_galleries/linux/mtp_device_task_helper.h" 5 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
Lei Zhang 2015/11/12 07:25:16 These 2 conversion headers can be deleted too.
mtomasz 2015/11/12 07:48:24 Done.
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" 12 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h"
13 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" 13 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h"
14 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" 14 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
15 #include "components/storage_monitor/storage_monitor.h" 15 #include "components/storage_monitor/storage_monitor.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" 17 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
18 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
19 #include "storage/browser/fileapi/async_file_util.h" 19 #include "storage/browser/fileapi/async_file_util.h"
20 #include "storage/common/fileapi/file_system_util.h" 20 #include "storage/common/fileapi/file_system_util.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 const ErrorCallback& error_callback) { 161 const ErrorCallback& error_callback) {
162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
163 163
164 GetMediaTransferProtocolManager()->RenameObject( 164 GetMediaTransferProtocolManager()->RenameObject(
165 device_handle_, object_id, new_name, 165 device_handle_, object_id, new_name,
166 base::Bind(&MTPDeviceTaskHelper::OnRenameObject, 166 base::Bind(&MTPDeviceTaskHelper::OnRenameObject,
167 weak_ptr_factory_.GetWeakPtr(), success_callback, 167 weak_ptr_factory_.GetWeakPtr(), success_callback,
168 error_callback)); 168 error_callback));
169 } 169 }
170 170
171 MTPDeviceTaskHelper::MTPEntry::MTPEntry() : file_id(0) {}
172
171 // TODO(yawano) storage_name is not used, delete it. 173 // TODO(yawano) storage_name is not used, delete it.
172 void MTPDeviceTaskHelper::CopyFileFromLocal( 174 void MTPDeviceTaskHelper::CopyFileFromLocal(
173 const std::string& storage_name, 175 const std::string& storage_name,
174 const int source_file_descriptor, 176 const int source_file_descriptor,
175 const uint32 parent_id, 177 const uint32 parent_id,
176 const std::string& file_name, 178 const std::string& file_name,
177 const CopyFileFromLocalSuccessCallback& success_callback, 179 const CopyFileFromLocalSuccessCallback& success_callback,
178 const ErrorCallback& error_callback) { 180 const ErrorCallback& error_callback) {
179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 181 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
180 182
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 void MTPDeviceTaskHelper::OnDidReadDirectory( 255 void MTPDeviceTaskHelper::OnDidReadDirectory(
254 const ReadDirectorySuccessCallback& success_callback, 256 const ReadDirectorySuccessCallback& success_callback,
255 const ErrorCallback& error_callback, 257 const ErrorCallback& error_callback,
256 const std::vector<MtpFileEntry>& file_entries, 258 const std::vector<MtpFileEntry>& file_entries,
257 bool has_more, 259 bool has_more,
258 bool error) const { 260 bool error) const {
259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 261 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
260 if (error) 262 if (error)
261 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); 263 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED);
262 264
263 storage::AsyncFileUtil::EntryList entries; 265 MTPEntries entries;
264 base::FilePath current; 266 base::FilePath current;
265 MTPDeviceObjectEnumerator file_enum(file_entries); 267 MTPDeviceObjectEnumerator file_enum(file_entries);
266 while (!(current = file_enum.Next()).empty()) { 268 while (!(current = file_enum.Next()).empty()) {
267 storage::DirectoryEntry entry; 269 MTPEntry entry;
268 entry.name = storage::VirtualPath::BaseName(current).value(); 270 entry.name = storage::VirtualPath::BaseName(current).value();
269 uint32 file_id = 0; 271 uint32 file_id = 0;
Lei Zhang 2015/11/12 07:25:17 Get rid of the temporary and pass |entry.file_id|
mtomasz 2015/11/12 07:48:24 Done.
270 bool ret = file_enum.GetEntryId(&file_id); 272 bool ret = file_enum.GetEntryId(&file_id);
271 DCHECK(ret); 273 DCHECK(ret);
272 entry.name.push_back(','); 274 entry.file_id = file_id;
273 entry.name += base::UintToString(file_id); 275 entry.file_info.is_directory = file_enum.IsDirectory();
274 entry.is_directory = file_enum.IsDirectory(); 276 entry.file_info.size = file_enum.Size();
275 entry.size = file_enum.Size(); 277 entry.file_info.last_modified = file_enum.LastModifiedTime();
276 entry.last_modified_time = file_enum.LastModifiedTime();
277 entries.push_back(entry); 278 entries.push_back(entry);
278 } 279 }
279 content::BrowserThread::PostTask( 280 content::BrowserThread::PostTask(
280 content::BrowserThread::IO, 281 content::BrowserThread::IO,
281 FROM_HERE, 282 FROM_HERE,
282 base::Bind(success_callback, entries, has_more)); 283 base::Bind(success_callback, entries, has_more));
283 } 284 }
284 285
285 void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes( 286 void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes(
286 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, 287 const MTPDeviceAsyncDelegate::ReadBytesRequest& request,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 394 }
394 395
395 void MTPDeviceTaskHelper::HandleDeviceError( 396 void MTPDeviceTaskHelper::HandleDeviceError(
396 const ErrorCallback& error_callback, 397 const ErrorCallback& error_callback,
397 base::File::Error error) const { 398 base::File::Error error) const {
398 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 399 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
399 content::BrowserThread::PostTask(content::BrowserThread::IO, 400 content::BrowserThread::PostTask(content::BrowserThread::IO,
400 FROM_HERE, 401 FROM_HERE,
401 base::Bind(error_callback, error)); 402 base::Bind(error_callback, error));
402 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698