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/linux/snapshot_file_details.cc

Issue 2358493002: Remove MTP support on Linux. (Closed)
Patch Set: move files Created 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
6
7 #include <limits>
8
9 #include "base/numerics/safe_conversions.h"
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // SnapshotRequestInfo //
13 ////////////////////////////////////////////////////////////////////////////////
14
15 SnapshotRequestInfo::SnapshotRequestInfo(
16 uint32_t file_id,
17 const base::FilePath& snapshot_file_path,
18 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback&
19 success_callback,
20 const MTPDeviceAsyncDelegate::ErrorCallback& error_callback)
21 : file_id(file_id),
22 snapshot_file_path(snapshot_file_path),
23 success_callback(success_callback),
24 error_callback(error_callback) {}
25
26 SnapshotRequestInfo::SnapshotRequestInfo(const SnapshotRequestInfo& other) =
27 default;
28
29 SnapshotRequestInfo::~SnapshotRequestInfo() {
30 }
31
32 ////////////////////////////////////////////////////////////////////////////////
33 // SnapshotFileDetails //
34 ////////////////////////////////////////////////////////////////////////////////
35
36 SnapshotFileDetails::SnapshotFileDetails(
37 const SnapshotRequestInfo& request_info,
38 const base::File::Info& file_info)
39 : request_info_(request_info),
40 file_info_(file_info),
41 bytes_written_(0),
42 error_occurred_(false) {
43 }
44
45 SnapshotFileDetails::~SnapshotFileDetails() {
46 }
47
48 void SnapshotFileDetails::set_error_occurred(bool error) {
49 error_occurred_ = error;
50 }
51
52 bool SnapshotFileDetails::AddBytesWritten(uint32_t bytes_written) {
53 if ((bytes_written == 0) ||
54 (bytes_written_ > std::numeric_limits<uint32_t>::max() - bytes_written) ||
55 (bytes_written_ + bytes_written > file_info_.size))
56 return false;
57
58 bytes_written_ += bytes_written;
59 return true;
60 }
61
62 bool SnapshotFileDetails::IsSnapshotFileWriteComplete() const {
63 return !error_occurred_ && (bytes_written_ == file_info_.size);
64 }
65
66 uint32_t SnapshotFileDetails::BytesToRead() const {
67 // Read data in 1MB chunks.
68 static const uint32_t kReadChunkSize = 1024 * 1024;
69 return std::min(
70 kReadChunkSize,
71 base::checked_cast<uint32_t>(file_info_.size) - bytes_written_);
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698