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

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 fixes according to code review comments 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 #include <vector>
8 9
9 #include "base/android/build_info.h" 10 #include "base/android/build_info.h"
10 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 13 #include "base/android/jni_string.h"
12 #include "base/android/jni_weak_ref.h" 14 #include "base/android/jni_weak_ref.h"
15 #include "base/base64.h"
13 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
15 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_service.h" 19 #include "base/prefs/pref_service.h"
17 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
18 #include "base/values.h" 21 #include "base/values.h"
19 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h" 23 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover.h" 24 #include "chrome/browser/browsing_data/browsing_data_remover.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/net/prediction_options.h" 26 #include "chrome/browser/net/prediction_options.h"
24 #include "chrome/browser/prefs/incognito_mode_prefs.h" 27 #include "chrome/browser/prefs/incognito_mode_prefs.h"
25 #include "chrome/browser/profiles/profile_manager.h" 28 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/translate/chrome_translate_client.h" 29 #include "chrome/browser/translate/chrome_translate_client.h"
27 #include "chrome/browser/ui/android/android_about_app_info.h" 30 #include "chrome/browser/ui/android/android_about_app_info.h"
28 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
29 #include "chrome/grit/locale_settings.h" 32 #include "chrome/grit/locale_settings.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 33 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/content_settings/core/common/content_settings.h" 34 #include "components/content_settings/core/common/content_settings.h"
32 #include "components/content_settings/core/common/content_settings_pattern.h" 35 #include "components/content_settings/core/common/content_settings_pattern.h"
33 #include "components/content_settings/core/common/pref_names.h" 36 #include "components/content_settings/core/common/pref_names.h"
34 #include "components/metrics/metrics_pref_names.h" 37 #include "components/metrics/metrics_pref_names.h"
35 #include "components/password_manager/core/common/password_manager_pref_names.h" 38 #include "components/password_manager/core/common/password_manager_pref_names.h"
36 #include "components/signin/core/common/signin_pref_names.h" 39 #include "components/signin/core/common/signin_pref_names.h"
37 #include "components/translate/core/browser/translate_prefs.h" 40 #include "components/translate/core/browser/translate_prefs.h"
38 #include "components/translate/core/common/translate_pref_names.h" 41 #include "components/translate/core/common/translate_pref_names.h"
42 #include "components/variations/pref_names.h"
39 #include "components/version_info/version_info.h" 43 #include "components/version_info/version_info.h"
40 #include "components/web_resource/web_resource_pref_names.h" 44 #include "components/web_resource/web_resource_pref_names.h"
41 #include "content/public/browser/browser_thread.h" 45 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/user_metrics.h" 46 #include "content/public/browser/user_metrics.h"
43 #include "jni/PrefServiceBridge_jni.h" 47 #include "jni/PrefServiceBridge_jni.h"
44 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
45 49
46 using base::android::AttachCurrentThread; 50 using base::android::AttachCurrentThread;
47 using base::android::CheckException; 51 using base::android::CheckException;
48 using base::android::ConvertJavaStringToUTF8; 52 using base::android::ConvertJavaStringToUTF8;
49 using base::android::ConvertUTF8ToJavaString; 53 using base::android::ConvertUTF8ToJavaString;
54 using base::android::GetApplicationContext;
50 using base::android::ScopedJavaLocalRef; 55 using base::android::ScopedJavaLocalRef;
51 using base::android::ScopedJavaGlobalRef; 56 using base::android::ScopedJavaGlobalRef;
52 using content::BrowserThread; 57 using content::BrowserThread;
53 58
54 namespace { 59 namespace {
55 60
56 enum NetworkPredictionOptions { 61 enum NetworkPredictionOptions {
57 NETWORK_PREDICTION_ALWAYS, 62 NETWORK_PREDICTION_ALWAYS,
58 NETWORK_PREDICTION_WIFI_ONLY, 63 NETWORK_PREDICTION_WIFI_ONLY,
59 NETWORK_PREDICTION_NEVER, 64 NETWORK_PREDICTION_NEVER,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 content_settings->GetDefaultContentSetting(content_settings_type, &source); 109 content_settings->GetDefaultContentSetting(content_settings_type, &source);
105 HostContentSettingsMap::ProviderType provider = 110 HostContentSettingsMap::ProviderType provider =
106 content_settings->GetProviderTypeFromSource(source); 111 content_settings->GetProviderTypeFromSource(source);
107 return provider >= HostContentSettingsMap::PREF_PROVIDER; 112 return provider >= HostContentSettingsMap::PREF_PROVIDER;
108 } 113 }
109 114
110 PrefService* GetPrefService() { 115 PrefService* GetPrefService() {
111 return GetOriginalProfile()->GetPrefs(); 116 return GetOriginalProfile()->GetPrefs();
112 } 117 }
113 118
119 void JavaByteArrayToString(JNIEnv* env,
120 jbyteArray byte_array,
121 std::string* out) {
Alexei Svitkine (slow) 2015/11/03 18:34:03 I suggest just making this return the std::string(
Alexander Agulenko 2015/11/04 08:00:58 Removed this function at all. Done.
122 DCHECK(out);
123 if (!byte_array) {
124 out->clear();
125 return;
126 }
127 std::vector<uint8> array_data;
128 base::android::JavaByteArrayToByteVector(env, byte_array, &array_data);
129 std::string temp(array_data.begin(), array_data.end());
130 out->swap(temp);
131 }
132
114 } // namespace 133 } // namespace
115 134
116 // ---------------------------------------------------------------------------- 135 // ----------------------------------------------------------------------------
117 // Native JNI methods 136 // Native JNI methods
118 // ---------------------------------------------------------------------------- 137 // ----------------------------------------------------------------------------
119 138
120 static jboolean IsContentSettingManaged(JNIEnv* env, 139 static jboolean IsContentSettingManaged(JNIEnv* env,
121 const JavaParamRef<jobject>& obj, 140 const JavaParamRef<jobject>& obj,
122 int content_settings_type) { 141 int content_settings_type) {
123 return IsContentSettingManaged( 142 return IsContentSettingManaged(
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 ContentSettingsType content_type) { 960 ContentSettingsType content_type) {
942 JNIEnv* env = AttachCurrentThread(); 961 JNIEnv* env = AttachCurrentThread();
943 base::android::ScopedJavaLocalRef<jstring> android_permission = 962 base::android::ScopedJavaLocalRef<jstring> android_permission =
944 Java_PrefServiceBridge_getAndroidPermissionForContentSetting( 963 Java_PrefServiceBridge_getAndroidPermissionForContentSetting(
945 env, content_type); 964 env, content_type);
946 if (android_permission.is_null()) 965 if (android_permission.is_null())
947 return std::string(); 966 return std::string();
948 967
949 return ConvertJavaStringToUTF8(android_permission); 968 return ConvertJavaStringToUTF8(android_permission);
950 } 969 }
970
971 // static
972 void PrefServiceBridge::GetVariationsFirstRunSeed(
973 std::string* seed_data,
974 std::string* seed_signature,
975 std::string* seed_country) {
976 JNIEnv* env = AttachCurrentThread();
977 ScopedJavaLocalRef<jbyteArray> j_seed_data =
978 Java_PrefServiceBridge_getVariationsFirstRunSeedData(
Alexei Svitkine (slow) 2015/11/03 18:34:03 Nit: Run "git cl format", since you have the wrong
Alexander Agulenko 2015/11/04 08:00:58 Done.
979 env, GetApplicationContext());
980 ScopedJavaLocalRef<jstring> j_seed_signature =
981 Java_PrefServiceBridge_getVariationsFirstRunSeedSignature(
982 env, GetApplicationContext());
983 ScopedJavaLocalRef<jstring> j_seed_country =
984 Java_PrefServiceBridge_getVariationsFirstRunSeedCountry(
985 env, GetApplicationContext());
986 JavaByteArrayToString(env, j_seed_data.obj(), seed_data);
987 *seed_signature = ConvertJavaStringToUTF8(j_seed_signature);
988 *seed_country = ConvertJavaStringToUTF8(j_seed_country);
989 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698