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

Side by Side Diff: components/browsing_data_ui/history_notice_utils.cc

Issue 1983073002: Query the existence other forms of browsing history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/browsing_data_ui/history_notice_utils.h" 5 #include "components/browsing_data_ui/history_notice_utils.h"
6 6
7 #include "base/bind.h"
7 #include "base/callback.h" 8 #include "base/callback.h"
8 #include "components/browser_sync/browser/profile_sync_service.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/stringprintf.h"
9 #include "components/history/core/browser/web_history_service.h" 11 #include "components/history/core/browser/web_history_service.h"
12 #include "components/sync_driver/sync_service.h"
13 #include "components/version_info/version_info.h"
14
15 namespace {
16
17 // Merges several asynchronous boolean callbacks into one that returns a boolean
18 // product of their responses. Deletes itself when done.
19 class MergeBooleanCallbacks {
20 public:
21 // Constructor. Upon receiving |expected_call_count| calls to |RunCallback|,
22 // |target_callback| will be run with the boolean product of their results.
23 MergeBooleanCallbacks(
24 int expected_call_count,
25 const base::Callback<void(bool)>& target_callback)
26 : expected_call_count_(expected_call_count),
27 target_callback_(target_callback),
28 final_response_(true),
29 call_count_(0) {}
30
31 // This method is to be bound to all asynchronous callbacks which we want
32 // to merge.
33 void RunCallback(bool response) {
34 final_response_ &= response;
35
36 if (++call_count_ < expected_call_count_)
37 return;
38
39 target_callback_.Run(final_response_);
40 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
41 }
42
43 private:
44 int expected_call_count_;
45 base::Callback<void(bool)> target_callback_;
46 bool final_response_;
47 int call_count_;
48 };
49
50 } // namespace
10 51
11 namespace browsing_data_ui { 52 namespace browsing_data_ui {
12 53
13 namespace testing { 54 namespace testing {
14 55
15 bool g_override_other_forms_of_browsing_history_query = false; 56 bool g_override_other_forms_of_browsing_history_query = false;
16 57
17 } 58 } // namespace testing
18 59
19 void ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 60 void ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
20 const ProfileSyncService* sync_service, 61 const sync_driver::SyncService* sync_service,
21 history::WebHistoryService* history_service, 62 history::WebHistoryService* history_service,
22 base::Callback<void(bool)> callback) { 63 base::Callback<void(bool)> callback) {
23 if (!sync_service || 64 if (!sync_service ||
24 !sync_service->IsSyncActive() || 65 !sync_service->IsSyncActive() ||
66 !sync_service->GetActiveDataTypes().Has(
67 syncer::HISTORY_DELETE_DIRECTIVES) ||
25 sync_service->IsUsingSecondaryPassphrase() || 68 sync_service->IsUsingSecondaryPassphrase() ||
26 !history_service) { 69 !history_service) {
27 callback.Run(false); 70 callback.Run(false);
28 return; 71 return;
29 } 72 }
30 73
31 history_service->QueryWebAndAppActivity(callback); 74 history_service->QueryWebAndAppActivity(callback);
32 } 75 }
33 76
34 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( 77 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
35 const ProfileSyncService* sync_service, 78 const sync_driver::SyncService* sync_service,
79 history::WebHistoryService* history_service,
80 version_info::Channel channel,
81 base::Callback<void(bool)> callback) {
82 // If the query for other forms of browsing history is overriden for testing,
83 // the conditions are identical with
84 // ShouldShowNoticeAboutOtherFormsOfBrowsingHistory.
85 if (testing::g_override_other_forms_of_browsing_history_query) {
86 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
87 sync_service, history_service, callback);
88 return;
89 }
90
91 if (!sync_service ||
92 !sync_service->IsSyncActive() ||
93 !sync_service->GetActiveDataTypes().Has(
94 syncer::HISTORY_DELETE_DIRECTIVES) ||
95 sync_service->IsUsingSecondaryPassphrase() ||
96 !history_service) {
97 callback.Run(false);
98 return;
99 }
100
101 // Return the boolean product of QueryWebAndAppActivity and
102 // QueryOtherFormsOfBrowsingHistory. MergeBooleanCallbacks deletes itself
103 // after processing both callbacks.
104 MergeBooleanCallbacks* merger = new MergeBooleanCallbacks(2, callback);
105 history_service->QueryWebAndAppActivity(base::Bind(
106 &MergeBooleanCallbacks::RunCallback, base::Unretained(merger)));
107 history_service->QueryOtherFormsOfBrowsingHistory(
108 channel,
109 base::Bind(
110 &MergeBooleanCallbacks::RunCallback, base::Unretained(merger)));
111 }
112
113 // TODO(crbug.com/614319): This function is deprecated and should be removed.
114 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
115 const sync_driver::SyncService* sync_service,
36 history::WebHistoryService* history_service, 116 history::WebHistoryService* history_service,
37 base::Callback<void(bool)> callback) { 117 base::Callback<void(bool)> callback) {
38 if (!history_service || 118 if (!history_service ||
39 (!testing::g_override_other_forms_of_browsing_history_query && 119 !testing::g_override_other_forms_of_browsing_history_query) {
40 !history_service->HasOtherFormsOfBrowsingHistory())) {
41 callback.Run(false); 120 callback.Run(false);
42 return; 121 return;
43 } 122 }
44 123
45 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 124 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
46 sync_service, history_service, callback); 125 sync_service, history_service, callback);
47 } 126 }
48 127
49 } // namespace browsing_data_ui 128 } // namespace browsing_data_ui
OLDNEW
« no previous file with comments | « components/browsing_data_ui/history_notice_utils.h ('k') | components/browsing_data_ui/history_notice_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698