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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 return true; | 58 return true; |
59 } | 59 } |
60 | 60 |
61 TypedUrlModelAssociator::TypedUrlModelAssociator( | 61 TypedUrlModelAssociator::TypedUrlModelAssociator( |
62 ProfileSyncService* sync_service, | 62 ProfileSyncService* sync_service, |
63 history::HistoryBackend* history_backend, | 63 history::HistoryBackend* history_backend, |
64 DataTypeErrorHandler* error_handler) | 64 DataTypeErrorHandler* error_handler) |
65 : sync_service_(sync_service), | 65 : sync_service_(sync_service), |
66 history_backend_(history_backend), | 66 history_backend_(history_backend), |
67 expected_loop_(MessageLoop::current()), | 67 expected_loop_(base::MessageLoop::current()), |
68 pending_abort_(false), | 68 pending_abort_(false), |
69 error_handler_(error_handler), | 69 error_handler_(error_handler), |
70 num_db_accesses_(0), | 70 num_db_accesses_(0), |
71 num_db_errors_(0) { | 71 num_db_errors_(0) { |
72 DCHECK(sync_service_); | 72 DCHECK(sync_service_); |
73 // history_backend_ may be null for unit tests (since it's not mockable). | 73 // history_backend_ may be null for unit tests (since it's not mockable). |
74 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
75 } | 75 } |
76 | 76 |
77 TypedUrlModelAssociator::~TypedUrlModelAssociator() {} | 77 TypedUrlModelAssociator::~TypedUrlModelAssociator() {} |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 num_db_errors_ = 0; | 167 num_db_errors_ = 0; |
168 } | 168 } |
169 | 169 |
170 int TypedUrlModelAssociator::GetErrorPercentage() const { | 170 int TypedUrlModelAssociator::GetErrorPercentage() const { |
171 return num_db_accesses_ ? (100 * num_db_errors_ / num_db_accesses_) : 0; | 171 return num_db_accesses_ ? (100 * num_db_errors_ / num_db_accesses_) : 0; |
172 } | 172 } |
173 | 173 |
174 syncer::SyncError TypedUrlModelAssociator::DoAssociateModels() { | 174 syncer::SyncError TypedUrlModelAssociator::DoAssociateModels() { |
175 DVLOG(1) << "Associating TypedUrl Models"; | 175 DVLOG(1) << "Associating TypedUrl Models"; |
176 syncer::SyncError error; | 176 syncer::SyncError error; |
177 DCHECK(expected_loop_ == MessageLoop::current()); | 177 DCHECK(expected_loop_ == base::MessageLoop::current()); |
178 if (IsAbortPending()) | 178 if (IsAbortPending()) |
179 return syncer::SyncError(); | 179 return syncer::SyncError(); |
180 history::URLRows typed_urls; | 180 history::URLRows typed_urls; |
181 ++num_db_accesses_; | 181 ++num_db_accesses_; |
182 if (!history_backend_->GetAllTypedURLs(&typed_urls)) { | 182 if (!history_backend_->GetAllTypedURLs(&typed_urls)) { |
183 ++num_db_errors_; | 183 ++num_db_errors_; |
184 return error_handler_->CreateAndUploadError( | 184 return error_handler_->CreateAndUploadError( |
185 FROM_HERE, | 185 FROM_HERE, |
186 "Could not get the typed_url entries.", | 186 "Could not get the typed_url entries.", |
187 model_type()); | 187 model_type()); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 specifics.add_visits(source.visits(i)); | 445 specifics.add_visits(source.visits(i)); |
446 specifics.add_visit_transitions(source.visit_transitions(i)); | 446 specifics.add_visit_transitions(source.visit_transitions(i)); |
447 } | 447 } |
448 } | 448 } |
449 DCHECK(specifics.visits_size() == specifics.visit_transitions_size()); | 449 DCHECK(specifics.visits_size() == specifics.visit_transitions_size()); |
450 return specifics; | 450 return specifics; |
451 } | 451 } |
452 | 452 |
453 bool TypedUrlModelAssociator::DeleteAllNodes( | 453 bool TypedUrlModelAssociator::DeleteAllNodes( |
454 syncer::WriteTransaction* trans) { | 454 syncer::WriteTransaction* trans) { |
455 DCHECK(expected_loop_ == MessageLoop::current()); | 455 DCHECK(expected_loop_ == base::MessageLoop::current()); |
456 | 456 |
457 // Just walk through all our child nodes and delete them. | 457 // Just walk through all our child nodes and delete them. |
458 syncer::ReadNode typed_url_root(trans); | 458 syncer::ReadNode typed_url_root(trans); |
459 if (typed_url_root.InitByTagLookup(kTypedUrlTag) != | 459 if (typed_url_root.InitByTagLookup(kTypedUrlTag) != |
460 syncer::BaseNode::INIT_OK) { | 460 syncer::BaseNode::INIT_OK) { |
461 LOG(ERROR) << "Could not lookup root node"; | 461 LOG(ERROR) << "Could not lookup root node"; |
462 return false; | 462 return false; |
463 } | 463 } |
464 int64 sync_child_id = typed_url_root.GetFirstChildId(); | 464 int64 sync_child_id = typed_url_root.GetFirstChildId(); |
465 while (sync_child_id != syncer::kInvalidId) { | 465 while (sync_child_id != syncer::kInvalidId) { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 837 |
838 bool TypedUrlModelAssociator::CryptoReadyIfNecessary() { | 838 bool TypedUrlModelAssociator::CryptoReadyIfNecessary() { |
839 // We only access the cryptographer while holding a transaction. | 839 // We only access the cryptographer while holding a transaction. |
840 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 840 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
841 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); | 841 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); |
842 return !encrypted_types.Has(syncer::TYPED_URLS) || | 842 return !encrypted_types.Has(syncer::TYPED_URLS) || |
843 sync_service_->IsCryptographerReady(&trans); | 843 sync_service_->IsCryptographerReady(&trans); |
844 } | 844 } |
845 | 845 |
846 } // namespace browser_sync | 846 } // namespace browser_sync |
OLD | NEW |