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

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

Issue 10662035: [Sync] Put everything in sync/api into csync namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 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_model_associator.h" 5 #include "chrome/browser/sync/glue/password_model_associator.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 29 matching lines...) Expand all
40 DCHECK(password_store_); 40 DCHECK(password_store_);
41 #if defined(OS_MACOSX) 41 #if defined(OS_MACOSX)
42 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 42 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
43 #else 43 #else
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
45 #endif 45 #endif
46 } 46 }
47 47
48 PasswordModelAssociator::~PasswordModelAssociator() {} 48 PasswordModelAssociator::~PasswordModelAssociator() {}
49 49
50 SyncError PasswordModelAssociator::AssociateModels() { 50 csync::SyncError PasswordModelAssociator::AssociateModels() {
51 SyncError error; 51 csync::SyncError error;
52 DCHECK(expected_loop_ == MessageLoop::current()); 52 DCHECK(expected_loop_ == MessageLoop::current());
53 { 53 {
54 base::AutoLock lock(abort_association_pending_lock_); 54 base::AutoLock lock(abort_association_pending_lock_);
55 abort_association_pending_ = false; 55 abort_association_pending_ = false;
56 } 56 }
57 57
58 // We must not be holding a transaction when we interact with the password 58 // We must not be holding a transaction when we interact with the password
59 // store, as it can post tasks to the UI thread which can itself be blocked 59 // store, as it can post tasks to the UI thread which can itself be blocked
60 // on our transaction, resulting in deadlock. (http://crbug.com/70658) 60 // on our transaction, resulting in deadlock. (http://crbug.com/70658)
61 std::vector<webkit::forms::PasswordForm*> passwords; 61 std::vector<webkit::forms::PasswordForm*> passwords;
(...skipping 18 matching lines...) Expand all
80 FROM_HERE, 80 FROM_HERE,
81 "Server did not create the top-level password node. We " 81 "Server did not create the top-level password node. We "
82 "might be running against an out-of-date server.", 82 "might be running against an out-of-date server.",
83 model_type()); 83 model_type());
84 } 84 }
85 85
86 for (std::vector<webkit::forms::PasswordForm*>::iterator ix = 86 for (std::vector<webkit::forms::PasswordForm*>::iterator ix =
87 passwords.begin(); 87 passwords.begin();
88 ix != passwords.end(); ++ix) { 88 ix != passwords.end(); ++ix) {
89 if (IsAbortPending()) { 89 if (IsAbortPending()) {
90 return SyncError(); 90 return csync::SyncError();
91 } 91 }
92 std::string tag = MakeTag(**ix); 92 std::string tag = MakeTag(**ix);
93 93
94 csync::ReadNode node(&trans); 94 csync::ReadNode node(&trans);
95 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag) == 95 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag) ==
96 csync::BaseNode::INIT_OK) { 96 csync::BaseNode::INIT_OK) {
97 const sync_pb::PasswordSpecificsData& password = 97 const sync_pb::PasswordSpecificsData& password =
98 node.GetPasswordSpecifics(); 98 node.GetPasswordSpecifics();
99 DCHECK_EQ(tag, MakeTag(password)); 99 DCHECK_EQ(tag, MakeTag(password));
100 100
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return false; 190 return false;
191 } 191 }
192 sync_node.Remove(); 192 sync_node.Remove();
193 } 193 }
194 194
195 id_map_.clear(); 195 id_map_.clear();
196 id_map_inverse_.clear(); 196 id_map_inverse_.clear();
197 return true; 197 return true;
198 } 198 }
199 199
200 SyncError PasswordModelAssociator::DisassociateModels() { 200 csync::SyncError PasswordModelAssociator::DisassociateModels() {
201 id_map_.clear(); 201 id_map_.clear();
202 id_map_inverse_.clear(); 202 id_map_inverse_.clear();
203 return SyncError(); 203 return csync::SyncError();
204 } 204 }
205 205
206 bool PasswordModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { 206 bool PasswordModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
207 DCHECK(has_nodes); 207 DCHECK(has_nodes);
208 *has_nodes = false; 208 *has_nodes = false;
209 int64 password_sync_id; 209 int64 password_sync_id;
210 if (!GetSyncIdForTaggedNode(kPasswordTag, &password_sync_id)) { 210 if (!GetSyncIdForTaggedNode(kPasswordTag, &password_sync_id)) {
211 LOG(ERROR) << "Server did not create the top-level password node. We " 211 LOG(ERROR) << "Server did not create the top-level password node. We "
212 << "might be running against an out-of-date server."; 212 << "might be running against an out-of-date server.";
213 return false; 213 return false;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, 285 bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
286 int64* sync_id) { 286 int64* sync_id) {
287 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 287 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
288 csync::ReadNode sync_node(&trans); 288 csync::ReadNode sync_node(&trans);
289 if (sync_node.InitByTagLookup(tag.c_str()) != csync::BaseNode::INIT_OK) 289 if (sync_node.InitByTagLookup(tag.c_str()) != csync::BaseNode::INIT_OK)
290 return false; 290 return false;
291 *sync_id = sync_node.GetId(); 291 *sync_id = sync_node.GetId();
292 return true; 292 return true;
293 } 293 }
294 294
295 SyncError PasswordModelAssociator::WriteToPasswordStore( 295 csync::SyncError PasswordModelAssociator::WriteToPasswordStore(
296 const PasswordVector* new_passwords, 296 const PasswordVector* new_passwords,
297 const PasswordVector* updated_passwords, 297 const PasswordVector* updated_passwords,
298 const PasswordVector* deleted_passwords) { 298 const PasswordVector* deleted_passwords) {
299 if (new_passwords) { 299 if (new_passwords) {
300 for (PasswordVector::const_iterator password = new_passwords->begin(); 300 for (PasswordVector::const_iterator password = new_passwords->begin();
301 password != new_passwords->end(); ++password) { 301 password != new_passwords->end(); ++password) {
302 password_store_->AddLoginImpl(*password); 302 password_store_->AddLoginImpl(*password);
303 } 303 }
304 } 304 }
305 305
306 if (updated_passwords) { 306 if (updated_passwords) {
307 for (PasswordVector::const_iterator password = updated_passwords->begin(); 307 for (PasswordVector::const_iterator password = updated_passwords->begin();
308 password != updated_passwords->end(); ++password) { 308 password != updated_passwords->end(); ++password) {
309 password_store_->UpdateLoginImpl(*password); 309 password_store_->UpdateLoginImpl(*password);
310 } 310 }
311 } 311 }
312 312
313 if (deleted_passwords) { 313 if (deleted_passwords) {
314 for (PasswordVector::const_iterator password = deleted_passwords->begin(); 314 for (PasswordVector::const_iterator password = deleted_passwords->begin();
315 password != deleted_passwords->end(); ++password) { 315 password != deleted_passwords->end(); ++password) {
316 password_store_->RemoveLoginImpl(*password); 316 password_store_->RemoveLoginImpl(*password);
317 } 317 }
318 } 318 }
319 319
320 if (new_passwords || updated_passwords || deleted_passwords) { 320 if (new_passwords || updated_passwords || deleted_passwords) {
321 // We have to notify password store observers of the change by hand since 321 // We have to notify password store observers of the change by hand since
322 // we use internal password store interfaces to make changes synchronously. 322 // we use internal password store interfaces to make changes synchronously.
323 password_store_->PostNotifyLoginsChanged(); 323 password_store_->PostNotifyLoginsChanged();
324 } 324 }
325 return SyncError(); 325 return csync::SyncError();
326 } 326 }
327 327
328 // static 328 // static
329 void PasswordModelAssociator::CopyPassword( 329 void PasswordModelAssociator::CopyPassword(
330 const sync_pb::PasswordSpecificsData& password, 330 const sync_pb::PasswordSpecificsData& password,
331 webkit::forms::PasswordForm* new_password) { 331 webkit::forms::PasswordForm* new_password) {
332 new_password->scheme = 332 new_password->scheme =
333 static_cast<webkit::forms::PasswordForm::Scheme>(password.scheme()); 333 static_cast<webkit::forms::PasswordForm::Scheme>(password.scheme());
334 new_password->signon_realm = password.signon_realm(); 334 new_password->signon_realm = password.signon_realm();
335 new_password->origin = GURL(password.origin()); 335 new_password->origin = GURL(password.origin());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 const std::string& password_element, 436 const std::string& password_element,
437 const std::string& signon_realm) { 437 const std::string& signon_realm) {
438 return net::EscapePath(origin_url) + "|" + 438 return net::EscapePath(origin_url) + "|" +
439 net::EscapePath(username_element) + "|" + 439 net::EscapePath(username_element) + "|" +
440 net::EscapePath(username_value) + "|" + 440 net::EscapePath(username_value) + "|" +
441 net::EscapePath(password_element) + "|" + 441 net::EscapePath(password_element) + "|" +
442 net::EscapePath(signon_realm); 442 net::EscapePath(signon_realm);
443 } 443 }
444 444
445 } // namespace browser_sync 445 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698