Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/webdata/autofill_entry.h" | |
|
Ilya Sherman
2012/03/19 21:12:51
nit: Please leave a blank line between the copyrig
GeorgeY
2012/03/20 20:47:58
Done.
| |
| 4 | 5 |
| 5 #include <algorithm> | 6 #include <algorithm> |
| 6 #include <set> | 7 #include <set> |
| 7 | 8 |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "chrome/browser/webdata/autofill_entry.h" | |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 | 11 |
| 12 AutofillKey::AutofillKey() {} | 12 AutofillKey::AutofillKey() {} |
| 13 | 13 |
| 14 AutofillKey::AutofillKey(const string16& name, const string16& value) | 14 AutofillKey::AutofillKey(const string16& name, const string16& value) |
| 15 : name_(name), | 15 : name_(name), |
| 16 value_(value) { | 16 value_(value) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 AutofillKey::AutofillKey(const char* name, const char* value) | 19 AutofillKey::AutofillKey(const char* name, const char* value) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool AutofillEntry::operator<(const AutofillEntry& entry) const { | 71 bool AutofillEntry::operator<(const AutofillEntry& entry) const { |
| 72 return key_ < entry.key(); | 72 return key_ < entry.key(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Culls the list of timestamps to the most recent |kMaxAutofillTimeStamps|. | 75 bool AutofillEntry::IsExpired() const { |
| 76 base::Time time = ExpirationTime(); | |
| 77 DCHECK(!timestamps_.empty()); | |
| 78 return (timestamps_.empty() || timestamps_.back() < time); | |
|
Ilya Sherman
2012/03/19 21:12:51
nit: No need to check timestamps_.empty() given th
GeorgeY
2012/03/20 20:47:58
Old implementation *allows* for all of the timesta
Ilya Sherman
2012/03/20 21:25:13
If so, we shouldn't have a DCHECK() ;)
GeorgeY
2012/03/21 20:56:40
OK, removed. Again in the current code it is a val
Ilya Sherman
2012/03/21 21:20:53
nit: If the DCHECK() will be correct in the future
GeorgeY
2012/03/21 22:10:56
Done.
| |
| 79 } | |
| 80 | |
| 81 // static | |
| 82 base::Time AutofillEntry::ExpirationTime() { | |
| 83 return base::Time::Now() - base::TimeDelta::FromDays(kExpirationPeriodInDays); | |
| 84 } | |
| 85 | |
| 86 // Culls the list of timestamps to the first and last used. | |
| 76 // If sync is enabled, at every browser restart, sync will do a match up of all | 87 // If sync is enabled, at every browser restart, sync will do a match up of all |
| 77 // autofill items on the server with all items on the web db. When webdb loads | 88 // autofill items on the server with all items on the web db. When webdb loads |
| 78 // all the items in memory(for sync to process. The method is | 89 // all the items in memory(for sync to process. The method is |
| 79 // |GetAllAutofillEntries|) they will pass through this method for culling. If | 90 // |GetAllAutofillEntries|) they will pass through this method for culling. If |
| 80 // sync finds any of these items were culled it will updates the server AND the | 91 // sync finds any of these items were culled it will updates the server AND the |
| 81 // web db with these new timestamps. However after restart if an autofill item | 92 // web db with these new timestamps. However after restart if an autofill item |
| 82 // exceeds the |kMaxAutofillTimeStamps| it will NOT be written to web db until | 93 // exceeds the |kMaxAutofillTimeStamps| it will NOT be written to web db until |
| 83 // restart. But sync when uploading to the server will only upload this culled | 94 // restart. But sync when uploading to the server will only upload this culled |
| 84 // list. Meaning until restart there will be mis-match in timestamps but | 95 // list. Meaning until restart there will be mis-match in timestamps but |
| 85 // it should correct itself at startup. | 96 // it should correct itself at startup. |
| 86 // Also if sync is not enabled this culling would never take place. | |
| 87 bool AutofillEntry::CullTimeStamps(const std::vector<base::Time>& source, | 97 bool AutofillEntry::CullTimeStamps(const std::vector<base::Time>& source, |
| 88 std::vector<base::Time>* result) { | 98 std::vector<base::Time>* result) { |
| 89 DCHECK(result); | 99 DCHECK(result); |
| 90 DCHECK(&source != result); | 100 DCHECK(&source != result); |
| 91 | 101 |
| 92 // First copy the source to result. | 102 // First copy the source to result. |
| 93 result->clear(); | 103 result->clear(); |
| 94 result->insert(result->begin(), source.begin(), source.end()); | |
| 95 | 104 |
| 96 if (source.size() <= kMaxAutofillTimeStamps) | 105 if (source.size() <= 2) { |
| 106 result->insert(result->begin(), source.begin(), source.end()); | |
| 97 return false; | 107 return false; |
| 108 } | |
|
Ilya Sherman
2012/03/19 21:12:51
nit: Please leave a blank line after this if-stmt,
GeorgeY
2012/03/20 20:47:58
Done.
| |
| 109 result->push_back(source.front()); | |
| 110 result->push_back(source.back()); | |
| 98 | 111 |
| 99 VLOG(1) << "Culling timestamps. Current count is : " << source.size(); | 112 DVLOG(1) << "Culling timestamps. Current count is : " << source.size(); |
| 100 | |
| 101 // Regular sort does ascending order. So we pass in a comparator function. | |
| 102 partial_sort(result->begin(), result->begin() + kMaxAutofillTimeStamps, | |
| 103 result->end(), std::greater<base::Time>()); | |
| 104 | |
| 105 result->erase(result->begin() + kMaxAutofillTimeStamps, result->end()); | |
| 106 | 113 |
| 107 return true; | 114 return true; |
| 108 } | 115 } |
| OLD | NEW |