OLD | NEW |
---|---|
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 "webkit/browser/blob/local_file_stream_reader.h" | 5 #include "webkit/browser/blob/local_file_stream_reader.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_util_proxy.h" | 8 #include "base/files/file_util_proxy.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
13 #include "net/base/file_stream.h" | 13 #include "net/base/file_stream.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 | 16 |
17 #if defined(OS_ANDROID) | |
18 #include "net/android/content_uri_utils.h" | |
19 #endif | |
20 | |
17 namespace webkit_blob { | 21 namespace webkit_blob { |
18 | 22 |
19 namespace { | 23 namespace { |
20 | 24 |
21 const int kOpenFlagsForRead = base::PLATFORM_FILE_OPEN | | 25 const int kOpenFlagsForRead = base::PLATFORM_FILE_OPEN | |
22 base::PLATFORM_FILE_READ | | 26 base::PLATFORM_FILE_READ | |
23 base::PLATFORM_FILE_ASYNC; | 27 base::PLATFORM_FILE_ASYNC; |
24 | 28 |
25 // Verify if the underlying file has not been modified. | 29 // Verify if the underlying file has not been modified. |
26 bool VerifySnapshotTime(const base::Time& expected_modification_time, | 30 bool VerifySnapshotTime(const base::Time& expected_modification_time, |
(...skipping 22 matching lines...) Expand all Loading... | |
49 DCHECK(!has_pending_open_); | 53 DCHECK(!has_pending_open_); |
50 if (stream_impl_) | 54 if (stream_impl_) |
51 return stream_impl_->Read(buf, buf_len, callback); | 55 return stream_impl_->Read(buf, buf_len, callback); |
52 return Open(base::Bind(&LocalFileStreamReader::DidOpenForRead, | 56 return Open(base::Bind(&LocalFileStreamReader::DidOpenForRead, |
53 weak_factory_.GetWeakPtr(), | 57 weak_factory_.GetWeakPtr(), |
54 make_scoped_refptr(buf), buf_len, callback)); | 58 make_scoped_refptr(buf), buf_len, callback)); |
55 } | 59 } |
56 | 60 |
57 int64 LocalFileStreamReader::GetLength( | 61 int64 LocalFileStreamReader::GetLength( |
58 const net::Int64CompletionCallback& callback) { | 62 const net::Int64CompletionCallback& callback) { |
63 #if defined(OS_ANDROID) | |
64 if (file_path_.IsContentUrl()) { | |
65 net::GetContentUrlLength( | |
66 task_runner_.get(), | |
67 file_path_, | |
68 base::Bind(&LocalFileStreamReader::DidGetContentUrlLength, | |
69 weak_factory_.GetWeakPtr(), | |
70 callback)); | |
71 return net::ERR_IO_PENDING; | |
72 } | |
73 #endif | |
joth
2013/10/31 06:42:39
...again if file_util::GetFileInfo() knew how to d
qinmin
2013/11/05 01:41:31
Done.
| |
59 const bool posted = base::FileUtilProxy::GetFileInfo( | 74 const bool posted = base::FileUtilProxy::GetFileInfo( |
60 task_runner_.get(), | 75 task_runner_.get(), |
61 file_path_, | 76 file_path_, |
62 base::Bind(&LocalFileStreamReader::DidGetFileInfoForGetLength, | 77 base::Bind(&LocalFileStreamReader::DidGetFileInfoForGetLength, |
63 weak_factory_.GetWeakPtr(), | 78 weak_factory_.GetWeakPtr(), |
64 callback)); | 79 callback)); |
65 DCHECK(posted); | 80 DCHECK(posted); |
66 return net::ERR_IO_PENDING; | 81 return net::ERR_IO_PENDING; |
67 } | 82 } |
68 | 83 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 callback.Run(net::PlatformFileErrorToNetError(error)); | 183 callback.Run(net::PlatformFileErrorToNetError(error)); |
169 return; | 184 return; |
170 } | 185 } |
171 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { | 186 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { |
172 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 187 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
173 return; | 188 return; |
174 } | 189 } |
175 callback.Run(file_info.size); | 190 callback.Run(file_info.size); |
176 } | 191 } |
177 | 192 |
193 #if defined(OS_ANDROID) | |
194 void LocalFileStreamReader::DidGetContentUrlLength( | |
195 const net::Int64CompletionCallback& callback, | |
196 int64 result) { | |
197 if (result < 0) { | |
198 callback.Run(net::ERR_FILE_NOT_FOUND); | |
199 return; | |
200 } | |
201 callback.Run(result); | |
202 } | |
203 #endif | |
204 | |
178 } // namespace webkit_blob | 205 } // namespace webkit_blob |
OLD | NEW |