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

Unified Diff: net/android/content_uri_utils.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, 2 months 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/android/content_uri_utils.cc
diff --git a/net/android/content_uri_utils.cc b/net/android/content_uri_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ec42ef1b86ec9b58eddaa6197090c624537a984
--- /dev/null
+++ b/net/android/content_uri_utils.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/android/content_uri_utils.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/location.h"
+#include "base/task_runner.h"
+#include "base/task_runner_util.h"
+#include "jni/ContentUriUtils_jni.h"
+#include "net/base/net_errors.h"
+
+using base::android::ConvertUTF8ToJavaString;
+
+namespace net {
+
+namespace {
+
+int64 GetLengthInternal(const base::FilePath& content_url) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> j_uri =
+ ConvertUTF8ToJavaString(env, content_url.value());
+ jlong length = Java_ContentUriUtils_getContentLength(
+ env, base::android::GetApplicationContext(), j_uri.obj());
+ return length;
+}
+
+void OnGetLengthCompleted(
+ const net::Int64CompletionCallback& callback, int64 length) {
+ callback.Run(length);
+}
+
+} // namespace
+
+bool RegisterContentUriUtils(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+int64 GetContentUrlLength(base::TaskRunner* task_runner,
+ const base::FilePath& content_url,
+ const net::Int64CompletionCallback& callback) {
+ bool posted = base::PostTaskAndReplyWithResult(
+ task_runner,
+ FROM_HERE,
+ base::Bind(&GetLengthInternal, content_url),
+ base::Bind(&OnGetLengthCompleted, callback));
+ DCHECK(posted);
+ return net::ERR_IO_PENDING;
+}
+
+int64 GetContentUrlLengthSync(const base::FilePath& content_url) {
+ return GetLengthInternal(content_url);
+}
+
+int OpenContentUrlForRead(const base::FilePath& content_url) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> j_uri =
+ ConvertUTF8ToJavaString(env, content_url.value());
+ jint fd = Java_ContentUriUtils_openContentUriForRead(
+ env, base::android::GetApplicationContext(), j_uri.obj());
+ if (fd < 0)
+ return base::kInvalidPlatformFileValue;
+ return fd;
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698