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

Side by Side Diff: components/payments/android/payment_manifest_downloader_android.cc

Issue 2645813006: Download web payment manifests. (Closed)
Patch Set: WIP Downloader tests - do not review Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/payments/android/payment_manifest_downloader_android.h"
6
7 #include <memory>
8 #include <unordered_map>
9 #include <utility>
10
11 #include "base/android/jni_string.h"
12 #include "base/android/scoped_java_ref.h"
13 #include "base/bind.h"
14 #include "base/memory/ptr_util.h"
15 #include "components/payments/payment_manifest_downloader.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/storage_partition.h"
18 #include "content/public/browser/web_contents.h"
19 #include "jni/PaymentManifestDownloader_jni.h"
20 #include "net/url_request/url_request_context_getter.h"
21
22 namespace payments {
23 namespace {
24
25 class SelfDeletingDownloadDelegate
26 : public payments::PaymentManifestDownloader::Delegate {
27 public:
28 explicit SelfDeletingDownloadDelegate(
29 const base::android::JavaParamRef<jobject>& jcallback)
30 : jcallback_(jcallback) {}
31
32 void set_downloader(
33 std::unique_ptr<payments::PaymentManifestDownloader> downloader) {
34 downloader_ = std::move(downloader);
35 }
36
37 void Download() { downloader_->Download(); }
38
39 // payments::PaymentManifestDownloader::Delegate
40 void OnManifestDownloadSuccess(const std::string& content) override {
41 JNIEnv* env = base::android::AttachCurrentThread();
42 payments::Java_ManifestDownloadCallback_onManifestDownloadSuccess(
43 env, jcallback_, base::android::ConvertUTF8ToJavaString(env, content));
44 delete this;
45 }
46
47 // payments::PaymentManifestDownloader::Delegate
48 void OnManifestDownloadFailure() override {
49 payments::Java_ManifestDownloadCallback_onManifestDownloadFailure(
50 base::android::AttachCurrentThread(), jcallback_);
51 delete this;
52 }
53
54 private:
55 ~SelfDeletingDownloadDelegate() override {}
56
57 base::android::ScopedJavaGlobalRef<jobject> jcallback_;
58 std::unique_ptr<payments::PaymentManifestDownloader> downloader_;
59
60 DISALLOW_COPY_AND_ASSIGN(SelfDeletingDownloadDelegate);
61 };
62
63 } // namespace
64
65 void DownloadPaymentManifest(
66 JNIEnv* env,
67 const base::android::JavaParamRef<jclass>& jcaller,
68 const base::android::JavaParamRef<jobject>& jweb_contents,
69 const base::android::JavaParamRef<jstring>& jmethod_name,
70 const base::android::JavaParamRef<jobject>& jcallback) {
71 SelfDeletingDownloadDelegate* delegate =
72 new SelfDeletingDownloadDelegate(jcallback);
73
74 content::WebContents* web_contents =
75 content::WebContents::FromJavaWebContents(jweb_contents);
76 if (!web_contents) {
77 delegate->OnManifestDownloadFailure();
78 return;
79 }
80
81 std::unique_ptr<payments::PaymentManifestDownloader> downloader =
82 base::MakeUnique<payments::PaymentManifestDownloader>(
83 content::BrowserContext::GetDefaultStoragePartition(
84 web_contents->GetBrowserContext())
85 ->GetURLRequestContext(),
86 base::android::ConvertJavaStringToUTF8(env, jmethod_name), delegate);
palmer 2017/01/27 00:11:47 I think here might be a better place to convert th
please use gerrit instead 2017/02/23 19:57:50 The code now uses a URL all up and down the Java/n
87 delegate->set_downloader(std::move(downloader));
88 delegate->Download();
89 }
90
91 } // namespace payments
92
93 bool RegisterPaymentManifestDownloader(JNIEnv* env) {
94 return payments::RegisterNativesImpl(env);
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698