OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/sync/glue/typed_url_model_associator.h" | 5 #include "chrome/browser/sync/glue/typed_url_model_associator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 it != visits.end(); ++it) { | 131 it != visits.end(); ++it) { |
132 if (map.count(it->visit_id) == 0 || | 132 if (map.count(it->visit_id) == 0 || |
133 map[it->visit_id] <= kLastImportedSource) { | 133 map[it->visit_id] <= kLastImportedSource) { |
134 return false; | 134 return false; |
135 } | 135 } |
136 } | 136 } |
137 // We only saw imported visits, so tell the caller to ignore them. | 137 // We only saw imported visits, so tell the caller to ignore them. |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 SyncError TypedUrlModelAssociator::AssociateModels() { | 141 csync::SyncError TypedUrlModelAssociator::AssociateModels() { |
142 ClearErrorStats(); | 142 ClearErrorStats(); |
143 SyncError error = DoAssociateModels(); | 143 csync::SyncError error = DoAssociateModels(); |
144 UMA_HISTOGRAM_PERCENTAGE("Sync.TypedUrlModelAssociationErrors", | 144 UMA_HISTOGRAM_PERCENTAGE("Sync.TypedUrlModelAssociationErrors", |
145 GetErrorPercentage()); | 145 GetErrorPercentage()); |
146 ClearErrorStats(); | 146 ClearErrorStats(); |
147 return error; | 147 return error; |
148 } | 148 } |
149 | 149 |
150 void TypedUrlModelAssociator::ClearErrorStats() { | 150 void TypedUrlModelAssociator::ClearErrorStats() { |
151 num_db_accesses_ = 0; | 151 num_db_accesses_ = 0; |
152 num_db_errors_ = 0; | 152 num_db_errors_ = 0; |
153 } | 153 } |
154 | 154 |
155 int TypedUrlModelAssociator::GetErrorPercentage() const { | 155 int TypedUrlModelAssociator::GetErrorPercentage() const { |
156 return num_db_accesses_ ? (100 * num_db_errors_ / num_db_accesses_) : 0; | 156 return num_db_accesses_ ? (100 * num_db_errors_ / num_db_accesses_) : 0; |
157 } | 157 } |
158 | 158 |
159 SyncError TypedUrlModelAssociator::DoAssociateModels() { | 159 csync::SyncError TypedUrlModelAssociator::DoAssociateModels() { |
160 DVLOG(1) << "Associating TypedUrl Models"; | 160 DVLOG(1) << "Associating TypedUrl Models"; |
161 SyncError error; | 161 csync::SyncError error; |
162 DCHECK(expected_loop_ == MessageLoop::current()); | 162 DCHECK(expected_loop_ == MessageLoop::current()); |
163 if (IsAbortPending()) | 163 if (IsAbortPending()) |
164 return SyncError(); | 164 return csync::SyncError(); |
165 history::URLRows typed_urls; | 165 history::URLRows typed_urls; |
166 ++num_db_accesses_; | 166 ++num_db_accesses_; |
167 if (!history_backend_->GetAllTypedURLs(&typed_urls)) { | 167 if (!history_backend_->GetAllTypedURLs(&typed_urls)) { |
168 ++num_db_errors_; | 168 ++num_db_errors_; |
169 return error_handler_->CreateAndUploadError( | 169 return error_handler_->CreateAndUploadError( |
170 FROM_HERE, | 170 FROM_HERE, |
171 "Could not get the typed_url entries.", | 171 "Could not get the typed_url entries.", |
172 model_type()); | 172 model_type()); |
173 } | 173 } |
174 | 174 |
175 // Get all the visits. | 175 // Get all the visits. |
176 std::map<history::URLID, history::VisitVector> visit_vectors; | 176 std::map<history::URLID, history::VisitVector> visit_vectors; |
177 for (history::URLRows::iterator ix = typed_urls.begin(); | 177 for (history::URLRows::iterator ix = typed_urls.begin(); |
178 ix != typed_urls.end();) { | 178 ix != typed_urls.end();) { |
179 if (IsAbortPending()) | 179 if (IsAbortPending()) |
180 return SyncError(); | 180 return csync::SyncError(); |
181 DCHECK_EQ(0U, visit_vectors.count(ix->id())); | 181 DCHECK_EQ(0U, visit_vectors.count(ix->id())); |
182 if (!FixupURLAndGetVisits(&(*ix), &(visit_vectors[ix->id()])) || | 182 if (!FixupURLAndGetVisits(&(*ix), &(visit_vectors[ix->id()])) || |
183 ShouldIgnoreUrl(*ix, visit_vectors[ix->id()])) { | 183 ShouldIgnoreUrl(*ix, visit_vectors[ix->id()])) { |
184 // Ignore this URL if we couldn't load the visits or if there's some | 184 // Ignore this URL if we couldn't load the visits or if there's some |
185 // other problem with it (it was empty, or imported and never visited). | 185 // other problem with it (it was empty, or imported and never visited). |
186 ix = typed_urls.erase(ix); | 186 ix = typed_urls.erase(ix); |
187 } else { | 187 } else { |
188 ++ix; | 188 ++ix; |
189 } | 189 } |
190 } | 190 } |
(...skipping 11 matching lines...) Expand all Loading... |
202 FROM_HERE, | 202 FROM_HERE, |
203 "Server did not create the top-level typed_url node. We " | 203 "Server did not create the top-level typed_url node. We " |
204 "might be running against an out-of-date server.", | 204 "might be running against an out-of-date server.", |
205 model_type()); | 205 model_type()); |
206 } | 206 } |
207 | 207 |
208 std::set<std::string> current_urls; | 208 std::set<std::string> current_urls; |
209 for (history::URLRows::iterator ix = typed_urls.begin(); | 209 for (history::URLRows::iterator ix = typed_urls.begin(); |
210 ix != typed_urls.end(); ++ix) { | 210 ix != typed_urls.end(); ++ix) { |
211 if (IsAbortPending()) | 211 if (IsAbortPending()) |
212 return SyncError(); | 212 return csync::SyncError(); |
213 std::string tag = ix->url().spec(); | 213 std::string tag = ix->url().spec(); |
214 // Empty URLs should be filtered out by ShouldIgnoreUrl() previously. | 214 // Empty URLs should be filtered out by ShouldIgnoreUrl() previously. |
215 DCHECK(!tag.empty()); | 215 DCHECK(!tag.empty()); |
216 history::VisitVector& visits = visit_vectors[ix->id()]; | 216 history::VisitVector& visits = visit_vectors[ix->id()]; |
217 | 217 |
218 csync::ReadNode node(&trans); | 218 csync::ReadNode node(&trans); |
219 if (node.InitByClientTagLookup(syncable::TYPED_URLS, tag) == | 219 if (node.InitByClientTagLookup(syncable::TYPED_URLS, tag) == |
220 csync::BaseNode::INIT_OK) { | 220 csync::BaseNode::INIT_OK) { |
221 // Same URL exists in sync data and in history data - compare the | 221 // Same URL exists in sync data and in history data - compare the |
222 // entries to see if there's any difference. | 222 // entries to see if there's any difference. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 289 |
290 current_urls.insert(tag); | 290 current_urls.insert(tag); |
291 } | 291 } |
292 | 292 |
293 // Now walk the sync nodes and detect any URLs that exist there, but not in | 293 // Now walk the sync nodes and detect any URLs that exist there, but not in |
294 // the history DB, so we can add them to our local history DB. | 294 // the history DB, so we can add them to our local history DB. |
295 std::vector<int64> obsolete_nodes; | 295 std::vector<int64> obsolete_nodes; |
296 int64 sync_child_id = typed_url_root.GetFirstChildId(); | 296 int64 sync_child_id = typed_url_root.GetFirstChildId(); |
297 while (sync_child_id != csync::kInvalidId) { | 297 while (sync_child_id != csync::kInvalidId) { |
298 if (IsAbortPending()) | 298 if (IsAbortPending()) |
299 return SyncError(); | 299 return csync::SyncError(); |
300 csync::ReadNode sync_child_node(&trans); | 300 csync::ReadNode sync_child_node(&trans); |
301 if (sync_child_node.InitByIdLookup(sync_child_id) != | 301 if (sync_child_node.InitByIdLookup(sync_child_id) != |
302 csync::BaseNode::INIT_OK) { | 302 csync::BaseNode::INIT_OK) { |
303 return error_handler_->CreateAndUploadError( | 303 return error_handler_->CreateAndUploadError( |
304 FROM_HERE, | 304 FROM_HERE, |
305 "Failed to fetch child node.", | 305 "Failed to fetch child node.", |
306 model_type()); | 306 model_type()); |
307 } | 307 } |
308 const sync_pb::TypedUrlSpecifics& typed_url( | 308 const sync_pb::TypedUrlSpecifics& typed_url( |
309 sync_child_node.GetTypedUrlSpecifics()); | 309 sync_child_node.GetTypedUrlSpecifics()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 // If we encountered any obsolete nodes, remove them so they don't hang | 353 // If we encountered any obsolete nodes, remove them so they don't hang |
354 // around and confuse people looking at the sync node browser. | 354 // around and confuse people looking at the sync node browser. |
355 if (!obsolete_nodes.empty()) { | 355 if (!obsolete_nodes.empty()) { |
356 for (std::vector<int64>::const_iterator it = obsolete_nodes.begin(); | 356 for (std::vector<int64>::const_iterator it = obsolete_nodes.begin(); |
357 it != obsolete_nodes.end(); | 357 it != obsolete_nodes.end(); |
358 ++it) { | 358 ++it) { |
359 if (IsAbortPending()) | 359 if (IsAbortPending()) |
360 return SyncError(); | 360 return csync::SyncError(); |
361 csync::WriteNode sync_node(&trans); | 361 csync::WriteNode sync_node(&trans); |
362 if (sync_node.InitByIdLookup(*it) != csync::BaseNode::INIT_OK) { | 362 if (sync_node.InitByIdLookup(*it) != csync::BaseNode::INIT_OK) { |
363 return error_handler_->CreateAndUploadError( | 363 return error_handler_->CreateAndUploadError( |
364 FROM_HERE, | 364 FROM_HERE, |
365 "Failed to fetch obsolete node.", | 365 "Failed to fetch obsolete node.", |
366 model_type()); | 366 model_type()); |
367 } | 367 } |
368 sync_node.Remove(); | 368 sync_node.Remove(); |
369 } | 369 } |
370 } | 370 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 csync::BaseNode::INIT_OK) { | 452 csync::BaseNode::INIT_OK) { |
453 LOG(ERROR) << "Typed url node lookup failed."; | 453 LOG(ERROR) << "Typed url node lookup failed."; |
454 return false; | 454 return false; |
455 } | 455 } |
456 sync_child_id = sync_child_node.GetSuccessorId(); | 456 sync_child_id = sync_child_node.GetSuccessorId(); |
457 sync_child_node.Remove(); | 457 sync_child_node.Remove(); |
458 } | 458 } |
459 return true; | 459 return true; |
460 } | 460 } |
461 | 461 |
462 SyncError TypedUrlModelAssociator::DisassociateModels() { | 462 csync::SyncError TypedUrlModelAssociator::DisassociateModels() { |
463 return SyncError(); | 463 return csync::SyncError(); |
464 } | 464 } |
465 | 465 |
466 void TypedUrlModelAssociator::AbortAssociation() { | 466 void TypedUrlModelAssociator::AbortAssociation() { |
467 base::AutoLock lock(pending_abort_lock_); | 467 base::AutoLock lock(pending_abort_lock_); |
468 pending_abort_ = true; | 468 pending_abort_ = true; |
469 } | 469 } |
470 | 470 |
471 bool TypedUrlModelAssociator::IsAbortPending() { | 471 bool TypedUrlModelAssociator::IsAbortPending() { |
472 base::AutoLock lock(pending_abort_lock_); | 472 base::AutoLock lock(pending_abort_lock_); |
473 return pending_abort_; | 473 return pending_abort_; |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 bool TypedUrlModelAssociator::CryptoReadyIfNecessary() { | 822 bool TypedUrlModelAssociator::CryptoReadyIfNecessary() { |
823 // We only access the cryptographer while holding a transaction. | 823 // We only access the cryptographer while holding a transaction. |
824 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 824 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
825 const syncable::ModelTypeSet encrypted_types = | 825 const syncable::ModelTypeSet encrypted_types = |
826 csync::GetEncryptedTypes(&trans); | 826 csync::GetEncryptedTypes(&trans); |
827 return !encrypted_types.Has(syncable::TYPED_URLS) || | 827 return !encrypted_types.Has(syncable::TYPED_URLS) || |
828 sync_service_->IsCryptographerReady(&trans); | 828 sync_service_->IsCryptographerReady(&trans); |
829 } | 829 } |
830 | 830 |
831 } // namespace browser_sync | 831 } // namespace browser_sync |
OLD | NEW |