OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/fileapi/upload_file_system_file_element_reader.h" | 5 #include "content/browser/fileapi/upload_file_system_file_element_reader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/numerics/safe_conversions.h" |
10 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
11 #include "storage/browser/blob/file_stream_reader.h" | 13 #include "storage/browser/blob/file_stream_reader.h" |
12 #include "storage/browser/fileapi/file_system_context.h" | 14 #include "storage/browser/fileapi/file_system_context.h" |
13 #include "storage/browser/fileapi/file_system_url.h" | 15 #include "storage/browser/fileapi/file_system_url.h" |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 | 18 |
17 UploadFileSystemFileElementReader::UploadFileSystemFileElementReader( | 19 UploadFileSystemFileElementReader::UploadFileSystemFileElementReader( |
18 storage::FileSystemContext* file_system_context, | 20 storage::FileSystemContext* file_system_context, |
19 const GURL& url, | 21 const GURL& url, |
(...skipping 14 matching lines...) Expand all Loading... |
34 } | 36 } |
35 | 37 |
36 int UploadFileSystemFileElementReader::Init( | 38 int UploadFileSystemFileElementReader::Init( |
37 const net::CompletionCallback& callback) { | 39 const net::CompletionCallback& callback) { |
38 // Reset states. | 40 // Reset states. |
39 weak_ptr_factory_.InvalidateWeakPtrs(); | 41 weak_ptr_factory_.InvalidateWeakPtrs(); |
40 stream_length_ = 0; | 42 stream_length_ = 0; |
41 position_ = 0; | 43 position_ = 0; |
42 | 44 |
43 // Initialize the stream reader and the length. | 45 // Initialize the stream reader and the length. |
44 stream_reader_ = | 46 stream_reader_ = file_system_context_->CreateFileStreamReader( |
45 file_system_context_->CreateFileStreamReader( | 47 file_system_context_->CrackURL(url_), |
46 file_system_context_->CrackURL(url_), | 48 range_offset_, |
47 range_offset_, | 49 range_length_ == std::numeric_limits<uint64>::max() |
48 expected_modification_time_); | 50 ? storage::kMaximumLength |
| 51 : base::checked_cast<int64>(range_length_), |
| 52 expected_modification_time_); |
49 DCHECK(stream_reader_); | 53 DCHECK(stream_reader_); |
50 | 54 |
51 const int64 result = stream_reader_->GetLength( | 55 const int64 result = stream_reader_->GetLength( |
52 base::Bind(&UploadFileSystemFileElementReader::OnGetLength, | 56 base::Bind(&UploadFileSystemFileElementReader::OnGetLength, |
53 weak_ptr_factory_.GetWeakPtr(), | 57 weak_ptr_factory_.GetWeakPtr(), |
54 callback)); | 58 callback)); |
55 if (result >= 0) { | 59 if (result >= 0) { |
56 stream_length_ = result; | 60 stream_length_ = result; |
57 return net::OK; | 61 return net::OK; |
58 } | 62 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 int result) { | 112 int result) { |
109 if (result > 0) { | 113 if (result > 0) { |
110 position_ += result; | 114 position_ += result; |
111 DCHECK_LE(position_, GetContentLength()); | 115 DCHECK_LE(position_, GetContentLength()); |
112 } | 116 } |
113 if (!callback.is_null()) | 117 if (!callback.is_null()) |
114 callback.Run(result); | 118 callback.Run(result); |
115 } | 119 } |
116 | 120 |
117 } // namespace content | 121 } // namespace content |
OLD | NEW |