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

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: Addressed comments, re-added protobuf 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
32 // This method is to be bound to all asynchronous callbacks which we want
33 // to merge.
34 void RunCallback(bool response) {
35 final_response_ &= response;
36
37 if (++call_count_ < expected_call_count_)
38 return;
39
40 target_callback_.Run(final_response_);
41 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
42 }
43
44 private:
45 int expected_call_count_;
46 base::Callback<void(bool)> target_callback_;
47 bool final_response_;
48 int call_count_;
49 };
50
51 } // namespace
10 52
11 namespace browsing_data_ui { 53 namespace browsing_data_ui {
12 54
13 namespace testing { 55 namespace testing {
14 56
15 bool g_override_other_forms_of_browsing_history_query = false; 57 bool g_override_other_forms_of_browsing_history_query = false;
16 58
17 } 59 } // namespace testing
18 60
19 void ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 61 void ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
20 const ProfileSyncService* sync_service, 62 const sync_driver::SyncService* sync_service,
21 history::WebHistoryService* history_service, 63 history::WebHistoryService* history_service,
22 base::Callback<void(bool)> callback) { 64 base::Callback<void(bool)> callback) {
23 if (!sync_service || 65 if (!sync_service ||
24 !sync_service->IsSyncActive() || 66 !sync_service->IsSyncActive() ||
67 !sync_service->GetActiveDataTypes().Has(
68 syncer::HISTORY_DELETE_DIRECTIVES) ||
25 sync_service->IsUsingSecondaryPassphrase() || 69 sync_service->IsUsingSecondaryPassphrase() ||
26 !history_service) { 70 !history_service) {
27 callback.Run(false); 71 callback.Run(false);
28 return; 72 return;
29 } 73 }
30 74
31 history_service->QueryWebAndAppActivity(callback); 75 history_service->QueryWebAndAppActivity(callback);
32 } 76 }
33 77
34 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( 78 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
35 const ProfileSyncService* sync_service, 79 const sync_driver::SyncService* sync_service,
80 history::WebHistoryService* history_service,
81 version_info::Channel channel,
82 bool is_tablet,
83 base::Callback<void(bool)> callback) {
84 // If the query for other forms of browsing history is overriden for testing,
85 // the conditions are identical with
86 // ShouldShowNoticeAboutOtherFormsOfBrowsingHistory.
87 if (testing::g_override_other_forms_of_browsing_history_query) {
88 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
89 sync_service, history_service, callback);
90 return;
91 }
92
93 if (!sync_service ||
94 !sync_service->IsSyncActive() ||
95 !sync_service->GetActiveDataTypes().Has(
96 syncer::HISTORY_DELETE_DIRECTIVES) ||
97 sync_service->IsUsingSecondaryPassphrase() ||
98 !history_service) {
99 callback.Run(false);
100 return;
101 }
102
103 // Return the boolean product of QueryWebAndAppActivity and
104 // QueryOtherFormsOfBrowsingHistory. MergeBooleanCallbacks deletes itself
105 // after processing both callbacks.
106 MergeBooleanCallbacks* merger = new MergeBooleanCallbacks(2, callback);
107 history_service->QueryWebAndAppActivity(base::Bind(
108 &MergeBooleanCallbacks::RunCallback, base::Unretained(merger)));
109 history_service->QueryOtherFormsOfBrowsingHistory(
110 channel, is_tablet,
111 base::Bind(
112 &MergeBooleanCallbacks::RunCallback, base::Unretained(merger)));
113 }
114
115 // TODO(msarda): This function is deprecated and should be removed.
116 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
117 const sync_driver::SyncService* sync_service,
36 history::WebHistoryService* history_service, 118 history::WebHistoryService* history_service,
37 base::Callback<void(bool)> callback) { 119 base::Callback<void(bool)> callback) {
38 if (!history_service || 120 if (!history_service ||
39 (!testing::g_override_other_forms_of_browsing_history_query && 121 (!testing::g_override_other_forms_of_browsing_history_query &&
40 !history_service->HasOtherFormsOfBrowsingHistory())) { 122 false /* !history_service->HasOtherFormsOfBrowsingHistory() */)) {
sdefresne 2016/05/24 08:32:29 Can you remove this /* comment */?
msramek 2016/05/24 12:03:00 Done. I originally left it there just to demonstr
41 callback.Run(false); 123 callback.Run(false);
42 return; 124 return;
43 } 125 }
44 126
45 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 127 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
46 sync_service, history_service, callback); 128 sync_service, history_service, callback);
47 } 129 }
48 130
49 } // namespace browsing_data_ui 131 } // namespace browsing_data_ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698