Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <vector> | |
| 9 | 10 |
| 10 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
| 11 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_array.h" | |
| 12 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 13 #include "base/android/jni_weak_ref.h" | 15 #include "base/android/jni_weak_ref.h" |
| 14 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 19 #include "base/values.h" | 21 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | |
| 21 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 24 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 22 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 25 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 26 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 24 #include "chrome/browser/net/prediction_options.h" | 27 #include "chrome/browser/net/prediction_options.h" |
| 25 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 28 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/translate/chrome_translate_client.h" | 30 #include "chrome/browser/translate/chrome_translate_client.h" |
| 28 #include "chrome/browser/ui/android/android_about_app_info.h" | 31 #include "chrome/browser/ui/android/android_about_app_info.h" |
| 29 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/grit/locale_settings.h" | 33 #include "chrome/grit/locale_settings.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 if (weak_chrome_native_preferences_.get(env).is_null()) | 488 if (weak_chrome_native_preferences_.get(env).is_null()) |
| 486 return; | 489 return; |
| 487 | 490 |
| 488 Java_PrefServiceBridge_browsingDataCleared( | 491 Java_PrefServiceBridge_browsingDataCleared( |
| 489 env, weak_chrome_native_preferences_.get(env).obj()); | 492 env, weak_chrome_native_preferences_.get(env).obj()); |
| 490 } | 493 } |
| 491 | 494 |
| 492 private: | 495 private: |
| 493 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; | 496 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; |
| 494 }; | 497 }; |
| 498 | |
| 495 } // namespace | 499 } // namespace |
| 496 | 500 |
| 501 static jboolean GetBrowsingDataDeletionPreference( | |
| 502 JNIEnv* env, | |
| 503 const JavaParamRef<jobject>& obj, | |
| 504 jint data_type) { | |
| 505 DCHECK_GE(data_type, 0); | |
| 506 DCHECK_LE(data_type, ClankBrowsingDataType::NUM_TYPES); | |
| 507 | |
| 508 // If there is no corresponding preference for this |data_type|, pretend | |
| 509 // that it's set to false. | |
| 510 // TODO(msramek): Consider defining native-side preferences for all Java UI | |
| 511 // data types for consistency. | |
| 512 std::string pref; | |
| 513 if (GetDeletionPreferenceFromDataType( | |
| 514 static_cast<ClankBrowsingDataType>(data_type), &pref)) { | |
| 515 return false; | |
| 516 } | |
| 517 | |
| 518 return GetOriginalProfile()->GetPrefs()->GetBoolean(pref); | |
| 519 } | |
| 520 | |
| 521 static void SetBrowsingDataDeletionPreference( | |
| 522 JNIEnv* env, | |
| 523 const JavaParamRef<jobject>& obj, | |
| 524 jint data_type, | |
| 525 jboolean value) { | |
| 526 DCHECK_GE(data_type, 0); | |
| 527 DCHECK_LE(data_type, ClankBrowsingDataType::NUM_TYPES); | |
| 528 | |
| 529 std::string pref; | |
| 530 if (!GetDeletionPreferenceFromDataType( | |
| 531 static_cast<ClankBrowsingDataType>(data_type), &pref)) { | |
| 532 return; | |
| 533 } | |
| 534 | |
| 535 GetOriginalProfile()->GetPrefs()->SetBoolean(pref, value); | |
| 536 } | |
| 537 | |
| 497 static void ClearBrowsingData(JNIEnv* env, | 538 static void ClearBrowsingData(JNIEnv* env, |
| 498 const JavaParamRef<jobject>& obj, | 539 const JavaParamRef<jobject>& obj, |
| 499 jboolean history, | 540 const JavaParamRef<jintArray>& data_types) { |
| 500 jboolean cache, | |
| 501 jboolean cookies_and_site_data, | |
| 502 jboolean passwords, | |
| 503 jboolean form_data) { | |
| 504 // BrowsingDataRemover deletes itself. | 541 // BrowsingDataRemover deletes itself. |
| 505 BrowsingDataRemover* browsing_data_remover = | 542 BrowsingDataRemover* browsing_data_remover = |
| 506 BrowsingDataRemover::CreateForPeriod( | 543 BrowsingDataRemover::CreateForPeriod( |
| 507 GetOriginalProfile(), | 544 GetOriginalProfile(), |
| 508 static_cast<BrowsingDataRemover::TimePeriod>( | 545 static_cast<BrowsingDataRemover::TimePeriod>( |
| 509 BrowsingDataRemover::EVERYTHING)); | 546 BrowsingDataRemover::EVERYTHING)); |
| 510 browsing_data_remover->AddObserver(new ClearBrowsingDataObserver(env, obj)); | 547 browsing_data_remover->AddObserver(new ClearBrowsingDataObserver(env, obj)); |
| 511 | 548 |
| 549 std::vector<int> data_types_vector; | |
| 550 base::android::JavaIntArrayToIntVector(env, data_types, &data_types_vector); | |
| 551 | |
| 512 int remove_mask = 0; | 552 int remove_mask = 0; |
| 513 if (history) | 553 for (const int data_type : data_types_vector) { |
|
newt (away)
2016/01/12 18:55:26
Rather than converting from ClankBrowsingDataType
msramek
2016/01/13 15:27:53
Hmm, that's a bit tricky.
I would like to have re
newt (away)
2016/01/13 20:01:49
Thanks for the detailed explanation.
I hadn't loo
msramek
2016/01/14 15:45:43
On Android, we show bookmarks only in the ClearSyn
| |
| 514 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; | 554 switch (static_cast<ClankBrowsingDataType>(data_type)) { |
| 515 if (cache) | 555 case HISTORY: |
| 516 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; | 556 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; |
| 517 if (cookies_and_site_data) { | 557 break; |
| 518 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | 558 case CACHE: |
| 519 remove_mask |= BrowsingDataRemover::REMOVE_SITE_DATA; | 559 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; |
| 560 break; | |
| 561 case COOKIES: | |
| 562 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | |
| 563 remove_mask |= BrowsingDataRemover::REMOVE_SITE_DATA; | |
| 564 break; | |
| 565 case PASSWORDS: | |
| 566 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | |
| 567 break; | |
| 568 case FORM_DATA: | |
| 569 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | |
| 570 break; | |
| 571 default: | |
| 572 NOTREACHED(); | |
| 573 } | |
| 520 } | 574 } |
| 521 if (passwords) | 575 |
| 522 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | |
| 523 if (form_data) | |
| 524 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | |
| 525 browsing_data_remover->Remove(remove_mask, | 576 browsing_data_remover->Remove(remove_mask, |
| 526 BrowsingDataHelper::UNPROTECTED_WEB); | 577 BrowsingDataHelper::UNPROTECTED_WEB); |
| 527 } | 578 } |
| 528 | 579 |
| 529 static jboolean CanDeleteBrowsingHistory(JNIEnv* env, | 580 static jboolean CanDeleteBrowsingHistory(JNIEnv* env, |
| 530 const JavaParamRef<jobject>& obj) { | 581 const JavaParamRef<jobject>& obj) { |
| 531 return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory); | 582 return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
| 532 } | 583 } |
| 533 | 584 |
| 534 static void SetAllowCookiesEnabled(JNIEnv* env, | 585 static void SetAllowCookiesEnabled(JNIEnv* env, |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 | 1005 |
| 955 return ConvertJavaStringToUTF8(android_permission); | 1006 return ConvertJavaStringToUTF8(android_permission); |
| 956 } | 1007 } |
| 957 | 1008 |
| 958 static void SetSupervisedUserId(JNIEnv* env, | 1009 static void SetSupervisedUserId(JNIEnv* env, |
| 959 const JavaParamRef<jobject>& obj, | 1010 const JavaParamRef<jobject>& obj, |
| 960 const JavaParamRef<jstring>& pref) { | 1011 const JavaParamRef<jstring>& pref) { |
| 961 GetPrefService()->SetString(prefs::kSupervisedUserId, | 1012 GetPrefService()->SetString(prefs::kSupervisedUserId, |
| 962 ConvertJavaStringToUTF8(env, pref)); | 1013 ConvertJavaStringToUTF8(env, pref)); |
| 963 } | 1014 } |
| OLD | NEW |