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

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

Issue 2076163002: Migrate SequencedTaskRunnerHandle calls to TaskRunnerHandle calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mix_c_Ab_1_scheduler_support_parallelTRH
Patch Set: Created 4 years, 6 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
« no previous file with comments | « chrome/browser/win/settings_app_monitor.cc ('k') | components/safe_json/safe_json_parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/location.h" 10 #include "base/location.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/threading/sequenced_task_runner_handle.h" 14 #include "base/threading/task_runner_handle.h"
15 #include "jni/JsonSanitizer_jni.h" 15 #include "jni/JsonSanitizer_jni.h"
16 16
17 namespace safe_json { 17 namespace safe_json {
18 18
19 namespace { 19 namespace {
20 20
21 // An implementation of JsonSanitizer that calls into Java. It deals with 21 // An implementation of JsonSanitizer that calls into Java. It deals with
22 // malformed input (in particular malformed Unicode encodings) in the following 22 // malformed input (in particular malformed Unicode encodings) in the following
23 // steps: 23 // steps:
24 // 1. The input string is checked for whether it is well-formed UTF-8. Malformed 24 // 1. The input string is checked for whether it is well-formed UTF-8. Malformed
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 JNIEnv* env = base::android::AttachCurrentThread(); 68 JNIEnv* env = base::android::AttachCurrentThread();
69 base::android::ScopedJavaLocalRef<jstring> unsafe_json_java = 69 base::android::ScopedJavaLocalRef<jstring> unsafe_json_java =
70 base::android::ConvertUTF8ToJavaString(env, unsafe_json); 70 base::android::ConvertUTF8ToJavaString(env, unsafe_json);
71 71
72 // This will synchronously call either OnSuccess() or OnError(). 72 // This will synchronously call either OnSuccess() or OnError().
73 Java_JsonSanitizer_sanitize(env, reinterpret_cast<jlong>(this), 73 Java_JsonSanitizer_sanitize(env, reinterpret_cast<jlong>(this),
74 unsafe_json_java.obj()); 74 unsafe_json_java.obj());
75 } 75 }
76 76
77 void JsonSanitizerAndroid::OnSuccess(const std::string& json) { 77 void JsonSanitizerAndroid::OnSuccess(const std::string& json) {
78 base::SequencedTaskRunnerHandle::Get()->PostTask( 78 base::TaskRunnerHandle::Get()->PostTask(FROM_HERE,
79 FROM_HERE, base::Bind(success_callback_, json)); 79 base::Bind(success_callback_, json));
80 } 80 }
81 81
82 void JsonSanitizerAndroid::OnError(const std::string& error) { 82 void JsonSanitizerAndroid::OnError(const std::string& error) {
83 base::SequencedTaskRunnerHandle::Get()->PostTask( 83 base::TaskRunnerHandle::Get()->PostTask(FROM_HERE,
84 FROM_HERE, base::Bind(error_callback_, error)); 84 base::Bind(error_callback_, error));
85 } 85 }
86 86
87 } // namespace 87 } // namespace
88 88
89 void OnSuccess(JNIEnv* env, 89 void OnSuccess(JNIEnv* env,
90 const JavaParamRef<jclass>& clazz, 90 const JavaParamRef<jclass>& clazz,
91 jlong jsanitizer, 91 jlong jsanitizer,
92 const JavaParamRef<jstring>& json) { 92 const JavaParamRef<jstring>& json) {
93 JsonSanitizerAndroid* sanitizer = 93 JsonSanitizerAndroid* sanitizer =
94 reinterpret_cast<JsonSanitizerAndroid*>(jsanitizer); 94 reinterpret_cast<JsonSanitizerAndroid*>(jsanitizer);
(...skipping 19 matching lines...) Expand all
114 JsonSanitizerAndroid sanitizer(success_callback, error_callback); 114 JsonSanitizerAndroid sanitizer(success_callback, error_callback);
115 sanitizer.Sanitize(unsafe_json); 115 sanitizer.Sanitize(unsafe_json);
116 } 116 }
117 117
118 // static 118 // static
119 bool JsonSanitizer::Register(JNIEnv* env) { 119 bool JsonSanitizer::Register(JNIEnv* env) {
120 return RegisterNativesImpl(env); 120 return RegisterNativesImpl(env);
121 } 121 }
122 122
123 } // namespace safe_json 123 } // namespace safe_json
OLDNEW
« no previous file with comments | « chrome/browser/win/settings_app_monitor.cc ('k') | components/safe_json/safe_json_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698