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

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

Issue 1465363002: [Storage] Android - ManageSpace UI, Important Origins, and CBD Dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, cleanup, etc Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/website_preference_bridge.h" 5 #include "chrome/browser/android/preferences/website_preference_bridge.h"
6 6
7 #include <algorithm>
8 #include <string>
9 #include <vector>
10
7 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 13 #include "base/android/scoped_java_ref.h"
10 #include "base/bind.h" 14 #include "base/bind.h"
11 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
12 #include "base/logging.h" 16 #include "base/logging.h"
13 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "chrome/browser/android/preferences/important_sites_util.h"
14 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 19 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h" 20 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
16 #include "chrome/browser/browsing_data/cookies_tree_model.h" 21 #include "chrome/browser/browsing_data/cookies_tree_model.h"
17 #include "chrome/browser/browsing_data/local_data_container.h" 22 #include "chrome/browser/browsing_data/local_data_container.h"
18 #include "chrome/browser/content_settings/cookie_settings_factory.h" 23 #include "chrome/browser/content_settings/cookie_settings_factory.h"
19 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 25 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
21 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" 26 #include "chrome/browser/content_settings/web_site_settings_uma_util.h"
22 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 27 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
23 #include "chrome/browser/permissions/permission_util.h" 28 #include "chrome/browser/permissions/permission_util.h"
24 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 30 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/storage/storage_info_fetcher.h" 31 #include "chrome/browser/storage/storage_info_fetcher.h"
27 #include "components/content_settings/core/browser/cookie_settings.h" 32 #include "components/content_settings/core/browser/cookie_settings.h"
28 #include "components/content_settings/core/browser/host_content_settings_map.h" 33 #include "components/content_settings/core/browser/host_content_settings_map.h"
29 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/storage_partition.h" 35 #include "content/public/browser/storage_partition.h"
31 #include "jni/WebsitePreferenceBridge_jni.h" 36 #include "jni/WebsitePreferenceBridge_jni.h"
37 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
32 #include "storage/browser/quota/quota_manager.h" 38 #include "storage/browser/quota/quota_manager.h"
33 #include "storage/common/quota/quota_status_code.h" 39 #include "storage/common/quota/quota_status_code.h"
34 #include "url/url_constants.h" 40 #include "url/url_constants.h"
35 41
36 using base::android::ConvertJavaStringToUTF8; 42 using base::android::ConvertJavaStringToUTF8;
37 using base::android::ConvertUTF8ToJavaString; 43 using base::android::ConvertUTF8ToJavaString;
38 using base::android::JavaRef; 44 using base::android::JavaRef;
39 using base::android::ScopedJavaGlobalRef; 45 using base::android::ScopedJavaGlobalRef;
40 using base::android::ScopedJavaLocalRef; 46 using base::android::ScopedJavaLocalRef;
41 using content::BrowserThread; 47 using content::BrowserThread;
42 48
43 namespace { 49 namespace {
50 // We need to limit our size due to the algorithm in ImportantSiteUtil, but we
51 // want to be more on the liberal side here as we're not exposing these sites
52 // to the user, we're just using them for our 'clear unimportant' feature.
53 const int kMaxImportantSites = 10;
44 54
45 Profile* GetActiveUserProfile(bool is_incognito) { 55 Profile* GetActiveUserProfile(bool is_incognito) {
46 Profile* profile = ProfileManager::GetActiveUserProfile(); 56 Profile* profile = ProfileManager::GetActiveUserProfile();
47 if (is_incognito) 57 if (is_incognito)
48 profile = profile->GetOffTheRecordProfile(); 58 profile = profile->GetOffTheRecordProfile();
49 return profile; 59 return profile;
50 } 60 }
51 61
52 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { 62 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) {
53 return HostContentSettingsMapFactory::GetForProfile( 63 return HostContentSettingsMapFactory::GetForProfile(
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 }; 646 };
637 647
638 class LocalStorageInfoReadyCallback { 648 class LocalStorageInfoReadyCallback {
639 public: 649 public:
640 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) 650 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback)
641 : env_(base::android::AttachCurrentThread()), 651 : env_(base::android::AttachCurrentThread()),
642 java_callback_(java_callback) { 652 java_callback_(java_callback) {
643 } 653 }
644 654
645 void OnLocalStorageModelInfoLoaded( 655 void OnLocalStorageModelInfoLoaded(
656 Profile* profile,
646 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& 657 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>&
647 local_storage_info) { 658 local_storage_info) {
648 ScopedJavaLocalRef<jobject> map = 659 ScopedJavaLocalRef<jobject> map =
649 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); 660 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_);
650 661
662 std::vector<std::string> important_domains =
663 ImportantSitesUtil::GetImportantRegisterableDomains(profile,
664 kMaxImportantSites);
665
651 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator 666 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator
652 i; 667 i;
653 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { 668 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) {
654 ScopedJavaLocalRef<jstring> full_origin = 669 ScopedJavaLocalRef<jstring> full_origin =
655 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); 670 ConvertUTF8ToJavaString(env_, i->origin_url.spec());
671 std::string origin_str = i->origin_url.GetOrigin().spec();
672 bool important = false;
673 std::string registerable_domain =
674 net::registry_controlled_domains::GetDomainAndRegistry(
675 i->origin_url,
676 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
677 if (std::find(important_domains.begin(), important_domains.end(),
678 registerable_domain) != important_domains.end()) {
679 important = true;
680 }
656 // Remove the trailing backslash so the origin is matched correctly in 681 // Remove the trailing backslash so the origin is matched correctly in
657 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. 682 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin.
658 std::string origin_str = i->origin_url.GetOrigin().spec();
659 DCHECK(origin_str[origin_str.size() - 1] == '/'); 683 DCHECK(origin_str[origin_str.size() - 1] == '/');
660 origin_str = origin_str.substr(0, origin_str.size() - 1); 684 origin_str = origin_str.substr(0, origin_str.size() - 1);
661 ScopedJavaLocalRef<jstring> origin = 685 ScopedJavaLocalRef<jstring> origin =
662 ConvertUTF8ToJavaString(env_, origin_str); 686 ConvertUTF8ToJavaString(env_, origin_str);
663 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( 687 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap(
664 env_, map.obj(), origin.obj(), full_origin.obj(), i->size); 688 env_, map.obj(), origin.obj(), full_origin.obj(), i->size, important);
665 } 689 }
666 690
667 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady( 691 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady(
668 env_, java_callback_.obj(), map.obj()); 692 env_, java_callback_.obj(), map.obj());
669 delete this; 693 delete this;
670 } 694 }
671 695
672 private: 696 private:
673 JNIEnv* env_; 697 JNIEnv* env_;
674 ScopedJavaGlobalRef<jobject> java_callback_; 698 ScopedJavaGlobalRef<jobject> java_callback_;
(...skipping 15 matching lines...) Expand all
690 const JavaParamRef<jclass>& clazz, 714 const JavaParamRef<jclass>& clazz,
691 const JavaParamRef<jobject>& java_callback) { 715 const JavaParamRef<jobject>& java_callback) {
692 Profile* profile = ProfileManager::GetActiveUserProfile(); 716 Profile* profile = ProfileManager::GetActiveUserProfile();
693 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 717 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
694 new BrowsingDataLocalStorageHelper(profile)); 718 new BrowsingDataLocalStorageHelper(profile));
695 // local_storage_callback will delete itself when it is run. 719 // local_storage_callback will delete itself when it is run.
696 LocalStorageInfoReadyCallback* local_storage_callback = 720 LocalStorageInfoReadyCallback* local_storage_callback =
697 new LocalStorageInfoReadyCallback(java_callback); 721 new LocalStorageInfoReadyCallback(java_callback);
698 local_storage_helper->StartFetching( 722 local_storage_helper->StartFetching(
699 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, 723 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded,
700 base::Unretained(local_storage_callback))); 724 base::Unretained(local_storage_callback), profile));
701 } 725 }
702 726
703 static void FetchStorageInfo(JNIEnv* env, 727 static void FetchStorageInfo(JNIEnv* env,
704 const JavaParamRef<jclass>& clazz, 728 const JavaParamRef<jclass>& clazz,
705 const JavaParamRef<jobject>& java_callback) { 729 const JavaParamRef<jobject>& java_callback) {
706 Profile* profile = ProfileManager::GetActiveUserProfile(); 730 Profile* profile = ProfileManager::GetActiveUserProfile();
707 731
708 // storage_info_ready_callback will delete itself when it is run. 732 // storage_info_ready_callback will delete itself when it is run.
709 StorageInfoReadyCallback* storage_info_ready_callback = 733 StorageInfoReadyCallback* storage_info_ready_callback =
710 new StorageInfoReadyCallback(java_callback); 734 new StorageInfoReadyCallback(java_callback);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 776 GURL url(ConvertJavaStringToUTF8(env, jorigin));
753 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 777 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
754 new SiteDataDeleteHelper(profile, url)); 778 new SiteDataDeleteHelper(profile, url));
755 site_data_deleter->Run(); 779 site_data_deleter->Run();
756 } 780 }
757 781
758 // Register native methods 782 // Register native methods
759 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 783 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
760 return RegisterNativesImpl(env); 784 return RegisterNativesImpl(env);
761 } 785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698