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 | ae197fb | 2015-10-29 21:14:19 | [diff] [blame^] | 16 | // A special value indicating that the local counting result is zero, but some |
| 17 | // history entries exist in Sync. |
| 18 | // TODO(msramek): Change the callback signature so we can return a structured |
| 19 | // result instead of special int values. |
| 20 | static const BrowsingDataCounter::ResultInt kOnlySyncedHistory; |
| 21 | |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 22 | HistoryCounter(); |
| 23 | ~HistoryCounter() override; |
| 24 | |
| 25 | const std::string& GetPrefName() const override; |
| 26 | |
| 27 | // Whether there are counting tasks in progress. Only used for testing. |
| 28 | bool HasTrackedTasks(); |
| 29 | |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame^] | 30 | // Make the history counter use a custom WebHistoryService instance. Only |
| 31 | // used for testing. |
| 32 | void SetWebHistoryServiceForTesting(history::WebHistoryService* service); |
| 33 | |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 34 | private: |
| 35 | const std::string pref_name_; |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame^] | 36 | |
| 37 | BrowsingDataCounter::ResultInt local_result_; |
| 38 | bool has_synced_visits_; |
| 39 | |
| 40 | bool local_counting_finished_; |
| 41 | bool web_counting_finished_; |
| 42 | |
| 43 | history::WebHistoryService* testing_web_history_service_; |
| 44 | |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 45 | base::CancelableTaskTracker cancelable_task_tracker_; |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame^] | 46 | scoped_ptr<history::WebHistoryService::Request> web_history_request_; |
| 47 | base::OneShotTimer web_history_timeout_; |
| 48 | |
| 49 | base::ThreadChecker thread_checker_; |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 50 | |
| 51 | void Count() override; |
| 52 | |
| 53 | void OnGetLocalHistoryCount(history::HistoryCountResult result); |
msramek | ae197fb | 2015-10-29 21:14:19 | [diff] [blame^] | 54 | void OnGetWebHistoryCount(history::WebHistoryService::Request* request, |
| 55 | const base::DictionaryValue* result); |
| 56 | void OnWebHistoryTimeout(); |
| 57 | void MergeResults(); |
msramek | 8be3328 | 2015-10-06 14:33:21 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | #endif // CHROME_BROWSER_BROWSING_DATA_HISTORY_COUNTER_H_ |