| 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 "net/base/file_stream_context.h" | 5 #include "net/base/file_stream_context.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "net/base/file_stream_net_log_parameters.h" | 11 #include "net/base/file_stream_net_log_parameters.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 | 13 |
| 14 #if defined(OS_ANDROID) |
| 15 #include "base/android/content_uri_utils.h" |
| 16 #endif |
| 17 |
| 14 namespace { | 18 namespace { |
| 15 | 19 |
| 16 void CallInt64ToInt(const net::CompletionCallback& callback, int64 result) { | 20 void CallInt64ToInt(const net::CompletionCallback& callback, int64 result) { |
| 17 callback.Run(static_cast<int>(result)); | 21 callback.Run(static_cast<int>(result)); |
| 18 } | 22 } |
| 19 | 23 |
| 20 } | 24 } |
| 21 | 25 |
| 22 namespace net { | 26 namespace net { |
| 23 | 27 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 190 } |
| 187 | 191 |
| 188 void FileStream::Context::BeginOpenEvent(const base::FilePath& path) { | 192 void FileStream::Context::BeginOpenEvent(const base::FilePath& path) { |
| 189 std::string file_name = path.AsUTF8Unsafe(); | 193 std::string file_name = path.AsUTF8Unsafe(); |
| 190 bound_net_log_.BeginEvent(NetLog::TYPE_FILE_STREAM_OPEN, | 194 bound_net_log_.BeginEvent(NetLog::TYPE_FILE_STREAM_OPEN, |
| 191 NetLog::StringCallback("file_name", &file_name)); | 195 NetLog::StringCallback("file_name", &file_name)); |
| 192 } | 196 } |
| 193 | 197 |
| 194 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( | 198 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( |
| 195 const base::FilePath& path, int open_flags) { | 199 const base::FilePath& path, int open_flags) { |
| 196 // FileStream::Context actually closes the file asynchronously, independently | 200 base::PlatformFile file; |
| 197 // from FileStream's destructor. It can cause problems for users wanting to | 201 #if defined(OS_ANDROID) |
| 198 // delete the file right after FileStream deletion. Thus we are always | 202 if (path.IsContentUri()) { |
| 199 // adding SHARE_DELETE flag to accommodate such use case. | 203 // Check that only Read flags are set. |
| 200 open_flags |= base::PLATFORM_FILE_SHARE_DELETE; | 204 DCHECK_EQ(open_flags & ~base::PLATFORM_FILE_ASYNC, |
| 201 base::PlatformFile file = | 205 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
| 202 base::CreatePlatformFile(path, open_flags, NULL, NULL); | 206 file = base::OpenContentUriForRead(path); |
| 207 } else { |
| 208 #endif // defined(OS_ANDROID) |
| 209 // FileStream::Context actually closes the file asynchronously, |
| 210 // independently from FileStream's destructor. It can cause problems for |
| 211 // users wanting to delete the file right after FileStream deletion. Thus |
| 212 // we are always adding SHARE_DELETE flag to accommodate such use case. |
| 213 open_flags |= base::PLATFORM_FILE_SHARE_DELETE; |
| 214 file = base::CreatePlatformFile(path, open_flags, NULL, NULL); |
| 215 #if defined(OS_ANDROID) |
| 216 } |
| 217 #endif // defined(OS_ANDROID) |
| 203 if (file == base::kInvalidPlatformFileValue) | 218 if (file == base::kInvalidPlatformFileValue) |
| 204 return OpenResult(file, IOResult::FromOSError(GetLastErrno())); | 219 return OpenResult(file, IOResult::FromOSError(GetLastErrno())); |
| 205 | 220 |
| 206 return OpenResult(file, IOResult(OK, 0)); | 221 return OpenResult(file, IOResult(OK, 0)); |
| 207 } | 222 } |
| 208 | 223 |
| 209 void FileStream::Context::ProcessOpenError(const IOResult& error_code) { | 224 void FileStream::Context::ProcessOpenError(const IOResult& error_code) { |
| 210 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); | 225 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); |
| 211 RecordError(error_code, FILE_ERROR_SOURCE_OPEN); | 226 RecordError(error_code, FILE_ERROR_SOURCE_OPEN); |
| 212 } | 227 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // operation is in progress. | 276 // operation is in progress. |
| 262 async_in_progress_ = false; | 277 async_in_progress_ = false; |
| 263 if (orphaned_) | 278 if (orphaned_) |
| 264 CloseAndDelete(); | 279 CloseAndDelete(); |
| 265 else | 280 else |
| 266 callback.Run(result); | 281 callback.Run(result); |
| 267 } | 282 } |
| 268 | 283 |
| 269 } // namespace net | 284 } // namespace net |
| 270 | 285 |
| OLD | NEW |