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

Side by Side Diff: chrome/browser/webdata/autofill_entry.cc

Issue 9585020: Cull autofill entries older than 60 days. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adressed comments Created 8 years, 9 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) 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 4
5 #include "chrome/browser/webdata/autofill_entry.h"
6
5 #include <algorithm> 7 #include <algorithm>
6 #include <set> 8 #include <set>
7 9
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "chrome/browser/webdata/autofill_entry.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 12
13 namespace {
14
15 // The period after which Autofill entries should expire in days.
16 const int64 kExpirationPeriodInDays = 60;
17
18 } // namespace
19
12 AutofillKey::AutofillKey() {} 20 AutofillKey::AutofillKey() {}
13 21
14 AutofillKey::AutofillKey(const string16& name, const string16& value) 22 AutofillKey::AutofillKey(const string16& name, const string16& value)
15 : name_(name), 23 : name_(name),
16 value_(value) { 24 value_(value) {
17 } 25 }
18 26
19 AutofillKey::AutofillKey(const char* name, const char* value) 27 AutofillKey::AutofillKey(const char* name, const char* value)
20 : name_(UTF8ToUTF16(name)), 28 : name_(UTF8ToUTF16(name)),
21 value_(UTF8ToUTF16(value)) { 29 value_(UTF8ToUTF16(value)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return false; 73 return false;
66 } 74 }
67 75
68 return true; 76 return true;
69 } 77 }
70 78
71 bool AutofillEntry::operator<(const AutofillEntry& entry) const { 79 bool AutofillEntry::operator<(const AutofillEntry& entry) const {
72 return key_ < entry.key(); 80 return key_ < entry.key();
73 } 81 }
74 82
75 // Culls the list of timestamps to the most recent |kMaxAutofillTimeStamps|. 83 bool AutofillEntry::IsExpired() const {
84 base::Time time = ExpirationTime();
85 DCHECK(!timestamps_.empty());
86 return (timestamps_.empty() || timestamps_.back() < time);
87 }
88
89 // static
90 base::Time AutofillEntry::ExpirationTime() {
91 return base::Time::Now() - base::TimeDelta::FromDays(kExpirationPeriodInDays);
92 }
93
94 // 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 95 // 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 96 // 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 97 // all the items in memory(for sync to process. The method is
79 // |GetAllAutofillEntries|) they will pass through this method for culling. If 98 // |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 99 // 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 100 // 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 101 // 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 102 // 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 103 // list. Meaning until restart there will be mis-match in timestamps but
85 // it should correct itself at startup. 104 // 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, 105 bool AutofillEntry::CullTimeStamps(const std::vector<base::Time>& source,
88 std::vector<base::Time>* result) { 106 std::vector<base::Time>* result) {
89 DCHECK(result); 107 DCHECK(result);
90 DCHECK(&source != result); 108 DCHECK(&source != result);
91 109
92 // First copy the source to result. 110 // First copy the source to result.
93 result->clear(); 111 result->clear();
94 result->insert(result->begin(), source.begin(), source.end());
95 112
96 if (source.size() <= kMaxAutofillTimeStamps) 113 if (source.size() <= 2) {
114 result->insert(result->begin(), source.begin(), source.end());
97 return false; 115 return false;
116 }
98 117
99 VLOG(1) << "Culling timestamps. Current count is : " << source.size(); 118 result->push_back(source.front());
119 result->push_back(source.back());
100 120
101 // Regular sort does ascending order. So we pass in a comparator function. 121 DVLOG(1) << "Culling timestamps. Current count is : " << source.size();
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 122
107 return true; 123 return true;
108 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698