blob: 4061cdbdc0ab66c6a5e34e13a449f04c9fc05dac [file] [log] [blame]
msramek8be33282015-10-06 14:33:211// 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"
msramekae197fb2015-10-29 21:14:199#include "base/timer/timer.h"
msramek8be33282015-10-06 14:33:2110#include "chrome/browser/browsing_data/browsing_data_counter.h"
11#include "components/history/core/browser/history_service.h"
msramekae197fb2015-10-29 21:14:1912#include "components/history/core/browser/web_history_service.h"
msramek8be33282015-10-06 14:33:2113
14class HistoryCounter: public BrowsingDataCounter {
15 public:
msramek6bb4dffa2015-11-03 18:20:5416 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 };
msramekae197fb2015-10-29 21:14:1928
msramek8be33282015-10-06 14:33:2129 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
msramekae197fb2015-10-29 21:14:1937 // Make the history counter use a custom WebHistoryService instance. Only
38 // used for testing.
39 void SetWebHistoryServiceForTesting(history::WebHistoryService* service);
40
msramek8be33282015-10-06 14:33:2141 private:
42 const std::string pref_name_;
msramekae197fb2015-10-29 21:14:1943
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
msramek8be33282015-10-06 14:33:2152 base::CancelableTaskTracker cancelable_task_tracker_;
msramekae197fb2015-10-29 21:14:1953 scoped_ptr<history::WebHistoryService::Request> web_history_request_;
54 base::OneShotTimer web_history_timeout_;
55
56 base::ThreadChecker thread_checker_;
msramek8be33282015-10-06 14:33:2157
58 void Count() override;
59
60 void OnGetLocalHistoryCount(history::HistoryCountResult result);
msramekae197fb2015-10-29 21:14:1961 void OnGetWebHistoryCount(history::WebHistoryService::Request* request,
62 const base::DictionaryValue* result);
63 void OnWebHistoryTimeout();
64 void MergeResults();
msramek8be33282015-10-06 14:33:2165};
66
67#endif // CHROME_BROWSER_BROWSING_DATA_HISTORY_COUNTER_H_