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

Side by Side Diff: chrome/browser/media_galleries/win/mtp_device_operations_util.cc

Issue 614893004: Refactor AppendToFile and WriteFileDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 6 years, 2 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/win/mtp_device_operations_util.h" 5 #include "chrome/browser/media_galleries/win/mtp_device_operations_util.h"
6 6
7 #include <portabledevice.h> 7 #include <portabledevice.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // |optimal_transfer_size|). This indicates the end of the stream has been 385 // |optimal_transfer_size|). This indicates the end of the stream has been
386 // reached. 386 // reached.
387 if (FAILED(hr)) 387 if (FAILED(hr))
388 return 0U; 388 return 0U;
389 DCHECK_GT(bytes_read, 0U); 389 DCHECK_GT(bytes_read, 0U);
390 CHECK_LE(bytes_read, buffer.length()); 390 CHECK_LE(bytes_read, buffer.length());
391 int data_len = 391 int data_len =
392 base::checked_cast<int>( 392 base::checked_cast<int>(
393 std::min(bytes_read, 393 std::min(bytes_read,
394 base::checked_cast<DWORD>(buffer.length()))); 394 base::checked_cast<DWORD>(buffer.length())));
395 if (base::AppendToFile(local_path, buffer.c_str(), data_len) != data_len) 395 return base::AppendToFile(local_path, buffer.c_str(), data_len) ? data_len
396 return 0U; 396 : 0;
397 return data_len;
398 } 397 }
399 398
400 base::string16 GetObjectIdFromName(IPortableDevice* device, 399 base::string16 GetObjectIdFromName(IPortableDevice* device,
401 const base::string16& parent_id, 400 const base::string16& parent_id,
402 const base::string16& object_name) { 401 const base::string16& object_name) {
403 MTPDeviceObjectEntries object_entries; 402 MTPDeviceObjectEntries object_entries;
404 if (!GetMTPDeviceObjectEntries(device, parent_id, object_name, 403 if (!GetMTPDeviceObjectEntries(device, parent_id, object_name,
405 &object_entries) || 404 &object_entries) ||
406 object_entries.empty()) 405 object_entries.empty())
407 return base::string16(); 406 return base::string16();
408 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have 407 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have
409 // the same name. Handle the situation gracefully. Refer to crbug.com/169930 408 // the same name. Handle the situation gracefully. Refer to crbug.com/169930
410 // for more details. 409 // for more details.
411 DCHECK_EQ(1U, object_entries.size()); 410 DCHECK_EQ(1U, object_entries.size());
412 return object_entries[0].object_id; 411 return object_entries[0].object_id;
413 } 412 }
414 413
415 } // namespace media_transfer_protocol 414 } // namespace media_transfer_protocol
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/linux/mtp_read_file_worker.cc ('k') | chrome/browser/net/net_log_temp_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698