blob: f38181c9a0b13d61cf91ba558a0fc1d2ca3666f3 [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:
msramekae197fb2015-10-29 21:14:1916 // 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
msramek8be33282015-10-06 14:33:2122 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
msramekae197fb2015-10-29 21:14:1930 // Make the history counter use a custom WebHistoryService instance. Only
31 // used for testing.
32 void SetWebHistoryServiceForTesting(history::WebHistoryService* service);
33
msramek8be33282015-10-06 14:33:2134 private:
35 const std::string pref_name_;
msramekae197fb2015-10-29 21:14:1936
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
msramek8be33282015-10-06 14:33:2145 base::CancelableTaskTracker cancelable_task_tracker_;
msramekae197fb2015-10-29 21:14:1946 scoped_ptr<history::WebHistoryService::Request> web_history_request_;
47 base::OneShotTimer web_history_timeout_;
48
49 base::ThreadChecker thread_checker_;
msramek8be33282015-10-06 14:33:2150
51 void Count() override;
52
53 void OnGetLocalHistoryCount(history::HistoryCountResult result);
msramekae197fb2015-10-29 21:14:1954 void OnGetWebHistoryCount(history::WebHistoryService::Request* request,
55 const base::DictionaryValue* result);
56 void OnWebHistoryTimeout();
57 void MergeResults();
msramek8be33282015-10-06 14:33:2158};
59
60#endif // CHROME_BROWSER_BROWSING_DATA_HISTORY_COUNTER_H_