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

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

Issue 6878038: [Sync] Ensure we don't hold a transaction when we access password store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rearrange Created 9 years, 8 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) 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/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 } 124 }
125 125
126 void PasswordChangeProcessor::ApplyChangesFromSyncModel( 126 void PasswordChangeProcessor::ApplyChangesFromSyncModel(
127 const sync_api::BaseTransaction* trans, 127 const sync_api::BaseTransaction* trans,
128 const sync_api::SyncManager::ChangeRecord* changes, 128 const sync_api::SyncManager::ChangeRecord* changes,
129 int change_count) { 129 int change_count) {
130 DCHECK(expected_loop_ == MessageLoop::current()); 130 DCHECK(expected_loop_ == MessageLoop::current());
131 if (!running()) 131 if (!running())
132 return; 132 return;
133 StopObserving();
134 133
135 sync_api::ReadNode password_root(trans); 134 sync_api::ReadNode password_root(trans);
136 if (!password_root.InitByTagLookup(kPasswordTag)) { 135 if (!password_root.InitByTagLookup(kPasswordTag)) {
137 error_handler()->OnUnrecoverableError(FROM_HERE, 136 error_handler()->OnUnrecoverableError(FROM_HERE,
138 "Password root node lookup failed."); 137 "Password root node lookup failed.");
139 return; 138 return;
140 } 139 }
141 140
142 PasswordModelAssociator::PasswordVector new_passwords; 141 DCHECK(deleted_passwords_.empty() && new_passwords_.empty() &&
143 PasswordModelAssociator::PasswordVector updated_passwords; 142 updated_passwords_.empty());
144 PasswordModelAssociator::PasswordVector deleted_passwords;
145 143
146 for (int i = 0; i < change_count; ++i) { 144 for (int i = 0; i < change_count; ++i) {
147 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == 145 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE ==
148 changes[i].action) { 146 changes[i].action) {
149 DCHECK(changes[i].specifics.HasExtension(sync_pb::password)) 147 DCHECK(changes[i].specifics.HasExtension(sync_pb::password))
150 << "Password specifics data not present on delete!"; 148 << "Password specifics data not present on delete!";
151 DCHECK(changes[i].extra.get()); 149 DCHECK(changes[i].extra.get());
152 sync_api::SyncManager::ExtraPasswordChangeRecordData* extra = 150 sync_api::SyncManager::ExtraPasswordChangeRecordData* extra =
153 changes[i].extra.get(); 151 changes[i].extra.get();
154 const sync_pb::PasswordSpecificsData& password = extra->unencrypted(); 152 const sync_pb::PasswordSpecificsData& password = extra->unencrypted();
155 webkit_glue::PasswordForm form; 153 webkit_glue::PasswordForm form;
156 PasswordModelAssociator::CopyPassword(password, &form); 154 PasswordModelAssociator::CopyPassword(password, &form);
157 deleted_passwords.push_back(form); 155 deleted_passwords_.push_back(form);
158 model_associator_->Disassociate(changes[i].id); 156 model_associator_->Disassociate(changes[i].id);
159 continue; 157 continue;
160 } 158 }
161 159
162 sync_api::ReadNode sync_node(trans); 160 sync_api::ReadNode sync_node(trans);
163 if (!sync_node.InitByIdLookup(changes[i].id)) { 161 if (!sync_node.InitByIdLookup(changes[i].id)) {
164 error_handler()->OnUnrecoverableError(FROM_HERE, 162 error_handler()->OnUnrecoverableError(FROM_HERE,
165 "Password node lookup failed."); 163 "Password node lookup failed.");
166 return; 164 return;
167 } 165 }
168 166
169 // Check that the changed node is a child of the passwords folder. 167 // Check that the changed node is a child of the passwords folder.
170 DCHECK(password_root.GetId() == sync_node.GetParentId()); 168 DCHECK(password_root.GetId() == sync_node.GetParentId());
171 DCHECK(syncable::PASSWORDS == sync_node.GetModelType()); 169 DCHECK(syncable::PASSWORDS == sync_node.GetModelType());
172 170
173 const sync_pb::PasswordSpecificsData& password_data = 171 const sync_pb::PasswordSpecificsData& password_data =
174 sync_node.GetPasswordSpecifics(); 172 sync_node.GetPasswordSpecifics();
175 webkit_glue::PasswordForm password; 173 webkit_glue::PasswordForm password;
176 PasswordModelAssociator::CopyPassword(password_data, &password); 174 PasswordModelAssociator::CopyPassword(password_data, &password);
177 175
178 if (sync_api::SyncManager::ChangeRecord::ACTION_ADD == changes[i].action) { 176 if (sync_api::SyncManager::ChangeRecord::ACTION_ADD == changes[i].action) {
179 std::string tag(PasswordModelAssociator::MakeTag(password)); 177 std::string tag(PasswordModelAssociator::MakeTag(password));
180 model_associator_->Associate(&tag, sync_node.GetId()); 178 model_associator_->Associate(&tag, sync_node.GetId());
181 new_passwords.push_back(password); 179 new_passwords_.push_back(password);
182 } else { 180 } else {
183 DCHECK(sync_api::SyncManager::ChangeRecord::ACTION_UPDATE == 181 DCHECK(sync_api::SyncManager::ChangeRecord::ACTION_UPDATE ==
184 changes[i].action); 182 changes[i].action);
185 updated_passwords.push_back(password); 183 updated_passwords_.push_back(password);
186 } 184 }
187 } 185 }
186 }
188 187
189 if (!model_associator_->WriteToPasswordStore(&new_passwords, 188 void PasswordChangeProcessor::CommitChangesFromSyncModel() {
190 &updated_passwords, 189 DCHECK(expected_loop_ == MessageLoop::current());
191 &deleted_passwords)) { 190 if (!running())
191 return;
192 StopObserving();
193
194 if (!model_associator_->WriteToPasswordStore(&new_passwords_,
195 &updated_passwords_,
196 &deleted_passwords_)) {
192 error_handler()->OnUnrecoverableError(FROM_HERE, "Error writing passwords"); 197 error_handler()->OnUnrecoverableError(FROM_HERE, "Error writing passwords");
193 return; 198 return;
194 } 199 }
195 200
201 deleted_passwords_.clear();
202 new_passwords_.clear();
203 updated_passwords_.clear();
204
196 StartObserving(); 205 StartObserving();
197 } 206 }
198 207
199 void PasswordChangeProcessor::StartImpl(Profile* profile) { 208 void PasswordChangeProcessor::StartImpl(Profile* profile) {
200 DCHECK(expected_loop_ == MessageLoop::current()); 209 DCHECK(expected_loop_ == MessageLoop::current());
201 observing_ = true; 210 observing_ = true;
202 } 211 }
203 212
204 void PasswordChangeProcessor::StopImpl() { 213 void PasswordChangeProcessor::StopImpl() {
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
206 observing_ = false; 215 observing_ = false;
207 } 216 }
208 217
209 218
210 void PasswordChangeProcessor::StartObserving() { 219 void PasswordChangeProcessor::StartObserving() {
211 DCHECK(expected_loop_ == MessageLoop::current()); 220 DCHECK(expected_loop_ == MessageLoop::current());
212 notification_registrar_.Add(this, 221 notification_registrar_.Add(this,
213 NotificationType::LOGINS_CHANGED, 222 NotificationType::LOGINS_CHANGED,
214 Source<PasswordStore>(password_store_)); 223 Source<PasswordStore>(password_store_));
215 } 224 }
216 225
217 void PasswordChangeProcessor::StopObserving() { 226 void PasswordChangeProcessor::StopObserving() {
218 DCHECK(expected_loop_ == MessageLoop::current()); 227 DCHECK(expected_loop_ == MessageLoop::current());
219 notification_registrar_.Remove(this, 228 notification_registrar_.Remove(this,
220 NotificationType::LOGINS_CHANGED, 229 NotificationType::LOGINS_CHANGED,
221 Source<PasswordStore>(password_store_)); 230 Source<PasswordStore>(password_store_));
222 } 231 }
223 232
224 } // namespace browser_sync 233 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/password_change_processor.h ('k') | chrome/browser/sync/glue/password_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698