OLD | NEW |
---|---|
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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/message_loop/message_loop.h" | |
8 #include "components/browser_sync/browser/profile_sync_service.h" | 9 #include "components/browser_sync/browser/profile_sync_service.h" |
9 #include "components/history/core/browser/web_history_service.h" | 10 #include "components/history/core/browser/web_history_service.h" |
11 #include "components/version_info/version_info.h" | |
12 | |
13 namespace { | |
14 | |
15 class MergeTwoBooleanCallbacks { | |
msarda
2016/05/18 08:58:07
Please comment this class as it is not really to u
sdefresne
2016/05/18 14:29:40
+1
msramek
2016/05/18 19:38:36
Done. Sorry about that, I hoped it would be clear
| |
16 public: | |
17 MergeTwoBooleanCallbacks( | |
18 const base::Callback<void(bool)>& merged_callback) | |
19 : merged_callback_(merged_callback), | |
20 final_response_(true) { | |
21 } | |
22 | |
23 void Callback(bool response) { | |
msarda
2016/05/18 08:58:07
Nit: s/Callback/RunCallback
msramek
2016/05/18 19:38:37
Done.
| |
24 final_response_ &= response; | |
25 | |
26 if (++callbacks_ == 2) { | |
sdefresne
2016/05/18 14:29:40
Avoid hard coded magic values.
BTW, I found the l
msramek
2016/05/18 19:38:37
Done.
Also changed 2 to |expected_call_count_|. I
| |
27 merged_callback_.Run(final_response_); | |
28 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
29 } | |
30 } | |
31 | |
32 private: | |
33 base::Callback<void(bool)> merged_callback_; | |
msarda
2016/05/18 08:58:07
Optional nit: I would rename this to target_callba
sdefresne
2016/05/18 14:29:40
I would call it callback_
msramek
2016/05/18 19:38:37
I would prefer keeping some kind of adjective to d
| |
34 bool final_response_; | |
sdefresne
2016/05/18 14:29:40
bool final_response_ = false;
msramek
2016/05/18 19:38:37
This is currently initialized in the constructor a
sdefresne
2016/05/18 19:42:39
Oh, yes I should have said "bool final_response_ =
msramek
2016/05/19 19:47:39
Makes sense. Let me move it up to the constructor
| |
35 int callbacks_ = 0; | |
36 }; | |
37 | |
38 } // namespace | |
10 | 39 |
11 namespace browsing_data_ui { | 40 namespace browsing_data_ui { |
12 | 41 |
13 namespace testing { | 42 namespace testing { |
14 | 43 |
15 bool g_override_other_forms_of_browsing_history_query = false; | 44 bool g_override_other_forms_of_browsing_history_query = false; |
16 | 45 |
17 } | 46 } // namespace testing |
18 | 47 |
19 void ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 48 void ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
20 const ProfileSyncService* sync_service, | 49 const ProfileSyncService* sync_service, |
21 history::WebHistoryService* history_service, | 50 history::WebHistoryService* history_service, |
22 base::Callback<void(bool)> callback) { | 51 base::Callback<void(bool)> callback) { |
23 if (!sync_service || | 52 if (!sync_service || |
24 !sync_service->IsSyncActive() || | 53 !sync_service->IsSyncActive() || |
25 sync_service->IsUsingSecondaryPassphrase() || | 54 sync_service->IsUsingSecondaryPassphrase() || |
26 !history_service) { | 55 !history_service) { |
27 callback.Run(false); | 56 callback.Run(false); |
28 return; | 57 return; |
29 } | 58 } |
30 | 59 |
31 history_service->QueryWebAndAppActivity(callback); | 60 history_service->QueryWebAndAppActivity(callback); |
32 } | 61 } |
33 | 62 |
34 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( | 63 void ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( |
msarda
2016/05/18 08:58:07
The function is not more complex: it waits for 2 c
sdefresne
2016/05/18 14:29:40
+1
msramek
2016/05/18 19:38:37
Done, added a unittest. Two things that I noticed
| |
35 const ProfileSyncService* sync_service, | 64 const ProfileSyncService* sync_service, |
36 history::WebHistoryService* history_service, | 65 history::WebHistoryService* history_service, |
66 const version_info::Channel channel, | |
67 const std::string& user_agent, | |
37 base::Callback<void(bool)> callback) { | 68 base::Callback<void(bool)> callback) { |
38 if (!history_service || | 69 // If the query for other forms of browsing history is overriden for testing, |
39 (!testing::g_override_other_forms_of_browsing_history_query && | 70 // the conditions are identical with |
40 !history_service->HasOtherFormsOfBrowsingHistory())) { | 71 // ShouldShowNoticeAboutOtherFormsOfBrowsingHistory. |
72 if (testing::g_override_other_forms_of_browsing_history_query) { | |
73 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | |
74 sync_service, history_service, callback); | |
75 return; | |
76 } | |
77 | |
78 if (!sync_service || | |
79 !sync_service->IsSyncActive() || | |
80 sync_service->IsUsingSecondaryPassphrase() || | |
81 !history_service) { | |
41 callback.Run(false); | 82 callback.Run(false); |
42 return; | 83 return; |
43 } | 84 } |
44 | 85 |
45 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 86 // Return the boolean product of QueryWebAndAppActivity and |
46 sync_service, history_service, callback); | 87 // QueryOtherFormsOfBrowsingHistory. MergeTwoBooleanCallbacks deletes itself |
88 // after processing the two callbacks. | |
89 MergeTwoBooleanCallbacks* merger = new MergeTwoBooleanCallbacks(callback); | |
90 history_service->QueryWebAndAppActivity(base::Bind( | |
91 &MergeTwoBooleanCallbacks::Callback, base::Unretained(merger))); | |
92 history_service->QueryOtherFormsOfBrowsingHistory( | |
93 channel, user_agent, | |
94 base::Bind( | |
95 &MergeTwoBooleanCallbacks::Callback, base::Unretained(merger))); | |
47 } | 96 } |
48 | 97 |
49 } // namespace browsing_data_ui | 98 } // namespace browsing_data_ui |
OLD | NEW |