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

Side by Side Diff: base/android/jni_registrar.cc

Issue 10591005: Add a way for JNI registrars to specify methods to be registered for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « base/android/jni_registrar.h ('k') | content/app/android/content_jni_registrar.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/android/jni_registrar.h" 5 #include "base/android/jni_registrar.h"
6 6
7 #include <vector>
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
9 10
10 namespace base { 11 namespace base {
11 namespace android { 12 namespace android {
12 13
14 typedef std::vector<RegistrationMethod> RegistrationMethodList;
15
16 // Retrieve a reference to the global RegistrationMethods list.
17 RegistrationMethodList &GetRegistrationMethodList() {
18 static RegistrationMethodList test_registration_method_list;
19 return test_registration_method_list;
20 }
21
22 AppendRegistrationMethods::AppendRegistrationMethods(
23 const RegistrationMethod* methods, size_t count) {
24 const RegistrationMethod* end = methods + count;
25 while (methods != end) {
26 GetRegistrationMethodList().push_back(*methods);
27 LOG(ERROR) << "Adding method:" << methods->name;
28 methods++;
29 }
30 }
31
32 bool RegisterAllNativeMethodsForTest(JNIEnv* env) {
33 RegistrationMethodList& native_methods = GetRegistrationMethodList();
34 for (RegistrationMethodList::iterator it = native_methods.begin();
35 it != native_methods.end(); ++it) {
36 if (!it->func(env) < 0) {
37 DLOG(ERROR) << it->name << " failed registration!";
38 return false;
39 }
40 LOG(ERROR) << "Registering method:" << it->name;
41 }
42 return true;
43 }
44
13 bool RegisterNativeMethods(JNIEnv* env, 45 bool RegisterNativeMethods(JNIEnv* env,
14 const RegistrationMethod* method, 46 const RegistrationMethod* method,
15 size_t count) { 47 size_t count) {
16 const RegistrationMethod* end = method + count; 48 const RegistrationMethod* end = method + count;
17 while (method != end) { 49 while (method != end) {
18 if (!method->func(env) < 0) { 50 if (!method->func(env) < 0) {
19 DLOG(ERROR) << method->name << " failed registration!"; 51 DLOG(ERROR) << method->name << " failed registration!";
20 return false; 52 return false;
21 } 53 }
22 method++; 54 method++;
23 } 55 }
24 return true; 56 return true;
25 } 57 }
26 58
27 } // namespace android 59 } // namespace android
28 } // namespace base 60 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_registrar.h ('k') | content/app/android/content_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698