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

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, working 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 const int kMaxImportantSites = 10;
Theresa 2016/04/27 21:11:00 Why is this different from the value in pref_servi
dmurph 2016/04/29 23:53:49 I chatted with Dru (the PM on this) and we decided
44 51
45 Profile* GetActiveUserProfile(bool is_incognito) { 52 Profile* GetActiveUserProfile(bool is_incognito) {
46 Profile* profile = ProfileManager::GetActiveUserProfile(); 53 Profile* profile = ProfileManager::GetActiveUserProfile();
47 if (is_incognito) 54 if (is_incognito)
48 profile = profile->GetOffTheRecordProfile(); 55 profile = profile->GetOffTheRecordProfile();
49 return profile; 56 return profile;
50 } 57 }
51 58
52 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { 59 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) {
53 return HostContentSettingsMapFactory::GetForProfile( 60 return HostContentSettingsMapFactory::GetForProfile(
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 }; 643 };
637 644
638 class LocalStorageInfoReadyCallback { 645 class LocalStorageInfoReadyCallback {
639 public: 646 public:
640 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) 647 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback)
641 : env_(base::android::AttachCurrentThread()), 648 : env_(base::android::AttachCurrentThread()),
642 java_callback_(java_callback) { 649 java_callback_(java_callback) {
643 } 650 }
644 651
645 void OnLocalStorageModelInfoLoaded( 652 void OnLocalStorageModelInfoLoaded(
653 Profile* profile,
646 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& 654 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>&
647 local_storage_info) { 655 local_storage_info) {
648 ScopedJavaLocalRef<jobject> map = 656 ScopedJavaLocalRef<jobject> map =
649 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); 657 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_);
650 658
659 std::vector<std::string> important_domains =
660 ImportantSitesUtil::GetImportantRegisterableDomains(profile,
661 kMaxImportantSites);
662
651 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator 663 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator
652 i; 664 i;
653 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { 665 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) {
654 ScopedJavaLocalRef<jstring> full_origin = 666 ScopedJavaLocalRef<jstring> full_origin =
655 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); 667 ConvertUTF8ToJavaString(env_, i->origin_url.spec());
668 std::string origin_str = i->origin_url.GetOrigin().spec();
669 bool important = false;
670 std::string registerable_domain =
671 net::registry_controlled_domains::GetDomainAndRegistry(
672 i->origin_url,
673 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
674 if (std::find(important_domains.begin(), important_domains.end(),
Theresa 2016/04/27 21:11:00 Does 'important' info need to be added to each web
dmurph 2016/04/29 23:53:49 We don't fetch it for every website (we just use t
Theresa 2016/05/03 00:04:27 sg.
675 registerable_domain) == important_domains.end()) {
676 important = true;
677 }
656 // Remove the trailing backslash so the origin is matched correctly in 678 // Remove the trailing backslash so the origin is matched correctly in
657 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. 679 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin.
658 std::string origin_str = i->origin_url.GetOrigin().spec();
659 DCHECK(origin_str[origin_str.size() - 1] == '/'); 680 DCHECK(origin_str[origin_str.size() - 1] == '/');
660 origin_str = origin_str.substr(0, origin_str.size() - 1); 681 origin_str = origin_str.substr(0, origin_str.size() - 1);
661 ScopedJavaLocalRef<jstring> origin = 682 ScopedJavaLocalRef<jstring> origin =
662 ConvertUTF8ToJavaString(env_, origin_str); 683 ConvertUTF8ToJavaString(env_, origin_str);
663 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( 684 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap(
664 env_, map.obj(), origin.obj(), full_origin.obj(), i->size); 685 env_, map.obj(), origin.obj(), full_origin.obj(), i->size, important);
665 } 686 }
666 687
667 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady( 688 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady(
668 env_, java_callback_.obj(), map.obj()); 689 env_, java_callback_.obj(), map.obj());
669 delete this; 690 delete this;
670 } 691 }
671 692
672 private: 693 private:
673 JNIEnv* env_; 694 JNIEnv* env_;
674 ScopedJavaGlobalRef<jobject> java_callback_; 695 ScopedJavaGlobalRef<jobject> java_callback_;
(...skipping 15 matching lines...) Expand all
690 const JavaParamRef<jclass>& clazz, 711 const JavaParamRef<jclass>& clazz,
691 const JavaParamRef<jobject>& java_callback) { 712 const JavaParamRef<jobject>& java_callback) {
692 Profile* profile = ProfileManager::GetActiveUserProfile(); 713 Profile* profile = ProfileManager::GetActiveUserProfile();
693 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 714 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
694 new BrowsingDataLocalStorageHelper(profile)); 715 new BrowsingDataLocalStorageHelper(profile));
695 // local_storage_callback will delete itself when it is run. 716 // local_storage_callback will delete itself when it is run.
696 LocalStorageInfoReadyCallback* local_storage_callback = 717 LocalStorageInfoReadyCallback* local_storage_callback =
697 new LocalStorageInfoReadyCallback(java_callback); 718 new LocalStorageInfoReadyCallback(java_callback);
698 local_storage_helper->StartFetching( 719 local_storage_helper->StartFetching(
699 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, 720 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded,
700 base::Unretained(local_storage_callback))); 721 base::Unretained(local_storage_callback), profile));
701 } 722 }
702 723
703 static void FetchStorageInfo(JNIEnv* env, 724 static void FetchStorageInfo(JNIEnv* env,
704 const JavaParamRef<jclass>& clazz, 725 const JavaParamRef<jclass>& clazz,
705 const JavaParamRef<jobject>& java_callback) { 726 const JavaParamRef<jobject>& java_callback) {
706 Profile* profile = ProfileManager::GetActiveUserProfile(); 727 Profile* profile = ProfileManager::GetActiveUserProfile();
707 728
708 // storage_info_ready_callback will delete itself when it is run. 729 // storage_info_ready_callback will delete itself when it is run.
709 StorageInfoReadyCallback* storage_info_ready_callback = 730 StorageInfoReadyCallback* storage_info_ready_callback =
710 new StorageInfoReadyCallback(java_callback); 731 new StorageInfoReadyCallback(java_callback);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 773 GURL url(ConvertJavaStringToUTF8(env, jorigin));
753 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 774 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
754 new SiteDataDeleteHelper(profile, url)); 775 new SiteDataDeleteHelper(profile, url));
755 site_data_deleter->Run(); 776 site_data_deleter->Run();
756 } 777 }
757 778
758 // Register native methods 779 // Register native methods
759 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 780 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
760 return RegisterNativesImpl(env); 781 return RegisterNativesImpl(env);
761 } 782 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698