| 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 #include <limits.h> | 5 #include <limits.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "chrome/browser/browsing_data/history_counter.h" | 9 #include "chrome/browser/browsing_data/history_counter.h" |
| 10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 HistoryCounter::HistoryCounter() : pref_name_(prefs::kDeleteBrowsingHistory), | 23 HistoryCounter::HistoryCounter() : pref_name_(prefs::kDeleteBrowsingHistory), |
| 24 has_synced_visits_(false), | 24 has_synced_visits_(false), |
| 25 local_counting_finished_(false), | 25 local_counting_finished_(false), |
| 26 web_counting_finished_(false), | 26 web_counting_finished_(false), |
| 27 testing_web_history_service_(nullptr), | 27 testing_web_history_service_(nullptr), |
| 28 sync_service_(nullptr), | 28 sync_service_(nullptr), |
| 29 history_sync_enabled_(false) { | 29 history_sync_enabled_(false) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 HistoryCounter::~HistoryCounter() { | 32 HistoryCounter::~HistoryCounter() { |
| 33 DCHECK(sync_service_); | 33 if (sync_service_) |
| 34 sync_service_->RemoveObserver(this); | 34 sync_service_->RemoveObserver(this); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void HistoryCounter::OnInitialized() { | 37 void HistoryCounter::OnInitialized() { |
| 38 sync_service_ = ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 38 sync_service_ = ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
| 39 DCHECK(sync_service_); | 39 if (sync_service_) |
| 40 sync_service_->AddObserver(this); | 40 sync_service_->AddObserver(this); |
| 41 history_sync_enabled_ = | 41 history_sync_enabled_ = |
| 42 !!WebHistoryServiceFactory::GetForProfile(GetProfile()); | 42 !!WebHistoryServiceFactory::GetForProfile(GetProfile()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 const std::string& HistoryCounter::GetPrefName() const { | 45 const std::string& HistoryCounter::GetPrefName() const { |
| 46 return pref_name_; | 46 return pref_name_; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool HistoryCounter::HasTrackedTasks() { | 49 bool HistoryCounter::HasTrackedTasks() { |
| 50 return cancelable_task_tracker_.HasTrackedTasks(); | 50 return cancelable_task_tracker_.HasTrackedTasks(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void HistoryCounter::SetWebHistoryServiceForTesting( | 53 void HistoryCounter::SetWebHistoryServiceForTesting( |
| 54 history::WebHistoryService* service) { | 54 history::WebHistoryService* service) { |
| 55 testing_web_history_service_ = service; | 55 testing_web_history_service_ = service; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void HistoryCounter::Count() { | 58 void HistoryCounter::Count() { |
| 59 // Reset the state. | 59 // Reset the state. |
| 60 cancelable_task_tracker_.TryCancelAll(); | 60 cancelable_task_tracker_.TryCancelAll(); |
| 61 web_history_request_.reset(); | 61 web_history_request_.reset(); |
| 62 has_synced_visits_ = false; | 62 has_synced_visits_ = false; |
| 63 | 63 |
| 64 // Count the locally stored items. | 64 // Count the locally stored items. |
| 65 local_counting_finished_ = false; | 65 local_counting_finished_ = false; |
| 66 | 66 |
| 67 history::HistoryService* service = | 67 history::HistoryService* service = |
| 68 HistoryServiceFactory::GetForProfileWithoutCreating(GetProfile()); | 68 HistoryServiceFactory::GetForProfile( |
| 69 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS); |
| 69 | 70 |
| 70 service->GetHistoryCount( | 71 service->GetHistoryCount( |
| 71 GetPeriodStart(), | 72 GetPeriodStart(), |
| 72 base::Time::Max(), | 73 base::Time::Max(), |
| 73 base::Bind(&HistoryCounter::OnGetLocalHistoryCount, | 74 base::Bind(&HistoryCounter::OnGetLocalHistoryCount, |
| 74 base::Unretained(this)), | 75 base::Unretained(this)), |
| 75 &cancelable_task_tracker_); | 76 &cancelable_task_tracker_); |
| 76 | 77 |
| 77 // If the history sync is enabled, test if there is at least one synced item. | 78 // If the history sync is enabled, test if there is at least one synced item. |
| 78 // If the testing web history service is present, use that one instead. | 79 // If the testing web history service is present, use that one instead. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 bool history_sync_enabled_new_state = | 183 bool history_sync_enabled_new_state = |
| 183 !!WebHistoryServiceFactory::GetForProfile(GetProfile()); | 184 !!WebHistoryServiceFactory::GetForProfile(GetProfile()); |
| 184 | 185 |
| 185 // If the history sync was just enabled or disabled, restart the counter | 186 // If the history sync was just enabled or disabled, restart the counter |
| 186 // so that we update the result accordingly. | 187 // so that we update the result accordingly. |
| 187 if (history_sync_enabled_ != history_sync_enabled_new_state) { | 188 if (history_sync_enabled_ != history_sync_enabled_new_state) { |
| 188 history_sync_enabled_ = history_sync_enabled_new_state; | 189 history_sync_enabled_ = history_sync_enabled_new_state; |
| 189 Restart(); | 190 Restart(); |
| 190 } | 191 } |
| 191 } | 192 } |
| OLD | NEW |