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

Side by Side Diff: chrome/browser/android/preferences/pref_service_bridge.cc

Issue 1417503010: Variations seed is pulled from the Java application on the first launch of Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fix: removed debug output Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/android/preferences/pref_service_bridge.h" 5 #include "chrome/browser/android/preferences/pref_service_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/android/jni_weak_ref.h" 12 #include "base/android/jni_weak_ref.h"
13 #include "base/base64.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h" 21 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover.h" 22 #include "chrome/browser/browsing_data/browsing_data_remover.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/net/prediction_options.h" 24 #include "chrome/browser/net/prediction_options.h"
24 #include "chrome/browser/prefs/incognito_mode_prefs.h" 25 #include "chrome/browser/prefs/incognito_mode_prefs.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/translate/chrome_translate_client.h" 27 #include "chrome/browser/translate/chrome_translate_client.h"
27 #include "chrome/browser/ui/android/android_about_app_info.h" 28 #include "chrome/browser/ui/android/android_about_app_info.h"
28 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
29 #include "chrome/grit/locale_settings.h" 30 #include "chrome/grit/locale_settings.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 31 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/content_settings/core/common/content_settings.h" 32 #include "components/content_settings/core/common/content_settings.h"
32 #include "components/content_settings/core/common/content_settings_pattern.h" 33 #include "components/content_settings/core/common/content_settings_pattern.h"
33 #include "components/content_settings/core/common/pref_names.h" 34 #include "components/content_settings/core/common/pref_names.h"
34 #include "components/metrics/metrics_pref_names.h" 35 #include "components/metrics/metrics_pref_names.h"
35 #include "components/password_manager/core/common/password_manager_pref_names.h" 36 #include "components/password_manager/core/common/password_manager_pref_names.h"
36 #include "components/signin/core/common/signin_pref_names.h" 37 #include "components/signin/core/common/signin_pref_names.h"
37 #include "components/translate/core/browser/translate_prefs.h" 38 #include "components/translate/core/browser/translate_prefs.h"
38 #include "components/translate/core/common/translate_pref_names.h" 39 #include "components/translate/core/common/translate_pref_names.h"
40 #include "components/variations/pref_names.h"
39 #include "components/version_info/version_info.h" 41 #include "components/version_info/version_info.h"
40 #include "components/web_resource/web_resource_pref_names.h" 42 #include "components/web_resource/web_resource_pref_names.h"
41 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/user_metrics.h" 44 #include "content/public/browser/user_metrics.h"
43 #include "jni/PrefServiceBridge_jni.h" 45 #include "jni/PrefServiceBridge_jni.h"
44 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
45 47
46 using base::android::AttachCurrentThread; 48 using base::android::AttachCurrentThread;
47 using base::android::CheckException; 49 using base::android::CheckException;
48 using base::android::ConvertJavaStringToUTF8; 50 using base::android::ConvertJavaStringToUTF8;
49 using base::android::ConvertUTF8ToJavaString; 51 using base::android::ConvertUTF8ToJavaString;
52 using base::android::GetApplicationContext;
50 using base::android::ScopedJavaLocalRef; 53 using base::android::ScopedJavaLocalRef;
51 using base::android::ScopedJavaGlobalRef; 54 using base::android::ScopedJavaGlobalRef;
52 using content::BrowserThread; 55 using content::BrowserThread;
53 56
54 namespace { 57 namespace {
55 58
56 enum NetworkPredictionOptions { 59 enum NetworkPredictionOptions {
57 NETWORK_PREDICTION_ALWAYS, 60 NETWORK_PREDICTION_ALWAYS,
58 NETWORK_PREDICTION_WIFI_ONLY, 61 NETWORK_PREDICTION_WIFI_ONLY,
59 NETWORK_PREDICTION_NEVER, 62 NETWORK_PREDICTION_NEVER,
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 ContentSettingsType content_type) { 944 ContentSettingsType content_type) {
942 JNIEnv* env = AttachCurrentThread(); 945 JNIEnv* env = AttachCurrentThread();
943 base::android::ScopedJavaLocalRef<jstring> android_permission = 946 base::android::ScopedJavaLocalRef<jstring> android_permission =
944 Java_PrefServiceBridge_getAndroidPermissionForContentSetting( 947 Java_PrefServiceBridge_getAndroidPermissionForContentSetting(
945 env, content_type); 948 env, content_type);
946 if (android_permission.is_null()) 949 if (android_permission.is_null())
947 return std::string(); 950 return std::string();
948 951
949 return ConvertJavaStringToUTF8(android_permission); 952 return ConvertJavaStringToUTF8(android_permission);
950 } 953 }
954
955 // static
956 std::string PrefServiceBridge::PullVariationsSeedPref(
Alexei Svitkine (slow) 2015/10/28 15:16:38 Instead of being able to pass arbitrary pref names
Alexander Agulenko 2015/10/28 23:05:09 Done.
957 const std::string& prefName) {
958 if (prefName == variations::prefs::kVariationsSeed) {
Alexei Svitkine (slow) 2015/10/28 15:16:38 Nit: No {}'s
Alexander Agulenko 2015/10/28 23:05:09 Done.
959 return PullRawVariationsSeed();
960 }
961 JNIEnv* env = AttachCurrentThread();
962 ScopedJavaLocalRef<jstring> j_pref_name = ConvertUTF8ToJavaString(env,
963 prefName);
964 base::android::ScopedJavaLocalRef<jstring> pref_data =
965 Java_PrefServiceBridge_getVariationsSeedPref(env, GetApplicationContext(),
966 j_pref_name.obj());
967 return ConvertJavaStringToUTF8(pref_data);
968 }
969
970 // static
971 std::string PrefServiceBridge::PullRawVariationsSeed() {
972 JNIEnv* env = AttachCurrentThread();
973 ScopedJavaLocalRef<jbyteArray> array =
974 Java_PrefServiceBridge_getRawVariationsSeed(env, GetApplicationContext());
975 if (array.is_null()) {
976 return std::string();
977 }
978 int array_length = env->GetArrayLength(array.obj());
979 /* std::string seed;
Steven Holte 2015/10/28 01:00:18 Looks like unfinished code?
Alexander Agulenko 2015/10/28 23:05:09 Done.
Alexander Agulenko 2015/10/28 23:05:09 Yes, this piece of code has been changed in Patch
980 seed.resize(array_length);
981 env->GetByteArrayRegion(array.obj(), 0, array_length,
982 reinterpret_cast<jbyte*>(&(seed[0])));
983 return seed; */
984 char* buf = new char[array_length];
985 env->GetByteArrayRegion(array.obj(), 0, array_length,
986 reinterpret_cast<jbyte*>(buf));
987 std::string seed(buf, buf + array_length);
988 delete[] buf;
989 return seed;
990 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698