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

Side by Side Diff: net/base/upload_file_element_reader.cc

Issue 46303005: Fix chrome upload with content uri (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify the change using FILE enum instead of adding a new enum Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/upload_file_element_reader.h" 5 #include "net/base/upload_file_element_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
11 #include "net/base/file_stream.h" 11 #include "net/base/file_stream.h"
12 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 14
15 #if defined(OS_ANDROID)
16 #include "net/android/content_uri_utils.h"
17 #endif
18
15 namespace net { 19 namespace net {
16 20
17 namespace { 21 namespace {
18 22
19 // In tests, this value is used to override the return value of 23 // In tests, this value is used to override the return value of
20 // UploadFileElementReader::GetContentLength() when set to non-zero. 24 // UploadFileElementReader::GetContentLength() when set to non-zero.
21 uint64 overriding_content_length = 0; 25 uint64 overriding_content_length = 0;
22 26
23 // This function is used to implement Init(). 27 // This function is used to implement Init().
24 template<typename FileStreamDeleter> 28 template<typename FileStreamDeleter>
(...skipping 13 matching lines...) Expand all
38 file_stream.reset(); 42 file_stream.reset();
39 } else if (range_offset) { 43 } else if (range_offset) {
40 rv = file_stream->SeekSync(FROM_BEGIN, range_offset); 44 rv = file_stream->SeekSync(FROM_BEGIN, range_offset);
41 if (rv < 0) { 45 if (rv < 0) {
42 DLOG(WARNING) << "Failed to seek \"" << path.value() 46 DLOG(WARNING) << "Failed to seek \"" << path.value()
43 << "\" to offset: " << range_offset << " (" << rv << ")"; 47 << "\" to offset: " << range_offset << " (" << rv << ")";
44 file_stream.reset(); 48 file_stream.reset();
45 } 49 }
46 } 50 }
47 51
52 #if defined(OS_ANDROID)
53 int64 length = std::max(0ll, GetContentUrlLengthSync(path));
kinuko 2013/10/31 06:10:51 Can this part be factored out as a separate static
joth 2013/10/31 06:42:39 +1 Maybe even, bundling this logic into file_util
qinmin 2013/11/05 01:41:31 Done. GetFileInfo() should work for content url no
54 if (file_stream.get() && length > 0 &&
55 range_offset < static_cast<uint64>(length)) {
mmenke 2013/10/31 15:07:06 This class is being modified to handle errors diff
qinmin 2013/11/05 01:41:31 Done.
56 // Compensate for the offset.
57 length = std::min(length - range_offset, range_length);
58 }
59 #else
48 int64 length = 0; 60 int64 length = 0;
49 if (file_stream.get() && 61 if (file_stream.get() &&
50 file_util::GetFileSize(path, &length) && 62 file_util::GetFileSize(path, &length) &&
51 range_offset < static_cast<uint64>(length)) { 63 range_offset < static_cast<uint64>(length)) {
52 // Compensate for the offset. 64 // Compensate for the offset.
53 length = std::min(length - range_offset, range_length); 65 length = std::min(length - range_offset, range_length);
54 } 66 }
67 #endif
55 *out_content_length = length; 68 *out_content_length = length;
56 out_file_stream->reset(file_stream.release()); 69 out_file_stream->reset(file_stream.release());
57 70
58 // If the underlying file has been changed and the expected file modification 71 // If the underlying file has been changed and the expected file modification
59 // time is set, treat it as error. Note that the expected modification time 72 // time is set, treat it as error. Note that the expected modification time
60 // from WebKit is based on time_t precision. So we have to convert both to 73 // from WebKit is based on time_t precision. So we have to convert both to
61 // time_t to compare. This check is used for sliced files. 74 // time_t to compare. This check is used for sliced files.
62 if (!expected_modification_time.is_null()) { 75 if (!expected_modification_time.is_null()) {
63 base::PlatformFileInfo info; 76 base::PlatformFileInfo info;
64 if (file_util::GetFileInfo(path, &info) && 77 if (file_util::GetFileInfo(path, &info) &&
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 const int result = ReadInternal(buf, buf_length, BytesRemaining(), 294 const int result = ReadInternal(buf, buf_length, BytesRemaining(),
282 file_stream_.get()); 295 file_stream_.get());
283 if (result > 0) { 296 if (result > 0) {
284 DCHECK_GE(bytes_remaining_, static_cast<uint64>(result)); 297 DCHECK_GE(bytes_remaining_, static_cast<uint64>(result));
285 bytes_remaining_ -= result; 298 bytes_remaining_ -= result;
286 } 299 }
287 return result; 300 return result;
288 } 301 }
289 302
290 } // namespace net 303 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698