Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/passwords/password_manager_presenter.h" | 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "chrome/browser/password_manager/password_manager_util_mac.h" | 46 #include "chrome/browser/password_manager/password_manager_util_mac.h" |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 using base::StringPiece; | 49 using base::StringPiece; |
| 50 using password_manager::PasswordStore; | 50 using password_manager::PasswordStore; |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 const char kSortKeyPartsSeparator = ' '; | 54 const char kSortKeyPartsSeparator = ' '; |
| 55 | 55 |
| 56 // The character that is added to a sort key if there is no federation. | |
| 57 const char kSortKeyNoFederationSymbol = '-'; | |
| 58 | |
| 56 // Helper function that returns the type of the entry (non-Android credentials, | 59 // Helper function that returns the type of the entry (non-Android credentials, |
| 57 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm). | 60 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm). |
| 58 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { | 61 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { |
| 59 if (!is_android_uri) | 62 if (!is_android_uri) |
| 60 return "0"; | 63 return "0"; |
| 61 if (is_clickable) | 64 if (is_clickable) |
| 62 return "1"; | 65 return "1"; |
| 63 return "2"; | 66 return "2"; |
| 64 } | 67 } |
| 65 | 68 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 84 net::registry_controlled_domains::GetDomainAndRegistry( | 87 net::registry_controlled_domains::GetDomainAndRegistry( |
| 85 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 88 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 86 if (site_name.empty()) // e.g. localhost. | 89 if (site_name.empty()) // e.g. localhost. |
| 87 site_name = origin; | 90 site_name = origin; |
| 88 std::string key = site_name + password_manager::SplitByDotAndReverse(origin); | 91 std::string key = site_name + password_manager::SplitByDotAndReverse(origin); |
| 89 | 92 |
| 90 if (entry_type == PasswordEntryType::SAVED) { | 93 if (entry_type == PasswordEntryType::SAVED) { |
| 91 key = key + kSortKeyPartsSeparator + | 94 key = key + kSortKeyPartsSeparator + |
| 92 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + | 95 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + |
| 93 base::UTF16ToUTF8(form.password_value); | 96 base::UTF16ToUTF8(form.password_value); |
| 94 if (!form.federation_origin.unique()) | 97 if (!form.federation_origin.unique()) |
|
vasilii
2016/11/15 13:18:11
Why don't you just use Origin::Serialize()?
kolos1
2016/11/15 13:57:38
Serialize() returns "null" if there is no federati
vasilii
2016/11/15 14:14:54
If it's important then it should go to a comment o
kolos1
2016/11/15 14:42:51
Done.
| |
| 95 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); | 98 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); |
| 99 else | |
| 100 key = key + kSortKeyPartsSeparator + kSortKeyNoFederationSymbol; | |
|
vasilii
2016/11/15 13:18:10
key+= is faster and easier to read.
kolos1
2016/11/15 13:57:38
In this particular case, we cannot use +=, because
vasilii
2016/11/15 14:14:55
key += kSortKeyPartsSeparator;
if ()
key += form
kolos1
2016/11/15 14:42:51
Done.
| |
| 96 } | 101 } |
| 97 | 102 |
| 103 // To separate HTTP/HTTPS credentials, add the scheme to the key. | |
| 104 key += kSortKeyPartsSeparator + link_url.scheme(); | |
| 105 | |
| 98 // Since Android and non-Android entries shouldn't be merged into one entry, | 106 // Since Android and non-Android entries shouldn't be merged into one entry, |
| 99 // add the entry type code to the sort key. | 107 // add the entry type code to the sort key. |
| 100 key += | 108 key += |
| 101 kSortKeyPartsSeparator + GetEntryTypeCode(is_android_uri, is_clickable); | 109 kSortKeyPartsSeparator + GetEntryTypeCode(is_android_uri, is_clickable); |
| 102 return key; | 110 return key; |
| 103 } | 111 } |
| 104 | 112 |
| 105 // Finds duplicates of |form| in |duplicates|, removes them from |store| and | 113 // Finds duplicates of |form| in |duplicates|, removes them from |store| and |
| 106 // from |duplicates|. | 114 // from |duplicates|. |
| 107 void RemoveDuplicates(const autofill::PasswordForm& form, | 115 void RemoveDuplicates(const autofill::PasswordForm& form, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 390 |
| 383 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 391 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 384 OnGetPasswordStoreResults( | 392 OnGetPasswordStoreResults( |
| 385 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { | 393 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { |
| 386 page_->password_exception_list_ = std::move(results); | 394 page_->password_exception_list_ = std::move(results); |
| 387 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, | 395 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, |
| 388 &page_->password_exception_duplicates_, | 396 &page_->password_exception_duplicates_, |
| 389 PasswordEntryType::BLACKLISTED); | 397 PasswordEntryType::BLACKLISTED); |
| 390 page_->SetPasswordExceptionList(); | 398 page_->SetPasswordExceptionList(); |
| 391 } | 399 } |
| OLD | NEW |