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

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: Fixed clang 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 #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
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::LastAccessOlder(base::Time time) const {
76 if (timestamps_.empty() || timestamps_.back() < time)
Ilya Sherman 2012/03/15 21:00:41 nit: Can we DCHECK(!timestamps_.empty()), or is th
GeorgeY 2012/03/17 00:36:16 Done.
77 return true;
78 return false;
Ilya Sherman 2012/03/15 21:00:41 nit: This implementation can be collapsed to "retu
GeorgeY 2012/03/17 00:36:16 Done.
79 }
80
81
82 // 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 83 // 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 84 // 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 85 // all the items in memory(for sync to process. The method is
79 // |GetAllAutofillEntries|) they will pass through this method for culling. If 86 // |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 87 // 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 88 // 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 89 // 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 90 // 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 91 // list. Meaning until restart there will be mis-match in timestamps but
85 // it should correct itself at startup. 92 // it should correct itself at startup.
86 // Also if sync is not enabled this culling would never take place. 93 // Also if sync is not enabled this culling would never take place.
87 bool AutofillEntry::CullTimeStamps(const std::vector<base::Time>& source, 94 bool AutofillEntry::CullTimeStamps(const std::vector<base::Time>& source,
88 std::vector<base::Time>* result) { 95 std::vector<base::Time>* result) {
89 DCHECK(result); 96 DCHECK(result);
90 DCHECK(&source != result); 97 DCHECK(&source != result);
91 98
92 // First copy the source to result. 99 // First copy the source to result.
93 result->clear(); 100 result->clear();
94 result->insert(result->begin(), source.begin(), source.end());
95 101
96 if (source.size() <= kMaxAutofillTimeStamps) 102 if (source.size() <= 2) {
103 result->insert(result->begin(), source.begin(), source.end());
97 return false; 104 return false;
105 }
106 result->push_back(source.front());
107 result->push_back(source.back());
Ilya Sherman 2012/03/15 21:00:41 Just to make sure, are the timestamps guaranteed t
GeorgeY 2012/03/17 00:36:16 Done.
98 108
99 VLOG(1) << "Culling timestamps. Current count is : " << source.size(); 109 VLOG(1) << "Culling timestamps. Current count is : " << source.size();
Ilya Sherman 2012/03/15 21:00:41 nit: DVLOG?
GeorgeY 2012/03/17 00:36:16 Done.
100 110
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
107 return true; 111 return true;
108 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698