| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 DCHECK(expected_loop_ == MessageLoop::current()); | 59 DCHECK(expected_loop_ == MessageLoop::current()); |
| 60 DCHECK(chrome::NOTIFICATION_LOGINS_CHANGED == type); | 60 DCHECK(chrome::NOTIFICATION_LOGINS_CHANGED == type); |
| 61 if (!observing_) | 61 if (!observing_) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 DCHECK(running()); | 64 DCHECK(running()); |
| 65 | 65 |
| 66 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); | 66 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); |
| 67 | 67 |
| 68 sync_api::ReadNode password_root(&trans); | 68 sync_api::ReadNode password_root(&trans); |
| 69 if (!password_root.InitByTagLookup(kPasswordTag)) { | 69 if (password_root.InitByTagLookup(kPasswordTag) != |
| 70 sync_api::BaseNode::INIT_OK) { |
| 70 error_handler()->OnUnrecoverableError(FROM_HERE, | 71 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 71 "Server did not create the top-level password node. " | 72 "Server did not create the top-level password node. " |
| 72 "We might be running against an out-of-date server."); | 73 "We might be running against an out-of-date server."); |
| 73 return; | 74 return; |
| 74 } | 75 } |
| 75 | 76 |
| 76 PasswordStoreChangeList* changes = | 77 PasswordStoreChangeList* changes = |
| 77 content::Details<PasswordStoreChangeList>(details).ptr(); | 78 content::Details<PasswordStoreChangeList>(details).ptr(); |
| 78 for (PasswordStoreChangeList::iterator change = changes->begin(); | 79 for (PasswordStoreChangeList::iterator change = changes->begin(); |
| 79 change != changes->end(); ++change) { | 80 change != changes->end(); ++change) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 // action was requested. If it did so, we wouldn't need to fall back | 97 // action was requested. If it did so, we wouldn't need to fall back |
| 97 // to trying to update an existing password node here. | 98 // to trying to update an existing password node here. |
| 98 // | 99 // |
| 99 // TODO: Remove this. See crbug.com/87855. | 100 // TODO: Remove this. See crbug.com/87855. |
| 100 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); | 101 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); |
| 101 if (sync_api::kInvalidId == sync_id) { | 102 if (sync_api::kInvalidId == sync_id) { |
| 102 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 103 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 103 "Unable to create or retrieve password node"); | 104 "Unable to create or retrieve password node"); |
| 104 return; | 105 return; |
| 105 } | 106 } |
| 106 if (!sync_node.InitByIdLookup(sync_id)) { | 107 if (sync_node.InitByIdLookup(sync_id) != |
| 108 sync_api::BaseNode::INIT_OK) { |
| 107 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 109 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 108 "Unable to create or retrieve password node"); | 110 "Unable to create or retrieve password node"); |
| 109 return; | 111 return; |
| 110 } | 112 } |
| 111 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); | 113 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); |
| 112 break; | 114 break; |
| 113 } | 115 } |
| 114 } | 116 } |
| 115 case PasswordStoreChange::UPDATE: { | 117 case PasswordStoreChange::UPDATE: { |
| 116 sync_api::WriteNode sync_node(&trans); | 118 sync_api::WriteNode sync_node(&trans); |
| 117 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); | 119 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); |
| 118 if (sync_api::kInvalidId == sync_id) { | 120 if (sync_api::kInvalidId == sync_id) { |
| 119 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 121 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 120 "Unexpected notification for: "); | 122 "Unexpected notification for: "); |
| 121 return; | 123 return; |
| 122 } else { | 124 } else { |
| 123 if (!sync_node.InitByIdLookup(sync_id)) { | 125 if (sync_node.InitByIdLookup(sync_id) != |
| 126 sync_api::BaseNode::INIT_OK) { |
| 124 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 127 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 125 "Password node lookup failed."); | 128 "Password node lookup failed."); |
| 126 return; | 129 return; |
| 127 } | 130 } |
| 128 } | 131 } |
| 129 | 132 |
| 130 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); | 133 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); |
| 131 break; | 134 break; |
| 132 } | 135 } |
| 133 case PasswordStoreChange::REMOVE: { | 136 case PasswordStoreChange::REMOVE: { |
| 134 sync_api::WriteNode sync_node(&trans); | 137 sync_api::WriteNode sync_node(&trans); |
| 135 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); | 138 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); |
| 136 if (sync_api::kInvalidId == sync_id) { | 139 if (sync_api::kInvalidId == sync_id) { |
| 137 // We've been asked to remove a password that we don't know about. | 140 // We've been asked to remove a password that we don't know about. |
| 138 // That's weird, but apparently we were already in the requested | 141 // That's weird, but apparently we were already in the requested |
| 139 // state, so it's not really an unrecoverable error. Just return. | 142 // state, so it's not really an unrecoverable error. Just return. |
| 140 LOG(WARNING) << "Trying to delete nonexistent password sync node!"; | 143 LOG(WARNING) << "Trying to delete nonexistent password sync node!"; |
| 141 return; | 144 return; |
| 142 } else { | 145 } else { |
| 143 if (!sync_node.InitByIdLookup(sync_id)) { | 146 if (sync_node.InitByIdLookup(sync_id) != |
| 147 sync_api::BaseNode::INIT_OK) { |
| 144 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 148 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 145 "Password node lookup failed."); | 149 "Password node lookup failed."); |
| 146 return; | 150 return; |
| 147 } | 151 } |
| 148 model_associator_->Disassociate(sync_node.GetId()); | 152 model_associator_->Disassociate(sync_node.GetId()); |
| 149 sync_node.Remove(); | 153 sync_node.Remove(); |
| 150 } | 154 } |
| 151 break; | 155 break; |
| 152 } | 156 } |
| 153 } | 157 } |
| 154 } | 158 } |
| 155 } | 159 } |
| 156 | 160 |
| 157 void PasswordChangeProcessor::ApplyChangesFromSyncModel( | 161 void PasswordChangeProcessor::ApplyChangesFromSyncModel( |
| 158 const sync_api::BaseTransaction* trans, | 162 const sync_api::BaseTransaction* trans, |
| 159 const sync_api::ImmutableChangeRecordList& changes) { | 163 const sync_api::ImmutableChangeRecordList& changes) { |
| 160 DCHECK(expected_loop_ == MessageLoop::current()); | 164 DCHECK(expected_loop_ == MessageLoop::current()); |
| 161 if (!running()) | 165 if (!running()) |
| 162 return; | 166 return; |
| 163 | 167 |
| 164 sync_api::ReadNode password_root(trans); | 168 sync_api::ReadNode password_root(trans); |
| 165 if (!password_root.InitByTagLookup(kPasswordTag)) { | 169 if (password_root.InitByTagLookup(kPasswordTag) != |
| 170 sync_api::BaseNode::INIT_OK) { |
| 166 error_handler()->OnUnrecoverableError(FROM_HERE, | 171 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 167 "Password root node lookup failed."); | 172 "Password root node lookup failed."); |
| 168 return; | 173 return; |
| 169 } | 174 } |
| 170 | 175 |
| 171 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && | 176 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && |
| 172 updated_passwords_.empty()); | 177 updated_passwords_.empty()); |
| 173 | 178 |
| 174 for (sync_api::ChangeRecordList::const_iterator it = | 179 for (sync_api::ChangeRecordList::const_iterator it = |
| 175 changes.Get().begin(); it != changes.Get().end(); ++it) { | 180 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| 176 if (sync_api::ChangeRecord::ACTION_DELETE == | 181 if (sync_api::ChangeRecord::ACTION_DELETE == |
| 177 it->action) { | 182 it->action) { |
| 178 DCHECK(it->specifics.has_password()) | 183 DCHECK(it->specifics.has_password()) |
| 179 << "Password specifics data not present on delete!"; | 184 << "Password specifics data not present on delete!"; |
| 180 DCHECK(it->extra.get()); | 185 DCHECK(it->extra.get()); |
| 181 sync_api::ExtraPasswordChangeRecordData* extra = | 186 sync_api::ExtraPasswordChangeRecordData* extra = |
| 182 it->extra.get(); | 187 it->extra.get(); |
| 183 const sync_pb::PasswordSpecificsData& password = extra->unencrypted(); | 188 const sync_pb::PasswordSpecificsData& password = extra->unencrypted(); |
| 184 webkit::forms::PasswordForm form; | 189 webkit::forms::PasswordForm form; |
| 185 PasswordModelAssociator::CopyPassword(password, &form); | 190 PasswordModelAssociator::CopyPassword(password, &form); |
| 186 deleted_passwords_.push_back(form); | 191 deleted_passwords_.push_back(form); |
| 187 model_associator_->Disassociate(it->id); | 192 model_associator_->Disassociate(it->id); |
| 188 continue; | 193 continue; |
| 189 } | 194 } |
| 190 | 195 |
| 191 sync_api::ReadNode sync_node(trans); | 196 sync_api::ReadNode sync_node(trans); |
| 192 if (!sync_node.InitByIdLookup(it->id)) { | 197 if (sync_node.InitByIdLookup(it->id) != sync_api::BaseNode::INIT_OK) { |
| 193 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 198 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 194 "Password node lookup failed."); | 199 "Password node lookup failed."); |
| 195 return; | 200 return; |
| 196 } | 201 } |
| 197 | 202 |
| 198 // Check that the changed node is a child of the passwords folder. | 203 // Check that the changed node is a child of the passwords folder. |
| 199 DCHECK_EQ(password_root.GetId(), sync_node.GetParentId()); | 204 DCHECK_EQ(password_root.GetId(), sync_node.GetParentId()); |
| 200 DCHECK_EQ(syncable::PASSWORDS, sync_node.GetModelType()); | 205 DCHECK_EQ(syncable::PASSWORDS, sync_node.GetModelType()); |
| 201 | 206 |
| 202 const sync_pb::PasswordSpecificsData& password_data = | 207 const sync_pb::PasswordSpecificsData& password_data = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 261 |
| 257 void PasswordChangeProcessor::StopObserving() { | 262 void PasswordChangeProcessor::StopObserving() { |
| 258 DCHECK(expected_loop_ == MessageLoop::current()); | 263 DCHECK(expected_loop_ == MessageLoop::current()); |
| 259 notification_registrar_.Remove( | 264 notification_registrar_.Remove( |
| 260 this, | 265 this, |
| 261 chrome::NOTIFICATION_LOGINS_CHANGED, | 266 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 262 content::Source<PasswordStore>(password_store_)); | 267 content::Source<PasswordStore>(password_store_)); |
| 263 } | 268 } |
| 264 | 269 |
| 265 } // namespace browser_sync | 270 } // namespace browser_sync |
| OLD | NEW |