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