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

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: if (!RemoveFormElementForID(pair_id)) 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 // TODO(georgey): add DCHECK(!timestamps_.empty()) after conversion of the db
86 // is complete.
87 return (timestamps_.empty() || timestamps_.back() < time);
88 }
89
90 // static
91 base::Time AutofillEntry::ExpirationTime() {
92 return base::Time::Now() - base::TimeDelta::FromDays(kExpirationPeriodInDays);
93 }
94
95 // 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 96 // 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 97 // 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 98 // all the items in memory(for sync to process. The method is
79 // |GetAllAutofillEntries|) they will pass through this method for culling. If 99 // |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 100 // 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 101 // 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 102 // 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 103 // 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 104 // list. Meaning until restart there will be mis-match in timestamps but
85 // it should correct itself at startup. 105 // 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, 106 bool AutofillEntry::CullTimeStamps(const std::vector<base::Time>& source,
88 std::vector<base::Time>* result) { 107 std::vector<base::Time>* result) {
89 DCHECK(result); 108 DCHECK(result);
90 DCHECK(&source != result); 109 DCHECK(&source != result);
91 110
92 // First copy the source to result. 111 // First copy the source to result.
93 result->clear(); 112 result->clear();
94 result->insert(result->begin(), source.begin(), source.end());
95 113
96 if (source.size() <= kMaxAutofillTimeStamps) 114 if (source.size() <= 2) {
115 result->insert(result->begin(), source.begin(), source.end());
97 return false; 116 return false;
117 }
98 118
99 VLOG(1) << "Culling timestamps. Current count is : " << source.size(); 119 result->push_back(source.front());
120 result->push_back(source.back());
100 121
101 // Regular sort does ascending order. So we pass in a comparator function. 122 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 123
107 return true; 124 return true;
108 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698