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

Side by Side Diff: components/password_manager/core/browser/statistics_table.cc

Issue 2552263002: Pass InteractionStats by value (Closed)
Patch Set: ={} Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/password_manager/core/browser/statistics_table.h" 5 #include "components/password_manager/core/browser/statistics_table.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 19 matching lines...) Expand all
30 InteractionsStats::InteractionsStats() = default; 30 InteractionsStats::InteractionsStats() = default;
31 31
32 bool operator==(const InteractionsStats& lhs, const InteractionsStats& rhs) { 32 bool operator==(const InteractionsStats& lhs, const InteractionsStats& rhs) {
33 return lhs.origin_domain == rhs.origin_domain && 33 return lhs.origin_domain == rhs.origin_domain &&
34 lhs.username_value == rhs.username_value && 34 lhs.username_value == rhs.username_value &&
35 lhs.dismissal_count == rhs.dismissal_count && 35 lhs.dismissal_count == rhs.dismissal_count &&
36 lhs.update_time == rhs.update_time; 36 lhs.update_time == rhs.update_time;
37 } 37 }
38 38
39 const InteractionsStats* FindStatsByUsername( 39 const InteractionsStats* FindStatsByUsername(
40 const std::vector<const InteractionsStats*>& stats, 40 const std::vector<InteractionsStats>& stats,
41 const base::string16& username) { 41 const base::string16& username) {
42 auto it = std::find_if(stats.begin(), stats.end(), 42 auto it = std::find_if(stats.begin(), stats.end(),
43 [&username](const InteractionsStats* element) { 43 [&username](const InteractionsStats& element) {
44 return username == element->username_value; 44 return username == element.username_value;
45 }); 45 });
46 return it == stats.end() ? nullptr : *it; 46 return it == stats.end() ? nullptr : &*it;
47 } 47 }
48 48
49 StatisticsTable::StatisticsTable() : db_(nullptr) { 49 StatisticsTable::StatisticsTable() : db_(nullptr) {
50 } 50 }
51 51
52 StatisticsTable::~StatisticsTable() = default; 52 StatisticsTable::~StatisticsTable() = default;
53 53
54 void StatisticsTable::Init(sql::Connection* db) { 54 void StatisticsTable::Init(sql::Connection* db) {
55 db_ = db; 55 db_ = db;
56 } 56 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool StatisticsTable::RemoveRow(const GURL& domain) { 99 bool StatisticsTable::RemoveRow(const GURL& domain) {
100 if (!domain.is_valid()) 100 if (!domain.is_valid())
101 return false; 101 return false;
102 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, 102 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE,
103 "DELETE FROM stats WHERE " 103 "DELETE FROM stats WHERE "
104 "origin_domain = ? ")); 104 "origin_domain = ? "));
105 s.BindString(0, domain.spec()); 105 s.BindString(0, domain.spec());
106 return s.Run(); 106 return s.Run();
107 } 107 }
108 108
109 std::vector<std::unique_ptr<InteractionsStats>> StatisticsTable::GetRows( 109 std::vector<InteractionsStats> StatisticsTable::GetRows(const GURL& domain) {
110 const GURL& domain) {
111 if (!domain.is_valid()) 110 if (!domain.is_valid())
112 return std::vector<std::unique_ptr<InteractionsStats>>(); 111 return std::vector<InteractionsStats>();
113 const char query[] = 112 const char query[] =
114 "SELECT origin_domain, username_value, " 113 "SELECT origin_domain, username_value, "
115 "dismissal_count, update_time FROM stats WHERE origin_domain == ?"; 114 "dismissal_count, update_time FROM stats WHERE origin_domain == ?";
116 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, query)); 115 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, query));
117 s.BindString(0, domain.spec()); 116 s.BindString(0, domain.spec());
118 std::vector<std::unique_ptr<InteractionsStats>> result; 117 std::vector<InteractionsStats> result;
119 while (s.Step()) { 118 while (s.Step()) {
120 result.push_back(base::WrapUnique(new InteractionsStats)); 119 result.push_back(InteractionsStats());
121 result.back()->origin_domain = GURL(s.ColumnString(COLUMN_ORIGIN_DOMAIN)); 120 result.back().origin_domain = GURL(s.ColumnString(COLUMN_ORIGIN_DOMAIN));
122 result.back()->username_value = s.ColumnString16(COLUMN_USERNAME); 121 result.back().username_value = s.ColumnString16(COLUMN_USERNAME);
123 result.back()->dismissal_count = s.ColumnInt(COLUMN_DISMISSALS); 122 result.back().dismissal_count = s.ColumnInt(COLUMN_DISMISSALS);
124 result.back()->update_time = 123 result.back().update_time =
125 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE)); 124 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE));
126 } 125 }
127 return result; 126 return result;
128 } 127 }
129 128
130 bool StatisticsTable::RemoveStatsByOriginAndTime( 129 bool StatisticsTable::RemoveStatsByOriginAndTime(
131 const base::Callback<bool(const GURL&)>& origin_filter, 130 const base::Callback<bool(const GURL&)>& origin_filter,
132 base::Time delete_begin, 131 base::Time delete_begin,
133 base::Time delete_end) { 132 base::Time delete_end) {
134 if (delete_end.is_null()) 133 if (delete_end.is_null())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 origin_delete_statement.BindString(0, origin); 170 origin_delete_statement.BindString(0, origin);
172 origin_delete_statement.BindInt64(1, delete_begin.ToInternalValue()); 171 origin_delete_statement.BindInt64(1, delete_begin.ToInternalValue());
173 origin_delete_statement.BindInt64(2, delete_end.ToInternalValue()); 172 origin_delete_statement.BindInt64(2, delete_end.ToInternalValue());
174 success = success && origin_delete_statement.Run(); 173 success = success && origin_delete_statement.Run();
175 } 174 }
176 175
177 return success; 176 return success;
178 } 177 }
179 178
180 } // namespace password_manager 179 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698