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" | |
| 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 bool AutofillEntry::HasTimestampsOlder(base::Time time) const { | |
| 76 for (size_t i = 0; i < timestamps_.size(); ++i) | |
|
Ilya Sherman
2012/03/06 08:48:35
nit: The loop body is more than one line, so pleas
GeorgeY
2012/03/09 20:14:24
Done.
| |
| 77 if (timestamps_[i] < time) | |
| 78 return true; | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 bool AutofillEntry::CullExpiredTimeStamps(base::Time expire_before) { | |
| 83 std::vector<base::Time> new_timestamps; | |
| 84 new_timestamps.reserve(timestamps_.size()); | |
| 85 | |
| 86 for (size_t i = 0; i < timestamps_.size(); ++i) { | |
| 87 if (timestamps_[i] >= expire_before) { | |
| 88 new_timestamps.push_back(timestamps_[i]); | |
| 89 } | |
|
Ilya Sherman
2012/03/06 08:48:35
nit: One-line if-stmt, so no need for curlys.
GeorgeY
2012/03/09 20:14:24
Done.
| |
| 90 } | |
| 91 | |
| 92 if (timestamps_.size() == new_timestamps.size()) | |
| 93 return false; | |
| 94 | |
| 95 timestamps_.swap(new_timestamps); | |
| 96 timestamps_culled_ = true; | |
|
Ilya Sherman
2012/03/06 08:48:35
It seems a little odd to me that we're using times
GeorgeY
2012/03/09 20:14:24
Because the original culling just limits the numbe
| |
| 97 return true; | |
| 98 } | |
| 99 | |
| 75 // Culls the list of timestamps to the most recent |kMaxAutofillTimeStamps|. | 100 // Culls the list of timestamps to the most recent |kMaxAutofillTimeStamps|. |
| 76 // If sync is enabled, at every browser restart, sync will do a match up of all | 101 // 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 | 102 // 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 | 103 // all the items in memory(for sync to process. The method is |
| 79 // |GetAllAutofillEntries|) they will pass through this method for culling. If | 104 // |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 | 105 // 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 | 106 // 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 | 107 // 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 | 108 // 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 | 109 // list. Meaning until restart there will be mis-match in timestamps but |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 99 VLOG(1) << "Culling timestamps. Current count is : " << source.size(); | 124 VLOG(1) << "Culling timestamps. Current count is : " << source.size(); |
| 100 | 125 |
| 101 // Regular sort does ascending order. So we pass in a comparator function. | 126 // Regular sort does ascending order. So we pass in a comparator function. |
| 102 partial_sort(result->begin(), result->begin() + kMaxAutofillTimeStamps, | 127 partial_sort(result->begin(), result->begin() + kMaxAutofillTimeStamps, |
| 103 result->end(), std::greater<base::Time>()); | 128 result->end(), std::greater<base::Time>()); |
| 104 | 129 |
| 105 result->erase(result->begin() + kMaxAutofillTimeStamps, result->end()); | 130 result->erase(result->begin() + kMaxAutofillTimeStamps, result->end()); |
| 106 | 131 |
| 107 return true; | 132 return true; |
| 108 } | 133 } |
| OLD | NEW |