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

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

Issue 2697123004: Convert RemoveDataMask from enum to pointers and split it between content and embedder (Closed)
Patch Set: Android compilation Created 3 years, 10 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 | « chrome/browser/BUILD.gn ('k') | chrome/browser/android/signin/signin_manager_android.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 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 9
10 #include <algorithm>
10 #include <memory> 11 #include <memory>
11 #include <set> 12 #include <set>
12 #include <string> 13 #include <string>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/android/build_info.h" 16 #include "base/android/build_info.h"
16 #include "base/android/jni_android.h" 17 #include "base/android/jni_android.h"
17 #include "base/android/jni_array.h" 18 #include "base/android/jni_array.h"
18 #include "base/android/jni_string.h" 19 #include "base/android/jni_string.h"
19 #include "base/android/jni_weak_ref.h" 20 #include "base/android/jni_weak_ref.h"
20 #include "base/feature_list.h" 21 #include "base/feature_list.h"
21 #include "base/files/file_path.h" 22 #include "base/files/file_path.h"
22 #include "base/files/file_util.h" 23 #include "base/files/file_util.h"
23 #include "base/metrics/histogram_macros.h" 24 #include "base/metrics/histogram_macros.h"
24 #include "base/scoped_observer.h" 25 #include "base/scoped_observer.h"
25 #include "base/strings/string_split.h" 26 #include "base/strings/string_split.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/browsing_data/browsing_data_helper.h" 30 #include "chrome/browser/browsing_data/browsing_data_helper.h"
30 #include "chrome/browser/browsing_data/browsing_data_remover.h" 31 #include "chrome/browser/browsing_data/browsing_data_remover.h"
31 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 32 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
33 #include "chrome/browser/browsing_data/chrome_browsing_data_types.h"
32 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 34 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
33 #include "chrome/browser/engagement/important_sites_util.h" 35 #include "chrome/browser/engagement/important_sites_util.h"
34 #include "chrome/browser/history/web_history_service_factory.h" 36 #include "chrome/browser/history/web_history_service_factory.h"
35 #include "chrome/browser/net/prediction_options.h" 37 #include "chrome/browser/net/prediction_options.h"
36 #include "chrome/browser/prefs/incognito_mode_prefs.h" 38 #include "chrome/browser/prefs/incognito_mode_prefs.h"
37 #include "chrome/browser/profiles/profile_manager.h" 39 #include "chrome/browser/profiles/profile_manager.h"
38 #include "chrome/browser/sync/profile_sync_service_factory.h" 40 #include "chrome/browser/sync/profile_sync_service_factory.h"
39 #include "chrome/browser/translate/chrome_translate_client.h" 41 #include "chrome/browser/translate/chrome_translate_client.h"
40 #include "chrome/browser/ui/android/android_about_app_info.h" 42 #include "chrome/browser/ui/android/android_about_app_info.h"
41 #include "chrome/common/channel_info.h" 43 #include "chrome/common/channel_info.h"
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 const JavaParamRef<jobjectArray>& jexcluding_domains, 614 const JavaParamRef<jobjectArray>& jexcluding_domains,
613 const JavaParamRef<jintArray>& jexcluding_domain_reasons, 615 const JavaParamRef<jintArray>& jexcluding_domain_reasons,
614 const JavaParamRef<jobjectArray>& jignoring_domains, 616 const JavaParamRef<jobjectArray>& jignoring_domains,
615 const JavaParamRef<jintArray>& jignoring_domain_reasons) { 617 const JavaParamRef<jintArray>& jignoring_domain_reasons) {
616 BrowsingDataRemover* browsing_data_remover = 618 BrowsingDataRemover* browsing_data_remover =
617 BrowsingDataRemoverFactory::GetForBrowserContext(GetOriginalProfile()); 619 BrowsingDataRemoverFactory::GetForBrowserContext(GetOriginalProfile());
618 620
619 std::vector<int> data_types_vector; 621 std::vector<int> data_types_vector;
620 base::android::JavaIntArrayToIntVector(env, data_types, &data_types_vector); 622 base::android::JavaIntArrayToIntVector(env, data_types, &data_types_vector);
621 623
622 int remove_mask = 0; 624 std::set<const content::BrowsingDataType*> remove_mask;
623 for (const int data_type : data_types_vector) { 625 for (const int data_type : data_types_vector) {
624 switch (static_cast<browsing_data::BrowsingDataType>(data_type)) { 626 switch (static_cast<browsing_data::BrowsingDataType>(data_type)) {
625 case browsing_data::HISTORY: 627 case browsing_data::HISTORY:
626 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; 628 remove_mask.insert(&kBrowsingDataTypeHistory);
627 break; 629 break;
628 case browsing_data::CACHE: 630 case browsing_data::CACHE:
629 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; 631 remove_mask.insert(&kBrowsingDataTypeCache);
630 break; 632 break;
631 case browsing_data::COOKIES: 633 case browsing_data::COOKIES:
632 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; 634 remove_mask.insert(&kBrowsingDataTypeCookies);
633 remove_mask |= BrowsingDataRemover::REMOVE_SITE_DATA; 635 remove_mask.insert(BrowsingDataTypeSetSiteData().begin(),
636 BrowsingDataTypeSetSiteData().end());
634 break; 637 break;
635 case browsing_data::PASSWORDS: 638 case browsing_data::PASSWORDS:
636 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; 639 remove_mask.insert(&kBrowsingDataTypePasswords);
637 break; 640 break;
638 case browsing_data::FORM_DATA: 641 case browsing_data::FORM_DATA:
639 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; 642 remove_mask.insert(&kBrowsingDataTypeFormData);
640 break; 643 break;
641 case browsing_data::BOOKMARKS: 644 case browsing_data::BOOKMARKS:
642 // Bookmarks are deleted separately on the Java side. 645 // Bookmarks are deleted separately on the Java side.
643 NOTREACHED(); 646 NOTREACHED();
644 break; 647 break;
645 case browsing_data::NUM_TYPES: 648 case browsing_data::NUM_TYPES:
646 NOTREACHED(); 649 NOTREACHED();
647 } 650 }
648 } 651 }
649 std::vector<std::string> excluding_domains; 652 std::vector<std::string> excluding_domains;
(...skipping 16 matching lines...) Expand all
666 } 669 }
667 670
668 if (!excluding_domains.empty() || !ignoring_domains.empty()) { 671 if (!excluding_domains.empty() || !ignoring_domains.empty()) {
669 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 672 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
670 GetOriginalProfile(), excluding_domains, excluding_domain_reasons, 673 GetOriginalProfile(), excluding_domains, excluding_domain_reasons,
671 ignoring_domains, ignoring_domain_reasons); 674 ignoring_domains, ignoring_domain_reasons);
672 } 675 }
673 676
674 // Delete the types protected by Important Sites with a filter, 677 // Delete the types protected by Important Sites with a filter,
675 // and the rest completely. 678 // and the rest completely.
676 int filterable_mask = 679 std::set<const content::BrowsingDataType*> filterable_mask;
677 remove_mask & BrowsingDataRemover::IMPORTANT_SITES_DATATYPES; 680 std::set_intersection(
678 int nonfilterable_mask = remove_mask & 681 remove_mask.begin(), remove_mask.end(),
679 ~BrowsingDataRemover::IMPORTANT_SITES_DATATYPES; 682 BrowsingDataTypeSetImportantSites().begin(),
683 BrowsingDataTypeSetImportantSites().end(),
684 std::inserter(filterable_mask, filterable_mask.begin()));
685
686 std::set<const content::BrowsingDataType*> nonfilterable_mask;
687 std::set_difference(
688 remove_mask.begin(), remove_mask.end(), filterable_mask.begin(),
689 filterable_mask.end(),
690 std::inserter(nonfilterable_mask, nonfilterable_mask.begin()));
680 691
681 // ClearBrowsingDataObserver deletes itself when |browsing_data_remover| is 692 // ClearBrowsingDataObserver deletes itself when |browsing_data_remover| is
682 // done with both removal tasks. 693 // done with both removal tasks.
683 ClearBrowsingDataObserver* observer = new ClearBrowsingDataObserver( 694 ClearBrowsingDataObserver* observer = new ClearBrowsingDataObserver(
684 env, obj, browsing_data_remover, 2 /* tasks_count */); 695 env, obj, browsing_data_remover, 2 /* tasks_count */);
685 696
686 browsing_data::TimePeriod period = 697 browsing_data::TimePeriod period =
687 static_cast<browsing_data::TimePeriod>(time_period); 698 static_cast<browsing_data::TimePeriod>(time_period);
688 browsing_data::RecordDeletionForPeriod(period); 699 browsing_data::RecordDeletionForPeriod(period);
689 700
690 if (filterable_mask) { 701 if (!filterable_mask.empty()) {
691 browsing_data_remover->RemoveWithFilterAndReply( 702 browsing_data_remover->RemoveWithFilterAndReply(
692 browsing_data::CalculateBeginDeleteTime(period), 703 browsing_data::CalculateBeginDeleteTime(period),
693 browsing_data::CalculateEndDeleteTime(period), 704 browsing_data::CalculateEndDeleteTime(period),
694 filterable_mask, BrowsingDataHelper::UNPROTECTED_WEB, 705 filterable_mask, BrowsingDataHelper::UNPROTECTED_WEB,
695 std::move(filter_builder), observer); 706 std::move(filter_builder), observer);
696 } else { 707 } else {
697 // Make sure |observer| doesn't wait for the filtered task. 708 // Make sure |observer| doesn't wait for the filtered task.
698 observer->OnBrowsingDataRemoverDone(); 709 observer->OnBrowsingDataRemoverDone();
699 } 710 }
700 711
701 if (nonfilterable_mask) { 712 if (!nonfilterable_mask.empty()) {
702 browsing_data_remover->RemoveAndReply( 713 browsing_data_remover->RemoveAndReply(
703 browsing_data::CalculateBeginDeleteTime(period), 714 browsing_data::CalculateBeginDeleteTime(period),
704 browsing_data::CalculateEndDeleteTime(period), 715 browsing_data::CalculateEndDeleteTime(period),
705 nonfilterable_mask, BrowsingDataHelper::UNPROTECTED_WEB, observer); 716 nonfilterable_mask, BrowsingDataHelper::UNPROTECTED_WEB, observer);
706 } else { 717 } else {
707 // Make sure |observer| doesn't wait for the non-filtered task. 718 // Make sure |observer| doesn't wait for the non-filtered task.
708 observer->OnBrowsingDataRemoverDone(); 719 observer->OnBrowsingDataRemoverDone();
709 } 720 }
710 } 721 }
711 722
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 1245
1235 return ConvertJavaStringToUTF8(android_permission); 1246 return ConvertJavaStringToUTF8(android_permission);
1236 } 1247 }
1237 1248
1238 static void SetSupervisedUserId(JNIEnv* env, 1249 static void SetSupervisedUserId(JNIEnv* env,
1239 const JavaParamRef<jobject>& obj, 1250 const JavaParamRef<jobject>& obj,
1240 const JavaParamRef<jstring>& pref) { 1251 const JavaParamRef<jstring>& pref) {
1241 GetPrefService()->SetString(prefs::kSupervisedUserId, 1252 GetPrefService()->SetString(prefs::kSupervisedUserId,
1242 ConvertJavaStringToUTF8(env, pref)); 1253 ConvertJavaStringToUTF8(env, pref));
1243 } 1254 }
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/android/signin/signin_manager_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698