| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_BROWSING_DATA_CORE_COUNTERS_HISTORY_COUNTER_H_ | 5 #ifndef COMPONENTS_BROWSING_DATA_CORE_COUNTERS_HISTORY_COUNTER_H_ |
| 6 #define COMPONENTS_BROWSING_DATA_CORE_COUNTERS_HISTORY_COUNTER_H_ | 6 #define COMPONENTS_BROWSING_DATA_CORE_COUNTERS_HISTORY_COUNTER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
| 9 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 10 #include "components/browsing_data/core/counters/browsing_data_counter.h" | 12 #include "components/browsing_data/core/counters/browsing_data_counter.h" |
| 11 #include "components/history/core/browser/history_service.h" | 13 #include "components/history/core/browser/history_service.h" |
| 12 #include "components/history/core/browser/web_history_service.h" | 14 #include "components/history/core/browser/web_history_service.h" |
| 13 #include "components/sync/driver/sync_service.h" | 15 #include "components/sync/driver/sync_service.h" |
| 14 #include "components/sync/driver/sync_service_observer.h" | 16 #include "components/sync/driver/sync_service_observer.h" |
| 15 | 17 |
| 16 namespace browsing_data { | 18 namespace browsing_data { |
| 17 | 19 |
| 18 class HistoryCounter : public browsing_data::BrowsingDataCounter, | 20 class HistoryCounter : public browsing_data::BrowsingDataCounter, |
| 19 public sync_driver::SyncServiceObserver { | 21 public syncer::SyncServiceObserver { |
| 20 public: | 22 public: |
| 21 typedef base::Callback<history::WebHistoryService*()> | 23 typedef base::Callback<history::WebHistoryService*()> |
| 22 GetUpdatedWebHistoryServiceCallback; | 24 GetUpdatedWebHistoryServiceCallback; |
| 23 | 25 |
| 24 class HistoryResult : public FinishedResult { | 26 class HistoryResult : public FinishedResult { |
| 25 public: | 27 public: |
| 26 HistoryResult(const HistoryCounter* source, | 28 HistoryResult(const HistoryCounter* source, |
| 27 ResultInt value, | 29 ResultInt value, |
| 28 bool has_synced_visits); | 30 bool has_synced_visits); |
| 29 ~HistoryResult() override; | 31 ~HistoryResult() override; |
| 30 | 32 |
| 31 bool has_synced_visits() const { return has_synced_visits_; } | 33 bool has_synced_visits() const { return has_synced_visits_; } |
| 32 | 34 |
| 33 private: | 35 private: |
| 34 bool has_synced_visits_; | 36 bool has_synced_visits_; |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 explicit HistoryCounter(history::HistoryService* history_service, | 39 explicit HistoryCounter(history::HistoryService* history_service, |
| 38 const GetUpdatedWebHistoryServiceCallback& callback, | 40 const GetUpdatedWebHistoryServiceCallback& callback, |
| 39 sync_driver::SyncService* sync_service); | 41 syncer::SyncService* sync_service); |
| 40 ~HistoryCounter() override; | 42 ~HistoryCounter() override; |
| 41 | 43 |
| 42 void OnInitialized() override; | 44 void OnInitialized() override; |
| 43 | 45 |
| 44 // Whether there are counting tasks in progress. Only used for testing. | 46 // Whether there are counting tasks in progress. Only used for testing. |
| 45 bool HasTrackedTasks(); | 47 bool HasTrackedTasks(); |
| 46 | 48 |
| 47 const char* GetPrefName() const override; | 49 const char* GetPrefName() const override; |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 void Count() override; | 52 void Count() override; |
| 51 | 53 |
| 52 void OnGetLocalHistoryCount(history::HistoryCountResult result); | 54 void OnGetLocalHistoryCount(history::HistoryCountResult result); |
| 53 void OnGetWebHistoryCount(history::WebHistoryService::Request* request, | 55 void OnGetWebHistoryCount(history::WebHistoryService::Request* request, |
| 54 const base::DictionaryValue* result); | 56 const base::DictionaryValue* result); |
| 55 void OnWebHistoryTimeout(); | 57 void OnWebHistoryTimeout(); |
| 56 void MergeResults(); | 58 void MergeResults(); |
| 57 | 59 |
| 58 // SyncServiceObserver implementation. | 60 // SyncServiceObserver implementation. |
| 59 void OnStateChanged() override; | 61 void OnStateChanged() override; |
| 60 | 62 |
| 61 history::HistoryService* history_service_; | 63 history::HistoryService* history_service_; |
| 62 | 64 |
| 63 GetUpdatedWebHistoryServiceCallback web_history_service_callback_; | 65 GetUpdatedWebHistoryServiceCallback web_history_service_callback_; |
| 64 | 66 |
| 65 sync_driver::SyncService* sync_service_; | 67 syncer::SyncService* sync_service_; |
| 66 | 68 |
| 67 bool has_synced_visits_; | 69 bool has_synced_visits_; |
| 68 | 70 |
| 69 bool local_counting_finished_; | 71 bool local_counting_finished_; |
| 70 bool web_counting_finished_; | 72 bool web_counting_finished_; |
| 71 | 73 |
| 72 base::CancelableTaskTracker cancelable_task_tracker_; | 74 base::CancelableTaskTracker cancelable_task_tracker_; |
| 73 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; | 75 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; |
| 74 base::OneShotTimer web_history_timeout_; | 76 base::OneShotTimer web_history_timeout_; |
| 75 | 77 |
| 76 base::ThreadChecker thread_checker_; | 78 base::ThreadChecker thread_checker_; |
| 77 | 79 |
| 78 BrowsingDataCounter::ResultInt local_result_; | 80 BrowsingDataCounter::ResultInt local_result_; |
| 79 | 81 |
| 80 bool history_sync_enabled_; | 82 bool history_sync_enabled_; |
| 81 | 83 |
| 82 base::WeakPtrFactory<HistoryCounter> weak_ptr_factory_; | 84 base::WeakPtrFactory<HistoryCounter> weak_ptr_factory_; |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 } // namespace browsing_data | 87 } // namespace browsing_data |
| 86 | 88 |
| 87 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_HISTORY_COUNTER_H_ | 89 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_HISTORY_COUNTER_H_ |
| OLD | NEW |