Chromium Code Reviews| Index: net/base/file_stream_context.cc |
| diff --git a/net/base/file_stream_context.cc b/net/base/file_stream_context.cc |
| index 2e774752045d9c0d0e6a8c82dc3dfc7a6bb9c366..c79fa0803deb9061b65b16367f8de15bc77ef3a3 100644 |
| --- a/net/base/file_stream_context.cc |
| +++ b/net/base/file_stream_context.cc |
| @@ -11,6 +11,10 @@ |
| #include "net/base/file_stream_net_log_parameters.h" |
| #include "net/base/net_errors.h" |
| +#if defined(OS_ANDROID) |
| +#include "base/android/content_uri_utils.h" |
| +#endif |
| + |
| namespace { |
| void CallInt64ToInt(const net::CompletionCallback& callback, int64 result) { |
| @@ -64,6 +68,12 @@ void FileStream::Context::Orphan() { |
| void FileStream::Context::OpenAsync(const base::FilePath& path, |
| int open_flags, |
| const CompletionCallback& callback) { |
| +#if defined(OS_ANDROID) |
| + if (path.IsContentUrl()) { |
| + OpenContentUrlAsync(path, open_flags, callback); |
| + return; |
| + } |
| +#endif |
|
mmenke
2013/11/05 02:33:19
Can't you just move all content URL code down int
qinmin
2013/11/05 03:38:41
Done.
|
| DCHECK(!async_in_progress_); |
| BeginOpenEvent(path); |
| @@ -80,6 +90,10 @@ void FileStream::Context::OpenAsync(const base::FilePath& path, |
| } |
| int FileStream::Context::OpenSync(const base::FilePath& path, int open_flags) { |
| +#if defined(OS_ANDROID) |
| + if (path.IsContentUrl()) |
| + return OpenContentUrlSync(path, open_flags); |
| +#endif |
| DCHECK(!async_in_progress_); |
| BeginOpenEvent(path); |
| @@ -266,5 +280,50 @@ void FileStream::Context::OnAsyncCompleted( |
| callback.Run(result); |
| } |
| +#if defined(OS_ANDROID) |
| +void FileStream::Context::OpenContentUrlAsync( |
| + const base::FilePath& path, |
| + int open_flags, |
| + const CompletionCallback& callback) { |
| + DCHECK(!async_in_progress_); |
| + const bool posted = base::PostTaskAndReplyWithResult( |
| + task_runner_.get(), |
| + FROM_HERE, |
| + base::Bind(&Context::OpenContentUrlImpl, base::Unretained(this), |
| + path, open_flags), |
| + base::Bind(&Context::OnOpenCompleted, base::Unretained(this), callback)); |
| + DCHECK(posted); |
| + |
| + async_in_progress_ = true; |
| +} |
| + |
| +int FileStream::Context::OpenContentUrlSync( |
| + const base::FilePath& path, int open_flags) { |
| + DCHECK(!async_in_progress_); |
| + |
| + OpenResult result = OpenContentUrlImpl(path, open_flags); |
| + file_ = result.file; |
| + if (file_ == base::kInvalidPlatformFileValue) { |
| + ProcessOpenError(result.error_code); |
| + } else { |
| + if (open_flags & base::PLATFORM_FILE_ASYNC) |
| + OnAsyncFileOpened(); |
| + } |
| + return result.error_code.result; |
| +} |
| + |
| +FileStream::Context::OpenResult FileStream::Context::OpenContentUrlImpl( |
| + const base::FilePath& path, int open_flags) { |
| + // Check that only Read flags are set. |
| + DCHECK_EQ(open_flags & ~base::PLATFORM_FILE_ASYNC, |
| + base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
| + base::PlatformFile file = base::OpenContentUrlForRead(path); |
| + if (file == base::kInvalidPlatformFileValue) |
| + return OpenResult(file, IOResult::FromOSError(GetLastErrno())); |
| + |
| + return OpenResult(file, IOResult(OK, 0)); |
| +} |
| +#endif |
| + |
| } // namespace net |