msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 1 | // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_BROWSING_DATA_HISTORY_COUNTER_H_ |
| 6 | #define CHROME_BROWSER_BROWSING_DATA_HISTORY_COUNTER_H_ |
| 7 | |
| 8 | #include "base/task/cancelable_task_tracker.h" |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 9 | #include "base/timer/timer.h" |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 10 | #include "chrome/browser/browsing_data/browsing_data_counter.h" |
| 11 | #include "components/history/core/browser/history_service.h" |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 12 | #include "components/history/core/browser/web_history_service.h" |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 13 | |
| 14 | class HistoryCounter: public BrowsingDataCounter { |
| 15 | public: |
msramek | 6bb4dffa | 2015-11-03 18:20:54 | [diff] [blame] | 16 | class HistoryResult : public FinishedResult { |
| 17 | public: |
| 18 | HistoryResult(const HistoryCounter* source, |
| 19 | ResultInt value, |
| 20 | bool has_synced_visits); |
| 21 | ~HistoryResult() override; |
| 22 | |
| 23 | bool has_synced_visits() const { return has_synced_visits_; } |
| 24 | |
| 25 | private: |
| 26 | bool has_synced_visits_; |
| 27 | }; |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 28 | |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 29 | HistoryCounter(); |
| 30 | ~HistoryCounter() override; |
| 31 | |
| 32 | const std::string& GetPrefName() const override; |
| 33 | |
| 34 | // Whether there are counting tasks in progress. Only used for testing. |
| 35 | bool HasTrackedTasks(); |
| 36 | |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 37 | // Make the history counter use a custom WebHistoryService instance. Only |
| 38 | // used for testing. |
| 39 | void SetWebHistoryServiceForTesting(history::WebHistoryService* service); |
| 40 | |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 41 | private: |
| 42 | const std::string pref_name_; |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 43 | |
| 44 | BrowsingDataCounter::ResultInt local_result_; |
| 45 | bool has_synced_visits_; |
| 46 | |
| 47 | bool local_counting_finished_; |
| 48 | bool web_counting_finished_; |
| 49 | |
| 50 | history::WebHistoryService* testing_web_history_service_; |
| 51 | |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 52 | base::CancelableTaskTracker cancelable_task_tracker_; |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 53 | scoped_ptr<history::WebHistoryService::Request> web_history_request_; |
| 54 | base::OneShotTimer web_history_timeout_; |
| 55 | |
| 56 | base::ThreadChecker thread_checker_; |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 57 | |
| 58 | void Count() override; |
| 59 | |
| 60 | void OnGetLocalHistoryCount(history::HistoryCountResult result); |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame] | 61 | void OnGetWebHistoryCount(history::WebHistoryService::Request* request, |
| 62 | const base::DictionaryValue* result); |
| 63 | void OnWebHistoryTimeout(); |
| 64 | void MergeResults(); |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif // CHROME_BROWSER_BROWSING_DATA_HISTORY_COUNTER_H_ |