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

Side by Side Diff: components/safe_json/json_sanitizer_android.cc

Issue 1312153003: jni_generator: Pass object parameters as JavaParamRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/safe_json/json_sanitizer.h" 5 #include "components/safe_json/json_sanitizer.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 base::Bind(success_callback_, json)); 77 base::Bind(success_callback_, json));
78 } 78 }
79 79
80 void JsonSanitizerAndroid::OnError(const std::string& error) { 80 void JsonSanitizerAndroid::OnError(const std::string& error) {
81 base::MessageLoop::current()->PostTask(FROM_HERE, 81 base::MessageLoop::current()->PostTask(FROM_HERE,
82 base::Bind(error_callback_, error)); 82 base::Bind(error_callback_, error));
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 void OnSuccess(JNIEnv* env, jclass clazz, jlong jsanitizer, jstring json) { 87 void OnSuccess(JNIEnv* env,
88 const JavaParamRef<jclass>& clazz,
89 jlong jsanitizer,
90 const JavaParamRef<jstring>& json) {
88 JsonSanitizerAndroid* sanitizer = 91 JsonSanitizerAndroid* sanitizer =
89 reinterpret_cast<JsonSanitizerAndroid*>(jsanitizer); 92 reinterpret_cast<JsonSanitizerAndroid*>(jsanitizer);
90 sanitizer->OnSuccess(base::android::ConvertJavaStringToUTF8(env, json)); 93 sanitizer->OnSuccess(base::android::ConvertJavaStringToUTF8(env, json));
91 } 94 }
92 95
93 void OnError(JNIEnv* env, jclass clazz, jlong jsanitizer, jstring error) { 96 void OnError(JNIEnv* env,
97 const JavaParamRef<jclass>& clazz,
98 jlong jsanitizer,
99 const JavaParamRef<jstring>& error) {
94 JsonSanitizerAndroid* sanitizer = 100 JsonSanitizerAndroid* sanitizer =
95 reinterpret_cast<JsonSanitizerAndroid*>(jsanitizer); 101 reinterpret_cast<JsonSanitizerAndroid*>(jsanitizer);
96 sanitizer->OnError(base::android::ConvertJavaStringToUTF8(env, error)); 102 sanitizer->OnError(base::android::ConvertJavaStringToUTF8(env, error));
97 } 103 }
98 104
99 // static 105 // static
100 void JsonSanitizer::Sanitize(const std::string& unsafe_json, 106 void JsonSanitizer::Sanitize(const std::string& unsafe_json,
101 const StringCallback& success_callback, 107 const StringCallback& success_callback,
102 const StringCallback& error_callback) { 108 const StringCallback& error_callback) {
103 // JsonSanitizerAndroid does all its work synchronously, but posts any 109 // JsonSanitizerAndroid does all its work synchronously, but posts any
104 // callbacks to the current message loop. This means it can be destroyed at 110 // callbacks to the current message loop. This means it can be destroyed at
105 // the end of this method. 111 // the end of this method.
106 JsonSanitizerAndroid sanitizer(success_callback, error_callback); 112 JsonSanitizerAndroid sanitizer(success_callback, error_callback);
107 sanitizer.Sanitize(unsafe_json); 113 sanitizer.Sanitize(unsafe_json);
108 } 114 }
109 115
110 // static 116 // static
111 bool JsonSanitizer::Register(JNIEnv* env) { 117 bool JsonSanitizer::Register(JNIEnv* env) {
112 return RegisterNativesImpl(env); 118 return RegisterNativesImpl(env);
113 } 119 }
114 120
115 } // namespace safe_json 121 } // namespace safe_json
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698