Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: components/browsing_data/core/counters/history_counter.cc

Issue 2855623005: Move browsing_data counter sync tests to separate file (Closed)
Patch Set: fixes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/browsing_data/core/counters/history_counter.h" 5 #include "components/browsing_data/core/counters/history_counter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // TODO(msramek): Include web history count when there is an API for it. 95 // TODO(msramek): Include web history count when there is an API for it.
96 } 96 }
97 97
98 void HistoryCounter::OnGetLocalHistoryCount( 98 void HistoryCounter::OnGetLocalHistoryCount(
99 history::HistoryCountResult result) { 99 history::HistoryCountResult result) {
100 // Ensure that all callbacks are on the same thread, so that we do not need 100 // Ensure that all callbacks are on the same thread, so that we do not need
101 // a mutex for |MergeResults|. 101 // a mutex for |MergeResults|.
102 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
103 103
104 if (!result.success) { 104 if (!result.success) {
105 LOG(ERROR) << "Failed to count the local history.";
106 return; 105 return;
107 } 106 }
108 107
109 local_result_ = result.count; 108 local_result_ = result.count;
110 local_counting_finished_ = true; 109 local_counting_finished_ = true;
111 MergeResults(); 110 MergeResults();
112 } 111 }
113 112
114 void HistoryCounter::OnGetWebHistoryCount( 113 void HistoryCounter::OnGetWebHistoryCount(
115 history::WebHistoryService::Request* request, 114 history::WebHistoryService::Request* request,
(...skipping 28 matching lines...) Expand all
144 web_history_request_.reset(); 143 web_history_request_.reset();
145 has_synced_visits_ = true; 144 has_synced_visits_ = true;
146 web_counting_finished_ = true; 145 web_counting_finished_ = true;
147 MergeResults(); 146 MergeResults();
148 } 147 }
149 148
150 void HistoryCounter::MergeResults() { 149 void HistoryCounter::MergeResults() {
151 if (!local_counting_finished_ || !web_counting_finished_) 150 if (!local_counting_finished_ || !web_counting_finished_)
152 return; 151 return;
153 152
154 ReportResult( 153 ReportResult(base::MakeUnique<HistoryResult>(
155 base::MakeUnique<HistoryResult>(this, local_result_, has_synced_visits_)); 154 this, local_result_, history_sync_enabled_, has_synced_visits_));
156 } 155 }
157 156
158 HistoryCounter::HistoryResult::HistoryResult(const HistoryCounter* source,
159 ResultInt value,
160 bool has_synced_visits)
161 : FinishedResult(source, value), has_synced_visits_(has_synced_visits) {}
162
163 HistoryCounter::HistoryResult::~HistoryResult() {}
164
165 void HistoryCounter::OnStateChanged(syncer::SyncService* sync) { 157 void HistoryCounter::OnStateChanged(syncer::SyncService* sync) {
166 bool history_sync_enabled_new_state = !!web_history_service_callback_.Run(); 158 bool history_sync_enabled_new_state = !!web_history_service_callback_.Run();
167 159
168 // If the history sync was just enabled or disabled, restart the counter 160 // If the history sync was just enabled or disabled, restart the counter
169 // so that we update the result accordingly. 161 // so that we update the result accordingly.
170 if (history_sync_enabled_ != history_sync_enabled_new_state) { 162 if (history_sync_enabled_ != history_sync_enabled_new_state) {
171 history_sync_enabled_ = history_sync_enabled_new_state; 163 history_sync_enabled_ = history_sync_enabled_new_state;
172 Restart(); 164 Restart();
173 } 165 }
174 } 166 }
175 167
168 HistoryCounter::HistoryResult::HistoryResult(const HistoryCounter* source,
169 ResultInt value,
170 bool is_sync_enabled,
171 bool has_synced_visits)
172 : SyncResult(source, value, is_sync_enabled),
173 has_synced_visits_(has_synced_visits) {}
174
175 HistoryCounter::HistoryResult::~HistoryResult() {}
176
176 } // namespace browsing_data 177 } // namespace browsing_data
OLDNEW
« no previous file with comments | « components/browsing_data/core/counters/history_counter.h ('k') | components/browsing_data/core/counters/passwords_counter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698