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

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

Issue 141113003: Refactor base/safe_numerics.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/safe_numerics.h" 15 #include "base/numerics/safe_conversions.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "base/win/scoped_co_mem.h" 19 #include "base/win/scoped_co_mem.h"
20 #include "base/win/scoped_propvariant.h" 20 #include "base/win/scoped_propvariant.h"
21 #include "chrome/browser/storage_monitor/removable_device_constants.h" 21 #include "chrome/browser/storage_monitor/removable_device_constants.h"
22 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 24
25 namespace media_transfer_protocol { 25 namespace media_transfer_protocol {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 optimal_transfer_size, &bytes_read); 378 optimal_transfer_size, &bytes_read);
379 // IStream::Read() returns S_FALSE when the actual number of bytes read from 379 // IStream::Read() returns S_FALSE when the actual number of bytes read from
380 // the stream object is less than the number of bytes requested (aka 380 // the stream object is less than the number of bytes requested (aka
381 // |optimal_transfer_size|). This indicates the end of the stream has been 381 // |optimal_transfer_size|). This indicates the end of the stream has been
382 // reached. 382 // reached.
383 if (FAILED(hr)) 383 if (FAILED(hr))
384 return 0U; 384 return 0U;
385 DCHECK_GT(bytes_read, 0U); 385 DCHECK_GT(bytes_read, 0U);
386 CHECK_LE(bytes_read, buffer.length()); 386 CHECK_LE(bytes_read, buffer.length());
387 int data_len = 387 int data_len =
388 base::checked_numeric_cast<int>( 388 base::checked_cast<int>(
389 std::min(bytes_read, 389 std::min(bytes_read,
390 base::checked_numeric_cast<DWORD>(buffer.length()))); 390 base::checked_cast<DWORD>(buffer.length())));
391 if (file_util::AppendToFile(local_path, buffer.c_str(), data_len) != data_len) 391 if (file_util::AppendToFile(local_path, buffer.c_str(), data_len) != data_len)
392 return 0U; 392 return 0U;
393 return data_len; 393 return data_len;
394 } 394 }
395 395
396 base::string16 GetObjectIdFromName(IPortableDevice* device, 396 base::string16 GetObjectIdFromName(IPortableDevice* device,
397 const base::string16& parent_id, 397 const base::string16& parent_id,
398 const base::string16& object_name) { 398 const base::string16& object_name) {
399 MTPDeviceObjectEntries object_entries; 399 MTPDeviceObjectEntries object_entries;
400 if (!GetMTPDeviceObjectEntries(device, parent_id, object_name, 400 if (!GetMTPDeviceObjectEntries(device, parent_id, object_name,
401 &object_entries) || 401 &object_entries) ||
402 object_entries.empty()) 402 object_entries.empty())
403 return base::string16(); 403 return base::string16();
404 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have 404 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have
405 // the same name. Handle the situation gracefully. Refer to crbug.com/169930 405 // the same name. Handle the situation gracefully. Refer to crbug.com/169930
406 // for more details. 406 // for more details.
407 DCHECK_EQ(1U, object_entries.size()); 407 DCHECK_EQ(1U, object_entries.size());
408 return object_entries[0].object_id; 408 return object_entries[0].object_id;
409 } 409 }
410 410
411 } // namespace media_transfer_protocol 411 } // namespace media_transfer_protocol
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/linux/snapshot_file_details.cc ('k') | chrome/browser/net/crl_set_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698