| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/tracked.h" | 10 #include "base/tracked.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/password_manager/password_store_change.h" | 12 #include "chrome/browser/password_manager/password_store_change.h" |
| 13 #include "chrome/browser/password_manager/password_store.h" | 13 #include "chrome/browser/password_manager/password_store.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sync/glue/password_model_associator.h" | 15 #include "chrome/browser/sync/glue/password_model_associator.h" |
| 16 #include "chrome/browser/sync/internal_api/change_record.h" |
| 16 #include "chrome/browser/sync/internal_api/read_node.h" | 17 #include "chrome/browser/sync/internal_api/read_node.h" |
| 17 #include "chrome/browser/sync/internal_api/write_node.h" | 18 #include "chrome/browser/sync/internal_api/write_node.h" |
| 18 #include "chrome/browser/sync/internal_api/write_transaction.h" | 19 #include "chrome/browser/sync/internal_api/write_transaction.h" |
| 19 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 20 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 21 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "content/common/notification_details.h" | 24 #include "content/common/notification_details.h" |
| 24 #include "content/common/notification_source.h" | 25 #include "content/common/notification_source.h" |
| 25 #include "webkit/glue/password_form.h" | 26 #include "webkit/glue/password_form.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 sync_node.Remove(); | 126 sync_node.Remove(); |
| 126 } | 127 } |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 void PasswordChangeProcessor::ApplyChangesFromSyncModel( | 134 void PasswordChangeProcessor::ApplyChangesFromSyncModel( |
| 134 const sync_api::BaseTransaction* trans, | 135 const sync_api::BaseTransaction* trans, |
| 135 const sync_api::SyncManager::ChangeRecord* changes, | 136 const sync_api::ImmutableChangeRecordList& changes) { |
| 136 int change_count) { | |
| 137 DCHECK(expected_loop_ == MessageLoop::current()); | 137 DCHECK(expected_loop_ == MessageLoop::current()); |
| 138 if (!running()) | 138 if (!running()) |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 sync_api::ReadNode password_root(trans); | 141 sync_api::ReadNode password_root(trans); |
| 142 if (!password_root.InitByTagLookup(kPasswordTag)) { | 142 if (!password_root.InitByTagLookup(kPasswordTag)) { |
| 143 error_handler()->OnUnrecoverableError(FROM_HERE, | 143 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 144 "Password root node lookup failed."); | 144 "Password root node lookup failed."); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && | 148 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && |
| 149 updated_passwords_.empty()); | 149 updated_passwords_.empty()); |
| 150 | 150 |
| 151 for (int i = 0; i < change_count; ++i) { | 151 for (sync_api::ChangeRecordList::const_iterator it = |
| 152 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == | 152 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| 153 changes[i].action) { | 153 if (sync_api::ChangeRecord::ACTION_DELETE == |
| 154 DCHECK(changes[i].specifics.HasExtension(sync_pb::password)) | 154 it->action) { |
| 155 DCHECK(it->specifics.HasExtension(sync_pb::password)) |
| 155 << "Password specifics data not present on delete!"; | 156 << "Password specifics data not present on delete!"; |
| 156 DCHECK(changes[i].extra.get()); | 157 DCHECK(it->extra.get()); |
| 157 sync_api::SyncManager::ExtraPasswordChangeRecordData* extra = | 158 sync_api::ExtraPasswordChangeRecordData* extra = |
| 158 changes[i].extra.get(); | 159 it->extra.get(); |
| 159 const sync_pb::PasswordSpecificsData& password = extra->unencrypted(); | 160 const sync_pb::PasswordSpecificsData& password = extra->unencrypted(); |
| 160 webkit_glue::PasswordForm form; | 161 webkit_glue::PasswordForm form; |
| 161 PasswordModelAssociator::CopyPassword(password, &form); | 162 PasswordModelAssociator::CopyPassword(password, &form); |
| 162 deleted_passwords_.push_back(form); | 163 deleted_passwords_.push_back(form); |
| 163 model_associator_->Disassociate(changes[i].id); | 164 model_associator_->Disassociate(it->id); |
| 164 continue; | 165 continue; |
| 165 } | 166 } |
| 166 | 167 |
| 167 sync_api::ReadNode sync_node(trans); | 168 sync_api::ReadNode sync_node(trans); |
| 168 if (!sync_node.InitByIdLookup(changes[i].id)) { | 169 if (!sync_node.InitByIdLookup(it->id)) { |
| 169 error_handler()->OnUnrecoverableError(FROM_HERE, | 170 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 170 "Password node lookup failed."); | 171 "Password node lookup failed."); |
| 171 return; | 172 return; |
| 172 } | 173 } |
| 173 | 174 |
| 174 // Check that the changed node is a child of the passwords folder. | 175 // Check that the changed node is a child of the passwords folder. |
| 175 DCHECK(password_root.GetId() == sync_node.GetParentId()); | 176 DCHECK_EQ(password_root.GetId(), sync_node.GetParentId()); |
| 176 DCHECK(syncable::PASSWORDS == sync_node.GetModelType()); | 177 DCHECK_EQ(syncable::PASSWORDS, sync_node.GetModelType()); |
| 177 | 178 |
| 178 const sync_pb::PasswordSpecificsData& password_data = | 179 const sync_pb::PasswordSpecificsData& password_data = |
| 179 sync_node.GetPasswordSpecifics(); | 180 sync_node.GetPasswordSpecifics(); |
| 180 webkit_glue::PasswordForm password; | 181 webkit_glue::PasswordForm password; |
| 181 PasswordModelAssociator::CopyPassword(password_data, &password); | 182 PasswordModelAssociator::CopyPassword(password_data, &password); |
| 182 | 183 |
| 183 if (sync_api::SyncManager::ChangeRecord::ACTION_ADD == changes[i].action) { | 184 if (sync_api::ChangeRecord::ACTION_ADD == it->action) { |
| 184 std::string tag(PasswordModelAssociator::MakeTag(password)); | 185 std::string tag(PasswordModelAssociator::MakeTag(password)); |
| 185 model_associator_->Associate(&tag, sync_node.GetId()); | 186 model_associator_->Associate(&tag, sync_node.GetId()); |
| 186 new_passwords_.push_back(password); | 187 new_passwords_.push_back(password); |
| 187 } else { | 188 } else { |
| 188 DCHECK(sync_api::SyncManager::ChangeRecord::ACTION_UPDATE == | 189 DCHECK_EQ(sync_api::ChangeRecord::ACTION_UPDATE, it->action); |
| 189 changes[i].action); | |
| 190 updated_passwords_.push_back(password); | 190 updated_passwords_.push_back(password); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 void PasswordChangeProcessor::CommitChangesFromSyncModel() { | 195 void PasswordChangeProcessor::CommitChangesFromSyncModel() { |
| 196 DCHECK(expected_loop_ == MessageLoop::current()); | 196 DCHECK(expected_loop_ == MessageLoop::current()); |
| 197 if (!running()) | 197 if (!running()) |
| 198 return; | 198 return; |
| 199 StopObserving(); | 199 StopObserving(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 void PasswordChangeProcessor::StopObserving() { | 233 void PasswordChangeProcessor::StopObserving() { |
| 234 DCHECK(expected_loop_ == MessageLoop::current()); | 234 DCHECK(expected_loop_ == MessageLoop::current()); |
| 235 notification_registrar_.Remove(this, | 235 notification_registrar_.Remove(this, |
| 236 chrome::NOTIFICATION_LOGINS_CHANGED, | 236 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 237 Source<PasswordStore>(password_store_)); | 237 Source<PasswordStore>(password_store_)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace browser_sync | 240 } // namespace browser_sync |
| OLD | NEW |