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

Unified Diff: net/base/file_stream_context.cc

Issue 46303005: Fix chrome upload with content uri (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing comments 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698