| 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/password_change_processor.h" | 5 #include "chrome/browser/sync/glue/password_change_processor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace browser_sync { | 30 namespace browser_sync { |
| 31 | 31 |
| 32 PasswordChangeProcessor::PasswordChangeProcessor( | 32 PasswordChangeProcessor::PasswordChangeProcessor( |
| 33 PasswordModelAssociator* model_associator, | 33 PasswordModelAssociator* model_associator, |
| 34 PasswordStore* password_store, | 34 PasswordStore* password_store, |
| 35 DataTypeErrorHandler* error_handler) | 35 DataTypeErrorHandler* error_handler) |
| 36 : ChangeProcessor(error_handler), | 36 : ChangeProcessor(error_handler), |
| 37 model_associator_(model_associator), | 37 model_associator_(model_associator), |
| 38 password_store_(password_store), | 38 password_store_(password_store), |
| 39 expected_loop_(MessageLoop::current()) { | 39 expected_loop_(base::MessageLoop::current()) { |
| 40 DCHECK(model_associator); | 40 DCHECK(model_associator); |
| 41 DCHECK(error_handler); | 41 DCHECK(error_handler); |
| 42 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
| 43 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 44 #else | 44 #else |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 46 #endif | 46 #endif |
| 47 } | 47 } |
| 48 | 48 |
| 49 PasswordChangeProcessor::~PasswordChangeProcessor() { | 49 PasswordChangeProcessor::~PasswordChangeProcessor() { |
| 50 DCHECK(expected_loop_ == MessageLoop::current()); | 50 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void PasswordChangeProcessor::Observe( | 53 void PasswordChangeProcessor::Observe( |
| 54 int type, | 54 int type, |
| 55 const content::NotificationSource& source, | 55 const content::NotificationSource& source, |
| 56 const content::NotificationDetails& details) { | 56 const content::NotificationDetails& details) { |
| 57 DCHECK(expected_loop_ == MessageLoop::current()); | 57 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 58 DCHECK(chrome::NOTIFICATION_LOGINS_CHANGED == type); | 58 DCHECK(chrome::NOTIFICATION_LOGINS_CHANGED == type); |
| 59 | 59 |
| 60 syncer::WriteTransaction trans(FROM_HERE, share_handle()); | 60 syncer::WriteTransaction trans(FROM_HERE, share_handle()); |
| 61 | 61 |
| 62 syncer::ReadNode password_root(&trans); | 62 syncer::ReadNode password_root(&trans); |
| 63 if (password_root.InitByTagLookup(kPasswordTag) != | 63 if (password_root.InitByTagLookup(kPasswordTag) != |
| 64 syncer::BaseNode::INIT_OK) { | 64 syncer::BaseNode::INIT_OK) { |
| 65 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 65 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 66 "Server did not create the top-level password node. " | 66 "Server did not create the top-level password node. " |
| 67 "We might be running against an out-of-date server."); | 67 "We might be running against an out-of-date server."); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 break; | 155 break; |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 void PasswordChangeProcessor::ApplyChangesFromSyncModel( | 161 void PasswordChangeProcessor::ApplyChangesFromSyncModel( |
| 162 const syncer::BaseTransaction* trans, | 162 const syncer::BaseTransaction* trans, |
| 163 int64 model_version, | 163 int64 model_version, |
| 164 const syncer::ImmutableChangeRecordList& changes) { | 164 const syncer::ImmutableChangeRecordList& changes) { |
| 165 DCHECK(expected_loop_ == MessageLoop::current()); | 165 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 166 | 166 |
| 167 syncer::ReadNode password_root(trans); | 167 syncer::ReadNode password_root(trans); |
| 168 if (password_root.InitByTagLookup(kPasswordTag) != | 168 if (password_root.InitByTagLookup(kPasswordTag) != |
| 169 syncer::BaseNode::INIT_OK) { | 169 syncer::BaseNode::INIT_OK) { |
| 170 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 170 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 171 "Password root node lookup failed."); | 171 "Password root node lookup failed."); |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 | 174 |
| 175 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && | 175 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 model_associator_->Associate(&tag, sync_node.GetId()); | 213 model_associator_->Associate(&tag, sync_node.GetId()); |
| 214 new_passwords_.push_back(password); | 214 new_passwords_.push_back(password); |
| 215 } else { | 215 } else { |
| 216 DCHECK_EQ(syncer::ChangeRecord::ACTION_UPDATE, it->action); | 216 DCHECK_EQ(syncer::ChangeRecord::ACTION_UPDATE, it->action); |
| 217 updated_passwords_.push_back(password); | 217 updated_passwords_.push_back(password); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 void PasswordChangeProcessor::CommitChangesFromSyncModel() { | 222 void PasswordChangeProcessor::CommitChangesFromSyncModel() { |
| 223 DCHECK(expected_loop_ == MessageLoop::current()); | 223 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 224 ScopedStopObserving<PasswordChangeProcessor> stop_observing(this); | 224 ScopedStopObserving<PasswordChangeProcessor> stop_observing(this); |
| 225 | 225 |
| 226 syncer::SyncError error = model_associator_->WriteToPasswordStore( | 226 syncer::SyncError error = model_associator_->WriteToPasswordStore( |
| 227 &new_passwords_, | 227 &new_passwords_, |
| 228 &updated_passwords_, | 228 &updated_passwords_, |
| 229 &deleted_passwords_); | 229 &deleted_passwords_); |
| 230 if (error.IsSet()) { | 230 if (error.IsSet()) { |
| 231 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 231 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 232 "Error writing passwords"); | 232 "Error writing passwords"); |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 | 235 |
| 236 deleted_passwords_.clear(); | 236 deleted_passwords_.clear(); |
| 237 new_passwords_.clear(); | 237 new_passwords_.clear(); |
| 238 updated_passwords_.clear(); | 238 updated_passwords_.clear(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void PasswordChangeProcessor::StartImpl(Profile* profile) { | 241 void PasswordChangeProcessor::StartImpl(Profile* profile) { |
| 242 DCHECK(expected_loop_ == MessageLoop::current()); | 242 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 243 StartObserving(); | 243 StartObserving(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void PasswordChangeProcessor::StartObserving() { | 246 void PasswordChangeProcessor::StartObserving() { |
| 247 DCHECK(expected_loop_ == MessageLoop::current()); | 247 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 248 notification_registrar_.Add(this, | 248 notification_registrar_.Add(this, |
| 249 chrome::NOTIFICATION_LOGINS_CHANGED, | 249 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 250 content::Source<PasswordStore>(password_store_)); | 250 content::Source<PasswordStore>(password_store_)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void PasswordChangeProcessor::StopObserving() { | 253 void PasswordChangeProcessor::StopObserving() { |
| 254 DCHECK(expected_loop_ == MessageLoop::current()); | 254 DCHECK(expected_loop_ == base::MessageLoop::current()); |
| 255 notification_registrar_.Remove( | 255 notification_registrar_.Remove( |
| 256 this, | 256 this, |
| 257 chrome::NOTIFICATION_LOGINS_CHANGED, | 257 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 258 content::Source<PasswordStore>(password_store_)); | 258 content::Source<PasswordStore>(password_store_)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace browser_sync | 261 } // namespace browser_sync |
| OLD | NEW |