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

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

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 months 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
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 int type, 56 int type,
57 const content::NotificationSource& source, 57 const content::NotificationSource& source,
58 const content::NotificationDetails& details) { 58 const content::NotificationDetails& details) {
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 csync::WriteTransaction trans(FROM_HERE, share_handle()); 66 syncer::WriteTransaction trans(FROM_HERE, share_handle());
67 67
68 csync::ReadNode password_root(&trans); 68 syncer::ReadNode password_root(&trans);
69 if (password_root.InitByTagLookup(kPasswordTag) != 69 if (password_root.InitByTagLookup(kPasswordTag) !=
70 csync::BaseNode::INIT_OK) { 70 syncer::BaseNode::INIT_OK) {
71 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 71 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
72 "Server did not create the top-level password node. " 72 "Server did not create the top-level password node. "
73 "We might be running against an out-of-date server."); 73 "We might be running against an out-of-date server.");
74 return; 74 return;
75 } 75 }
76 76
77 PasswordStoreChangeList* changes = 77 PasswordStoreChangeList* changes =
78 content::Details<PasswordStoreChangeList>(details).ptr(); 78 content::Details<PasswordStoreChangeList>(details).ptr();
79 for (PasswordStoreChangeList::iterator change = changes->begin(); 79 for (PasswordStoreChangeList::iterator change = changes->begin();
80 change != changes->end(); ++change) { 80 change != changes->end(); ++change) {
81 std::string tag = PasswordModelAssociator::MakeTag(change->form()); 81 std::string tag = PasswordModelAssociator::MakeTag(change->form());
82 switch (change->type()) { 82 switch (change->type()) {
83 case PasswordStoreChange::ADD: { 83 case PasswordStoreChange::ADD: {
84 csync::WriteNode sync_node(&trans); 84 syncer::WriteNode sync_node(&trans);
85 csync::WriteNode::InitUniqueByCreationResult result = 85 syncer::WriteNode::InitUniqueByCreationResult result =
86 sync_node.InitUniqueByCreation(syncable::PASSWORDS, password_root, 86 sync_node.InitUniqueByCreation(syncable::PASSWORDS, password_root,
87 tag); 87 tag);
88 if (result == csync::WriteNode::INIT_SUCCESS) { 88 if (result == syncer::WriteNode::INIT_SUCCESS) {
89 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); 89 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node);
90 model_associator_->Associate(&tag, sync_node.GetId()); 90 model_associator_->Associate(&tag, sync_node.GetId());
91 break; 91 break;
92 } else { 92 } else {
93 // Maybe this node already exists and we should update it. 93 // Maybe this node already exists and we should update it.
94 // 94 //
95 // If the PasswordStore is told to add an entry but an entry with the 95 // If the PasswordStore is told to add an entry but an entry with the
96 // same name already exists, it will overwrite it. It will report 96 // same name already exists, it will overwrite it. It will report
97 // this change as an ADD rather than an UPDATE. Ideally, it would be 97 // this change as an ADD rather than an UPDATE. Ideally, it would be
98 // able to tell us what action was actually taken, rather than what 98 // able to tell us what action was actually taken, rather than what
99 // action was requested. If it did so, we wouldn't need to fall back 99 // action was requested. If it did so, we wouldn't need to fall back
100 // to trying to update an existing password node here. 100 // to trying to update an existing password node here.
101 // 101 //
102 // TODO: Remove this. See crbug.com/87855. 102 // TODO: Remove this. See crbug.com/87855.
103 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); 103 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag);
104 if (csync::kInvalidId == sync_id) { 104 if (syncer::kInvalidId == sync_id) {
105 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 105 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
106 "Unable to create or retrieve password node"); 106 "Unable to create or retrieve password node");
107 LOG(ERROR) << "Invalid sync id."; 107 LOG(ERROR) << "Invalid sync id.";
108 return; 108 return;
109 } 109 }
110 if (sync_node.InitByIdLookup(sync_id) != 110 if (sync_node.InitByIdLookup(sync_id) !=
111 csync::BaseNode::INIT_OK) { 111 syncer::BaseNode::INIT_OK) {
112 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 112 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
113 "Password node lookup failed."); 113 "Password node lookup failed.");
114 LOG(ERROR) << "Password node lookup failed."; 114 LOG(ERROR) << "Password node lookup failed.";
115 return; 115 return;
116 } 116 }
117 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); 117 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node);
118 break; 118 break;
119 } 119 }
120 } 120 }
121 case PasswordStoreChange::UPDATE: { 121 case PasswordStoreChange::UPDATE: {
122 csync::WriteNode sync_node(&trans); 122 syncer::WriteNode sync_node(&trans);
123 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); 123 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag);
124 if (csync::kInvalidId == sync_id) { 124 if (syncer::kInvalidId == sync_id) {
125 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 125 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
126 "Invalid sync id"); 126 "Invalid sync id");
127 LOG(ERROR) << "Invalid sync id."; 127 LOG(ERROR) << "Invalid sync id.";
128 return; 128 return;
129 } else { 129 } else {
130 if (sync_node.InitByIdLookup(sync_id) != 130 if (sync_node.InitByIdLookup(sync_id) !=
131 csync::BaseNode::INIT_OK) { 131 syncer::BaseNode::INIT_OK) {
132 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 132 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
133 "Password node lookup failed."); 133 "Password node lookup failed.");
134 LOG(ERROR) << "Password node lookup failed."; 134 LOG(ERROR) << "Password node lookup failed.";
135 return; 135 return;
136 } 136 }
137 } 137 }
138 138
139 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node); 139 PasswordModelAssociator::WriteToSyncNode(change->form(), &sync_node);
140 break; 140 break;
141 } 141 }
142 case PasswordStoreChange::REMOVE: { 142 case PasswordStoreChange::REMOVE: {
143 csync::WriteNode sync_node(&trans); 143 syncer::WriteNode sync_node(&trans);
144 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag); 144 int64 sync_id = model_associator_->GetSyncIdFromChromeId(tag);
145 if (csync::kInvalidId == sync_id) { 145 if (syncer::kInvalidId == sync_id) {
146 // We've been asked to remove a password that we don't know about. 146 // We've been asked to remove a password that we don't know about.
147 // That's weird, but apparently we were already in the requested 147 // That's weird, but apparently we were already in the requested
148 // state, so it's not really an unrecoverable error. Just return. 148 // state, so it's not really an unrecoverable error. Just return.
149 LOG(WARNING) << "Trying to delete nonexistent password sync node!"; 149 LOG(WARNING) << "Trying to delete nonexistent password sync node!";
150 return; 150 return;
151 } else { 151 } else {
152 if (sync_node.InitByIdLookup(sync_id) != 152 if (sync_node.InitByIdLookup(sync_id) !=
153 csync::BaseNode::INIT_OK) { 153 syncer::BaseNode::INIT_OK) {
154 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 154 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
155 "Password node lookup failed."); 155 "Password node lookup failed.");
156 return; 156 return;
157 } 157 }
158 model_associator_->Disassociate(sync_node.GetId()); 158 model_associator_->Disassociate(sync_node.GetId());
159 sync_node.Remove(); 159 sync_node.Remove();
160 } 160 }
161 break; 161 break;
162 } 162 }
163 } 163 }
164 } 164 }
165 } 165 }
166 166
167 void PasswordChangeProcessor::ApplyChangesFromSyncModel( 167 void PasswordChangeProcessor::ApplyChangesFromSyncModel(
168 const csync::BaseTransaction* trans, 168 const syncer::BaseTransaction* trans,
169 const csync::ImmutableChangeRecordList& changes) { 169 const syncer::ImmutableChangeRecordList& changes) {
170 DCHECK(expected_loop_ == MessageLoop::current()); 170 DCHECK(expected_loop_ == MessageLoop::current());
171 if (!running()) 171 if (!running())
172 return; 172 return;
173 173
174 csync::ReadNode password_root(trans); 174 syncer::ReadNode password_root(trans);
175 if (password_root.InitByTagLookup(kPasswordTag) != 175 if (password_root.InitByTagLookup(kPasswordTag) !=
176 csync::BaseNode::INIT_OK) { 176 syncer::BaseNode::INIT_OK) {
177 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 177 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
178 "Password root node lookup failed."); 178 "Password root node lookup failed.");
179 return; 179 return;
180 } 180 }
181 181
182 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() && 182 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() &&
183 updated_passwords_.empty()); 183 updated_passwords_.empty());
184 184
185 for (csync::ChangeRecordList::const_iterator it = 185 for (syncer::ChangeRecordList::const_iterator it =
186 changes.Get().begin(); it != changes.Get().end(); ++it) { 186 changes.Get().begin(); it != changes.Get().end(); ++it) {
187 if (csync::ChangeRecord::ACTION_DELETE == 187 if (syncer::ChangeRecord::ACTION_DELETE ==
188 it->action) { 188 it->action) {
189 DCHECK(it->specifics.has_password()) 189 DCHECK(it->specifics.has_password())
190 << "Password specifics data not present on delete!"; 190 << "Password specifics data not present on delete!";
191 DCHECK(it->extra.get()); 191 DCHECK(it->extra.get());
192 csync::ExtraPasswordChangeRecordData* extra = 192 syncer::ExtraPasswordChangeRecordData* extra =
193 it->extra.get(); 193 it->extra.get();
194 const sync_pb::PasswordSpecificsData& password = extra->unencrypted(); 194 const sync_pb::PasswordSpecificsData& password = extra->unencrypted();
195 webkit::forms::PasswordForm form; 195 webkit::forms::PasswordForm form;
196 PasswordModelAssociator::CopyPassword(password, &form); 196 PasswordModelAssociator::CopyPassword(password, &form);
197 deleted_passwords_.push_back(form); 197 deleted_passwords_.push_back(form);
198 model_associator_->Disassociate(it->id); 198 model_associator_->Disassociate(it->id);
199 continue; 199 continue;
200 } 200 }
201 201
202 csync::ReadNode sync_node(trans); 202 syncer::ReadNode sync_node(trans);
203 if (sync_node.InitByIdLookup(it->id) != csync::BaseNode::INIT_OK) { 203 if (sync_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) {
204 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 204 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
205 "Password node lookup failed."); 205 "Password node lookup failed.");
206 return; 206 return;
207 } 207 }
208 208
209 // Check that the changed node is a child of the passwords folder. 209 // Check that the changed node is a child of the passwords folder.
210 DCHECK_EQ(password_root.GetId(), sync_node.GetParentId()); 210 DCHECK_EQ(password_root.GetId(), sync_node.GetParentId());
211 DCHECK_EQ(syncable::PASSWORDS, sync_node.GetModelType()); 211 DCHECK_EQ(syncable::PASSWORDS, sync_node.GetModelType());
212 212
213 const sync_pb::PasswordSpecificsData& password_data = 213 const sync_pb::PasswordSpecificsData& password_data =
214 sync_node.GetPasswordSpecifics(); 214 sync_node.GetPasswordSpecifics();
215 webkit::forms::PasswordForm password; 215 webkit::forms::PasswordForm password;
216 PasswordModelAssociator::CopyPassword(password_data, &password); 216 PasswordModelAssociator::CopyPassword(password_data, &password);
217 217
218 if (csync::ChangeRecord::ACTION_ADD == it->action) { 218 if (syncer::ChangeRecord::ACTION_ADD == it->action) {
219 std::string tag(PasswordModelAssociator::MakeTag(password)); 219 std::string tag(PasswordModelAssociator::MakeTag(password));
220 model_associator_->Associate(&tag, sync_node.GetId()); 220 model_associator_->Associate(&tag, sync_node.GetId());
221 new_passwords_.push_back(password); 221 new_passwords_.push_back(password);
222 } else { 222 } else {
223 DCHECK_EQ(csync::ChangeRecord::ACTION_UPDATE, it->action); 223 DCHECK_EQ(syncer::ChangeRecord::ACTION_UPDATE, it->action);
224 updated_passwords_.push_back(password); 224 updated_passwords_.push_back(password);
225 } 225 }
226 } 226 }
227 } 227 }
228 228
229 void PasswordChangeProcessor::CommitChangesFromSyncModel() { 229 void PasswordChangeProcessor::CommitChangesFromSyncModel() {
230 DCHECK(expected_loop_ == MessageLoop::current()); 230 DCHECK(expected_loop_ == MessageLoop::current());
231 if (!running()) 231 if (!running())
232 return; 232 return;
233 ScopedStopObserving<PasswordChangeProcessor> stop_observing(this); 233 ScopedStopObserving<PasswordChangeProcessor> stop_observing(this);
234 234
235 csync::SyncError error = model_associator_->WriteToPasswordStore( 235 syncer::SyncError error = model_associator_->WriteToPasswordStore(
236 &new_passwords_, 236 &new_passwords_,
237 &updated_passwords_, 237 &updated_passwords_,
238 &deleted_passwords_); 238 &deleted_passwords_);
239 if (error.IsSet()) { 239 if (error.IsSet()) {
240 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 240 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
241 "Error writing passwords"); 241 "Error writing passwords");
242 return; 242 return;
243 } 243 }
244 244
245 deleted_passwords_.clear(); 245 deleted_passwords_.clear();
(...skipping 21 matching lines...) Expand all
267 267
268 void PasswordChangeProcessor::StopObserving() { 268 void PasswordChangeProcessor::StopObserving() {
269 DCHECK(expected_loop_ == MessageLoop::current()); 269 DCHECK(expected_loop_ == MessageLoop::current());
270 notification_registrar_.Remove( 270 notification_registrar_.Remove(
271 this, 271 this,
272 chrome::NOTIFICATION_LOGINS_CHANGED, 272 chrome::NOTIFICATION_LOGINS_CHANGED,
273 content::Source<PasswordStore>(password_store_)); 273 content::Source<PasswordStore>(password_store_));
274 } 274 }
275 275
276 } // namespace browser_sync 276 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/password_change_processor.h ('k') | chrome/browser/sync/glue/password_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698