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_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 16 matching lines...) Expand all Loading... |
27 const char kPasswordTag[] = "google_chrome_passwords"; | 27 const char kPasswordTag[] = "google_chrome_passwords"; |
28 | 28 |
29 PasswordModelAssociator::PasswordModelAssociator( | 29 PasswordModelAssociator::PasswordModelAssociator( |
30 ProfileSyncService* sync_service, | 30 ProfileSyncService* sync_service, |
31 PasswordStore* password_store, | 31 PasswordStore* password_store, |
32 DataTypeErrorHandler* error_handler) | 32 DataTypeErrorHandler* error_handler) |
33 : sync_service_(sync_service), | 33 : sync_service_(sync_service), |
34 password_store_(password_store), | 34 password_store_(password_store), |
35 password_node_id_(syncer::kInvalidId), | 35 password_node_id_(syncer::kInvalidId), |
36 abort_association_pending_(false), | 36 abort_association_pending_(false), |
37 expected_loop_(MessageLoop::current()), | 37 expected_loop_(base::MessageLoop::current()), |
38 error_handler_(error_handler) { | 38 error_handler_(error_handler) { |
39 DCHECK(sync_service_); | 39 DCHECK(sync_service_); |
40 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
41 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
42 #else | 42 #else |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
44 #endif | 44 #endif |
45 } | 45 } |
46 | 46 |
47 PasswordModelAssociator::~PasswordModelAssociator() {} | 47 PasswordModelAssociator::~PasswordModelAssociator() {} |
48 | 48 |
49 syncer::SyncError PasswordModelAssociator::AssociateModels( | 49 syncer::SyncError PasswordModelAssociator::AssociateModels( |
50 syncer::SyncMergeResult* local_merge_result, | 50 syncer::SyncMergeResult* local_merge_result, |
51 syncer::SyncMergeResult* syncer_merge_result) { | 51 syncer::SyncMergeResult* syncer_merge_result) { |
52 syncer::SyncError error; | 52 syncer::SyncError error; |
53 DCHECK(expected_loop_ == MessageLoop::current()); | 53 DCHECK(expected_loop_ == base::MessageLoop::current()); |
54 { | 54 { |
55 base::AutoLock lock(abort_association_pending_lock_); | 55 base::AutoLock lock(abort_association_pending_lock_); |
56 abort_association_pending_ = false; | 56 abort_association_pending_ = false; |
57 } | 57 } |
58 | 58 |
59 // We must not be holding a transaction when we interact with the password | 59 // We must not be holding a transaction when we interact with the password |
60 // store, as it can post tasks to the UI thread which can itself be blocked | 60 // store, as it can post tasks to the UI thread which can itself be blocked |
61 // on our transaction, resulting in deadlock. (http://crbug.com/70658) | 61 // on our transaction, resulting in deadlock. (http://crbug.com/70658) |
62 std::vector<content::PasswordForm*> passwords; | 62 std::vector<content::PasswordForm*> passwords; |
63 if (!password_store_->FillAutofillableLogins(&passwords) || | 63 if (!password_store_->FillAutofillableLogins(&passwords) || |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 NULL); | 174 NULL); |
175 if (error.IsSet()) { | 175 if (error.IsSet()) { |
176 return error; | 176 return error; |
177 } | 177 } |
178 | 178 |
179 return error; | 179 return error; |
180 } | 180 } |
181 | 181 |
182 bool PasswordModelAssociator::DeleteAllNodes( | 182 bool PasswordModelAssociator::DeleteAllNodes( |
183 syncer::WriteTransaction* trans) { | 183 syncer::WriteTransaction* trans) { |
184 DCHECK(expected_loop_ == MessageLoop::current()); | 184 DCHECK(expected_loop_ == base::MessageLoop::current()); |
185 for (PasswordToSyncIdMap::iterator node_id = id_map_.begin(); | 185 for (PasswordToSyncIdMap::iterator node_id = id_map_.begin(); |
186 node_id != id_map_.end(); ++node_id) { | 186 node_id != id_map_.end(); ++node_id) { |
187 syncer::WriteNode sync_node(trans); | 187 syncer::WriteNode sync_node(trans); |
188 if (sync_node.InitByIdLookup(node_id->second) != | 188 if (sync_node.InitByIdLookup(node_id->second) != |
189 syncer::BaseNode::INIT_OK) { | 189 syncer::BaseNode::INIT_OK) { |
190 LOG(ERROR) << "Typed url node lookup failed."; | 190 LOG(ERROR) << "Typed url node lookup failed."; |
191 return false; | 191 return false; |
192 } | 192 } |
193 sync_node.Tombstone(); | 193 sync_node.Tombstone(); |
194 } | 194 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 259 } |
260 | 260 |
261 int64 PasswordModelAssociator::GetSyncIdFromChromeId( | 261 int64 PasswordModelAssociator::GetSyncIdFromChromeId( |
262 const std::string& password) { | 262 const std::string& password) { |
263 PasswordToSyncIdMap::const_iterator iter = id_map_.find(password); | 263 PasswordToSyncIdMap::const_iterator iter = id_map_.find(password); |
264 return iter == id_map_.end() ? syncer::kInvalidId : iter->second; | 264 return iter == id_map_.end() ? syncer::kInvalidId : iter->second; |
265 } | 265 } |
266 | 266 |
267 void PasswordModelAssociator::Associate( | 267 void PasswordModelAssociator::Associate( |
268 const std::string* password, int64 sync_id) { | 268 const std::string* password, int64 sync_id) { |
269 DCHECK(expected_loop_ == MessageLoop::current()); | 269 DCHECK(expected_loop_ == base::MessageLoop::current()); |
270 DCHECK_NE(syncer::kInvalidId, sync_id); | 270 DCHECK_NE(syncer::kInvalidId, sync_id); |
271 DCHECK(id_map_.find(*password) == id_map_.end()); | 271 DCHECK(id_map_.find(*password) == id_map_.end()); |
272 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); | 272 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); |
273 id_map_[*password] = sync_id; | 273 id_map_[*password] = sync_id; |
274 id_map_inverse_[sync_id] = *password; | 274 id_map_inverse_[sync_id] = *password; |
275 } | 275 } |
276 | 276 |
277 void PasswordModelAssociator::Disassociate(int64 sync_id) { | 277 void PasswordModelAssociator::Disassociate(int64 sync_id) { |
278 DCHECK(expected_loop_ == MessageLoop::current()); | 278 DCHECK(expected_loop_ == base::MessageLoop::current()); |
279 SyncIdToPasswordMap::iterator iter = id_map_inverse_.find(sync_id); | 279 SyncIdToPasswordMap::iterator iter = id_map_inverse_.find(sync_id); |
280 if (iter == id_map_inverse_.end()) | 280 if (iter == id_map_inverse_.end()) |
281 return; | 281 return; |
282 CHECK(id_map_.erase(iter->second)); | 282 CHECK(id_map_.erase(iter->second)); |
283 id_map_inverse_.erase(iter); | 283 id_map_inverse_.erase(iter); |
284 } | 284 } |
285 | 285 |
286 bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, | 286 bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, |
287 int64* sync_id) { | 287 int64* sync_id) { |
288 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 288 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 const std::string& password_element, | 437 const std::string& password_element, |
438 const std::string& signon_realm) { | 438 const std::string& signon_realm) { |
439 return net::EscapePath(origin_url) + "|" + | 439 return net::EscapePath(origin_url) + "|" + |
440 net::EscapePath(username_element) + "|" + | 440 net::EscapePath(username_element) + "|" + |
441 net::EscapePath(username_value) + "|" + | 441 net::EscapePath(username_value) + "|" + |
442 net::EscapePath(password_element) + "|" + | 442 net::EscapePath(password_element) + "|" + |
443 net::EscapePath(signon_realm); | 443 net::EscapePath(signon_realm); |
444 } | 444 } |
445 | 445 |
446 } // namespace browser_sync | 446 } // namespace browser_sync |
OLD | NEW |