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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" |
11 #include "components/history/core/browser/web_history_service.h" | 13 #include "components/history/core/browser/web_history_service.h" |
12 #include "components/sync_driver/sync_service.h" | 14 #include "components/sync_driver/sync_service.h" |
13 #include "components/version_info/version_info.h" | 15 #include "components/version_info/version_info.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // Merges several asynchronous boolean callbacks into one that returns a boolean | 19 // Merges several asynchronous boolean callbacks into one that returns a boolean |
18 // product of their responses. Deletes itself when done. | 20 // product of their responses. Deletes itself when done. |
19 class MergeBooleanCallbacks { | 21 class MergeBooleanCallbacks { |
20 public: | 22 public: |
21 // Constructor. Upon receiving |expected_call_count| calls to |RunCallback|, | 23 // Constructor. Upon receiving |expected_call_count| calls to |RunCallback|, |
22 // |target_callback| will be run with the boolean product of their results. | 24 // |target_callback| will be run with the boolean product of their results. |
23 MergeBooleanCallbacks( | 25 MergeBooleanCallbacks( |
24 int expected_call_count, | 26 int expected_call_count, |
25 const base::Callback<void(bool)>& target_callback) | 27 const base::Callback<void(bool)>& target_callback) |
26 : expected_call_count_(expected_call_count), | 28 : expected_call_count_(expected_call_count), |
27 target_callback_(target_callback), | 29 target_callback_(target_callback), |
28 final_response_(true), | 30 final_response_(true), |
29 call_count_(0) {} | 31 call_count_(0) {} |
30 | 32 |
31 // This method is to be bound to all asynchronous callbacks which we want | 33 // This method is to be bound to all asynchronous callbacks which we want |
32 // to merge. | 34 // to merge. |
33 void RunCallback(bool response) { | 35 void RunCallback(bool response) { |
34 final_response_ &= response; | 36 final_response_ &= response; |
35 | 37 |
36 if (++call_count_ < expected_call_count_) | 38 if (++call_count_ < expected_call_count_) |
37 return; | 39 return; |
38 | 40 |
39 target_callback_.Run(final_response_); | 41 target_callback_.Run(final_response_); |
40 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 42 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
41 } | 43 } |
42 | 44 |
43 private: | 45 private: |
44 int expected_call_count_; | 46 int expected_call_count_; |
45 base::Callback<void(bool)> target_callback_; | 47 base::Callback<void(bool)> target_callback_; |
46 bool final_response_; | 48 bool final_response_; |
47 int call_count_; | 49 int call_count_; |
48 }; | 50 }; |
49 | 51 |
50 } // namespace | 52 } // namespace |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 !testing::g_override_other_forms_of_browsing_history_query) { | 121 !testing::g_override_other_forms_of_browsing_history_query) { |
120 callback.Run(false); | 122 callback.Run(false); |
121 return; | 123 return; |
122 } | 124 } |
123 | 125 |
124 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 126 ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
125 sync_service, history_service, callback); | 127 sync_service, history_service, callback); |
126 } | 128 } |
127 | 129 |
128 } // namespace browsing_data_ui | 130 } // namespace browsing_data_ui |
OLD | NEW |