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

Side by Side Diff: chrome/browser/android/browsing_data/browsing_data_bridge.cc

Issue 2716333002: Implement important sites dialog for desktop. (Closed)
Patch Set: change element.$.someId to element.$$(#someId) Created 3 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
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/android/chrome_feature_list.h » ('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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/browsing_data/browsing_data_bridge.h" 5 #include "chrome/browser/android/browsing_data/browsing_data_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/android/jni_android.h" 15 #include "base/android/jni_android.h"
16 #include "base/android/jni_array.h" 16 #include "base/android/jni_array.h"
17 #include "base/android/jni_string.h" 17 #include "base/android/jni_string.h"
18 #include "base/android/jni_weak_ref.h" 18 #include "base/android/jni_weak_ref.h"
19 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
20 #include "base/scoped_observer.h" 20 #include "base/scoped_observer.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/browsing_data/browsing_data_important_sites_util.h"
22 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 23 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
23 #include "chrome/browser/engagement/important_sites_util.h" 24 #include "chrome/browser/engagement/important_sites_util.h"
24 #include "chrome/browser/history/web_history_service_factory.h" 25 #include "chrome/browser/history/web_history_service_factory.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/sync/profile_sync_service_factory.h" 27 #include "chrome/browser/sync/profile_sync_service_factory.h"
27 #include "chrome/common/channel_info.h" 28 #include "chrome/common/channel_info.h"
28 #include "components/browser_sync/profile_sync_service.h" 29 #include "components/browser_sync/profile_sync_service.h"
29 #include "components/browsing_data/core/history_notice_utils.h" 30 #include "components/browsing_data/core/history_notice_utils.h"
30 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
31 #include "content/public/browser/browser_context.h" 32 #include "content/public/browser/browser_context.h"
32 #include "content/public/browser/browsing_data_filter_builder.h" 33 #include "content/public/browser/browsing_data_filter_builder.h"
33 #include "content/public/browser/browsing_data_remover.h" 34 #include "content/public/browser/browsing_data_remover.h"
34 #include "jni/BrowsingDataBridge_jni.h" 35 #include "jni/BrowsingDataBridge_jni.h"
35 36
36 using base::android::AttachCurrentThread; 37 using base::android::AttachCurrentThread;
37 using base::android::JavaParamRef; 38 using base::android::JavaParamRef;
38 using base::android::JavaRef; 39 using base::android::JavaRef;
39 using base::android::ScopedJavaLocalRef; 40 using base::android::ScopedJavaLocalRef;
40 using base::android::ScopedJavaGlobalRef; 41 using base::android::ScopedJavaGlobalRef;
41 using content::BrowsingDataRemover; 42 using content::BrowsingDataRemover;
42 43
43 namespace { 44 namespace {
44 45
45 const size_t kMaxImportantSites = 5; 46 const size_t kMaxImportantSites = 5;
46 47
47 Profile* GetOriginalProfile() { 48 Profile* GetOriginalProfile() {
48 return ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); 49 return ProfileManager::GetActiveUserProfile()->GetOriginalProfile();
49 } 50 }
50 51
51 // Merges |task_count| BrowsingDataRemover completion callbacks and redirects 52 void OnBrowsingDataRemoverDone(
52 // them back into Java. 53 JavaObjectWeakGlobalRef weak_chrome_native_preferences) {
53 class ClearBrowsingDataObserver : public BrowsingDataRemover::Observer { 54 JNIEnv* env = AttachCurrentThread();
54 public: 55 if (weak_chrome_native_preferences.get(env).is_null())
55 // |obj| is expected to be the object passed into ClearBrowsingData(); e.g. a 56 return;
56 // ChromePreference.
57 ClearBrowsingDataObserver(JNIEnv* env,
58 jobject obj,
59 BrowsingDataRemover* browsing_data_remover,
60 int task_count)
61 : task_count_(task_count),
62 weak_chrome_native_preferences_(env, obj),
63 observer_(this) {
64 DCHECK_GT(task_count, 0);
65 observer_.Add(browsing_data_remover);
66 }
67 57
68 void OnBrowsingDataRemoverDone() override { 58 Java_BrowsingDataBridge_browsingDataCleared(
69 DCHECK(task_count_); 59 env, weak_chrome_native_preferences.get(env));
70 if (--task_count_) 60 }
71 return;
72
73 // We delete ourselves when done.
74 std::unique_ptr<ClearBrowsingDataObserver> auto_delete(this);
75
76 JNIEnv* env = AttachCurrentThread();
77 if (weak_chrome_native_preferences_.get(env).is_null())
78 return;
79
80 Java_BrowsingDataBridge_browsingDataCleared(
81 env, weak_chrome_native_preferences_.get(env));
82 }
83
84 private:
85 int task_count_;
86 JavaObjectWeakGlobalRef weak_chrome_native_preferences_;
87 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_;
88 };
89 61
90 } // namespace 62 } // namespace
91 63
92 bool RegisterBrowsingDataBridge(JNIEnv* env) { 64 bool RegisterBrowsingDataBridge(JNIEnv* env) {
93 return RegisterNativesImpl(env); 65 return RegisterNativesImpl(env);
94 } 66 }
95 67
96 static void ClearBrowsingData( 68 static void ClearBrowsingData(
97 JNIEnv* env, 69 JNIEnv* env,
98 const JavaParamRef<jobject>& obj, 70 const JavaParamRef<jobject>& obj,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 for (const std::string& domain : excluding_domains) { 129 for (const std::string& domain : excluding_domains) {
158 filter_builder->AddRegisterableDomain(domain); 130 filter_builder->AddRegisterableDomain(domain);
159 } 131 }
160 132
161 if (!excluding_domains.empty() || !ignoring_domains.empty()) { 133 if (!excluding_domains.empty() || !ignoring_domains.empty()) {
162 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 134 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
163 GetOriginalProfile(), excluding_domains, excluding_domain_reasons, 135 GetOriginalProfile(), excluding_domains, excluding_domain_reasons,
164 ignoring_domains, ignoring_domain_reasons); 136 ignoring_domains, ignoring_domain_reasons);
165 } 137 }
166 138
167 // Delete the types protected by Important Sites with a filter, 139 base::OnceClosure callback = base::BindOnce(
168 // and the rest completely. 140 &OnBrowsingDataRemoverDone, JavaObjectWeakGlobalRef(env, obj));
169 int filterable_mask =
170 remove_mask &
171 ChromeBrowsingDataRemoverDelegate::IMPORTANT_SITES_DATA_TYPES;
172 int nonfilterable_mask =
173 remove_mask &
174 ~ChromeBrowsingDataRemoverDelegate::IMPORTANT_SITES_DATA_TYPES;
175
176 // ClearBrowsingDataObserver deletes itself when |browsing_data_remover| is
177 // done with both removal tasks.
178 ClearBrowsingDataObserver* observer = new ClearBrowsingDataObserver(
179 env, obj, browsing_data_remover, 2 /* tasks_count */);
180 141
181 browsing_data::TimePeriod period = 142 browsing_data::TimePeriod period =
182 static_cast<browsing_data::TimePeriod>(time_period); 143 static_cast<browsing_data::TimePeriod>(time_period);
183 browsing_data::RecordDeletionForPeriod(period);
184 144
185 if (filterable_mask) { 145 browsing_data_important_sites_util::Remove(
186 browsing_data_remover->RemoveWithFilterAndReply( 146 remove_mask, BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, period,
187 browsing_data::CalculateBeginDeleteTime(period), 147 std::move(filter_builder), browsing_data_remover, std::move(callback));
188 browsing_data::CalculateEndDeleteTime(period), filterable_mask,
189 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
190 std::move(filter_builder), observer);
191 } else {
192 // Make sure |observer| doesn't wait for the filtered task.
193 observer->OnBrowsingDataRemoverDone();
194 }
195
196 if (nonfilterable_mask) {
197 browsing_data_remover->RemoveAndReply(
198 browsing_data::CalculateBeginDeleteTime(period),
199 browsing_data::CalculateEndDeleteTime(period), nonfilterable_mask,
200 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, observer);
201 } else {
202 // Make sure |observer| doesn't wait for the non-filtered task.
203 observer->OnBrowsingDataRemoverDone();
204 }
205 } 148 }
206 149
207 static void ShowNoticeAboutOtherFormsOfBrowsingHistory( 150 static void ShowNoticeAboutOtherFormsOfBrowsingHistory(
208 const JavaRef<jobject>& listener, 151 const JavaRef<jobject>& listener,
209 bool show) { 152 bool show) {
210 JNIEnv* env = AttachCurrentThread(); 153 JNIEnv* env = AttachCurrentThread();
211 UMA_HISTOGRAM_BOOLEAN( 154 UMA_HISTOGRAM_BOOLEAN(
212 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", show); 155 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", show);
213 if (!show) 156 if (!show)
214 return; 157 return;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 227
285 static void MarkOriginAsImportantForTesting( 228 static void MarkOriginAsImportantForTesting(
286 JNIEnv* env, 229 JNIEnv* env,
287 const JavaParamRef<jclass>& clazz, 230 const JavaParamRef<jclass>& clazz,
288 const JavaParamRef<jstring>& jorigin) { 231 const JavaParamRef<jstring>& jorigin) {
289 GURL origin(base::android::ConvertJavaStringToUTF8(jorigin)); 232 GURL origin(base::android::ConvertJavaStringToUTF8(jorigin));
290 CHECK(origin.is_valid()); 233 CHECK(origin.is_valid());
291 ImportantSitesUtil::MarkOriginAsImportantForTesting(GetOriginalProfile(), 234 ImportantSitesUtil::MarkOriginAsImportantForTesting(GetOriginalProfile(),
292 origin); 235 origin);
293 } 236 }
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/android/chrome_feature_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698