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

Side by Side Diff: chrome/browser/android/chrome_backup_agent.cc

Issue 2877703006: Add functions to convert boolean jni array. (Closed)
Patch Set: Created 3 years, 7 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 | « base/android/jni_array_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <jni.h> 5 #include <jni.h>
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return base::android::ScopedJavaLocalRef<jbooleanArray>(env, array); 67 return base::android::ScopedJavaLocalRef<jbooleanArray>(env, array);
68 } 68 }
69 69
70 static void SetBoolBackupPrefs( 70 static void SetBoolBackupPrefs(
71 JNIEnv* env, 71 JNIEnv* env,
72 const base::android::JavaParamRef<jobject>& jcaller, 72 const base::android::JavaParamRef<jobject>& jcaller,
73 const base::android::JavaParamRef<jobjectArray>& names, 73 const base::android::JavaParamRef<jobjectArray>& names,
74 const base::android::JavaParamRef<jbooleanArray>& values) { 74 const base::android::JavaParamRef<jbooleanArray>& values) {
75 std::vector<std::string> pref_names; 75 std::vector<std::string> pref_names;
76 base::android::AppendJavaStringArrayToStringVector(env, names, &pref_names); 76 base::android::AppendJavaStringArrayToStringVector(env, names, &pref_names);
77 jboolean* pref_values = env->GetBooleanArrayElements(values, nullptr); 77 std::vector<bool> pref_values;
78 JavaBooleanArrayToBoolVector(env, values, &pref_values);
78 std::unordered_set<std::string> valid_prefs( 79 std::unordered_set<std::string> valid_prefs(
79 std::begin(backed_up_preferences_), std::end(backed_up_preferences_)); 80 std::begin(backed_up_preferences_), std::end(backed_up_preferences_));
80 81
81 PrefService* prefs = ProfileManager::GetLastUsedProfile()->GetPrefs(); 82 PrefService* prefs = ProfileManager::GetLastUsedProfile()->GetPrefs();
82 for (unsigned int i = 0; i < pref_names.size(); i++) { 83 for (unsigned int i = 0; i < pref_names.size(); i++) {
83 if (valid_prefs.count(pref_names[i])) { 84 if (valid_prefs.count(pref_names[i])) {
84 prefs->SetBoolean(pref_names[i], pref_values[i]); 85 prefs->SetBoolean(pref_names[i], pref_values[i]);
85 } 86 }
86 } 87 }
87 prefs->CommitPendingWrite(); 88 prefs->CommitPendingWrite();
(...skipping 26 matching lines...) Expand all
114 void SetBoolBackupPrefsForTesting( 115 void SetBoolBackupPrefsForTesting(
115 JNIEnv* env, 116 JNIEnv* env,
116 const base::android::JavaParamRef<jobject>& jcaller, 117 const base::android::JavaParamRef<jobject>& jcaller,
117 const base::android::JavaParamRef<jobjectArray>& names, 118 const base::android::JavaParamRef<jobjectArray>& names,
118 const base::android::JavaParamRef<jbooleanArray>& values) { 119 const base::android::JavaParamRef<jbooleanArray>& values) {
119 SetBoolBackupPrefs(env, jcaller, names, values); 120 SetBoolBackupPrefs(env, jcaller, names, values);
120 } 121 }
121 122
122 } // namespace android 123 } // namespace android
123 } // namespace chrome 124 } // namespace chrome
OLDNEW
« no previous file with comments | « base/android/jni_array_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698