Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/sync/glue/password_change_processor.cc

Issue 8862005: Handle duplicate password sync nodes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/location.h" 9 #include "base/location.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 PasswordStoreChangeList* changes = 76 PasswordStoreChangeList* changes =
77 content::Details<PasswordStoreChangeList>(details).ptr(); 77 content::Details<PasswordStoreChangeList>(details).ptr();
78 for (PasswordStoreChangeList::iterator change = changes->begin(); 78 for (PasswordStoreChangeList::iterator change = changes->begin();
79 change != changes->end(); ++change) { 79 change != changes->end(); ++change) {
80 std::string tag = PasswordModelAssociator::MakeTag(change->form()); 80 std::string tag = PasswordModelAssociator::MakeTag(change->form());
81 switch (change->type()) { 81 switch (change->type()) {
82 case PasswordStoreChange::ADD: { 82 case PasswordStoreChange::ADD: {
83 sync_api::WriteNode sync_node(&trans); 83 sync_api::WriteNode sync_node(&trans);
84 if (!sync_node.InitUniqueByCreation(syncable::PASSWORDS, 84 if (sync_node.InitUniqueByCreation(syncable::PASSWORDS,
85 password_root, tag)) { 85 password_root, tag)) {
86 error_handler()->OnUnrecoverableError(FROM_HERE, 86 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node);
87 "Failed to create password sync node."); 87 model_associator_->Associate(&tag, sync_node.GetId());
88 return; 88 break;
89 } else {
90 // Maybe this node already exists and we should update it.
91 //
92 // If the PasswordStore is told to add an entry but an entry with the
93 // same name already exists, it will overwrite it. It will report
94 // this change as an ADD rather than an UPDATE. Ideally, it would be
95 // able to tell us what action was actually taken, rather than what
96 // 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 //
99 // TODO: Remove this. See crbug.com/87855.
100 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag);
101 if (sync_api::kInvalidId == sync_id) {
102 error_handler()->OnUnrecoverableError(FROM_HERE,
103 "Unable to create or lookup password node");
104 return;
105 }
106 if (!sync_node.InitByIdLookup(sync_id)) {
107 error_handler()->OnUnrecoverableError(FROM_HERE,
108 "Unable to create or lookup password node");
Mike Mammarella 2011/12/08 04:32:04 Grammar nit: "look up" is two words as a verb.
rlarocque 2011/12/09 18:53:42 Done.
109 return;
110 }
111 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node);
112 break;
89 } 113 }
90
91 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node);
92 model_associator_->Associate(&tag, sync_node.GetId());
93 break;
94 } 114 }
95 case PasswordStoreChange::UPDATE: { 115 case PasswordStoreChange::UPDATE: {
96 sync_api::WriteNode sync_node(&trans); 116 sync_api::WriteNode sync_node(&trans);
97 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); 117 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag);
98 if (sync_api::kInvalidId == sync_id) { 118 if (sync_api::kInvalidId == sync_id) {
99 error_handler()->OnUnrecoverableError(FROM_HERE, 119 error_handler()->OnUnrecoverableError(FROM_HERE,
100 "Unexpected notification for: "); 120 "Unexpected notification for: ");
101 return; 121 return;
102 } else { 122 } else {
103 if (!sync_node.InitByIdLookup(sync_id)) { 123 if (!sync_node.InitByIdLookup(sync_id)) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 253
234 void PasswordChangeProcessor::StopObserving() { 254 void PasswordChangeProcessor::StopObserving() {
235 DCHECK(expected_loop_ == MessageLoop::current()); 255 DCHECK(expected_loop_ == MessageLoop::current());
236 notification_registrar_.Remove( 256 notification_registrar_.Remove(
237 this, 257 this,
238 chrome::NOTIFICATION_LOGINS_CHANGED, 258 chrome::NOTIFICATION_LOGINS_CHANGED,
239 content::Source<PasswordStore>(password_store_)); 259 content::Source<PasswordStore>(password_store_));
240 } 260 }
241 261
242 } // namespace browser_sync 262 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698