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

Unified Diff: chrome/browser/extensions/activity_log/counting_policy.cc

Issue 23980002: Activity Log: allow searching by day (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed error from last rebase Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/activity_log/counting_policy.cc
diff --git a/chrome/browser/extensions/activity_log/counting_policy.cc b/chrome/browser/extensions/activity_log/counting_policy.cc
index f5998942230d3669874c087ac00aeaf06ca121a5..7d5702b4c8decc305385abf92b32acf8a6ca4d19 100644
--- a/chrome/browser/extensions/activity_log/counting_policy.cc
+++ b/chrome/browser/extensions/activity_log/counting_policy.cc
@@ -379,7 +379,8 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
const Action::ActionType type,
const std::string& api_name,
const std::string& page_url,
- const std::string& arg_url) {
+ const std::string& arg_url,
+ const int days_ago) {
// Ensure data is flushed to the database first so that we query over all
// data.
activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
@@ -408,12 +409,17 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
where_str += where_next + "page_url LIKE ?";
where_next = " AND ";
}
- if (!arg_url.empty())
+ if (!arg_url.empty()) {
where_str += where_next + "arg_url LIKE ?";
+ where_next = " AND ";
+ }
+ if (days_ago >= 0)
+ where_str += where_next + "time BETWEEN ? AND ?";
+
std::string query_str = base::StringPrintf(
"SELECT extension_id,time, action_type, api_name, args, page_url,"
- "page_title, arg_url, other, count FROM %s %s %s ORDER BY time DESC "
- "LIMIT 300",
+ "page_title, arg_url, other, count FROM %s %s %s ORDER BY count DESC,"
+ " time DESC LIMIT 300",
kReadViewName,
where_str.empty() ? "" : "WHERE",
where_str.c_str());
@@ -429,6 +435,13 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
query.BindString(++i, page_url + "%");
if (!arg_url.empty())
query.BindString(++i, arg_url + "%");
+ if (days_ago >= 0) {
+ int64 early_bound;
+ int64 late_bound;
+ Util::ComputeDatabaseTimeBounds(Now(), days_ago, &early_bound, &late_bound);
+ query.BindInt64(++i, early_bound);
+ query.BindInt64(++i, late_bound);
+ }
// Execute the query and get results.
while (query.is_valid() && query.Step()) {
@@ -466,79 +479,6 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
return actions.Pass();
}
-scoped_ptr<Action::ActionVector> CountingPolicy::DoReadData(
- const std::string& extension_id,
- const int days_ago) {
- // Ensure data is flushed to the database first so that we query over all
- // data.
- activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
-
- DCHECK_GE(days_ago, 0);
- scoped_ptr<Action::ActionVector> actions(new Action::ActionVector());
-
- sql::Connection* db = GetDatabaseConnection();
- if (!db) {
- return actions.Pass();
- }
-
- int64 early_bound;
- int64 late_bound;
- Util::ComputeDatabaseTimeBounds(Now(), days_ago, &early_bound, &late_bound);
- std::string query_str = base::StringPrintf(
- "SELECT time, action_type, api_name, args, page_url, page_title, "
- "arg_url, other, count "
- "FROM %s WHERE extension_id=? AND time>? AND time<=? "
- "ORDER BY time DESC",
- kReadViewName);
- sql::Statement query(db->GetCachedStatement(SQL_FROM_HERE,
- query_str.c_str()));
- query.BindString(0, extension_id);
- query.BindInt64(1, early_bound);
- query.BindInt64(2, late_bound);
-
- while (query.is_valid() && query.Step()) {
- scoped_refptr<Action> action =
- new Action(extension_id,
- base::Time::FromInternalValue(query.ColumnInt64(0)),
- static_cast<Action::ActionType>(query.ColumnInt(1)),
- query.ColumnString(2));
-
- if (query.ColumnType(3) != sql::COLUMN_TYPE_NULL) {
- scoped_ptr<Value> parsed_value(
- base::JSONReader::Read(query.ColumnString(3)));
- if (parsed_value && parsed_value->IsType(Value::TYPE_LIST)) {
- action->set_args(
- make_scoped_ptr(static_cast<ListValue*>(parsed_value.release())));
- } else {
- LOG(WARNING) << "Unable to parse args: '" << query.ColumnString(3)
- << "'";
- }
- }
-
- action->ParsePageUrl(query.ColumnString(4));
- action->set_page_title(query.ColumnString(5));
- action->ParseArgUrl(query.ColumnString(6));
-
- if (query.ColumnType(7) != sql::COLUMN_TYPE_NULL) {
- scoped_ptr<Value> parsed_value(
- base::JSONReader::Read(query.ColumnString(7)));
- if (parsed_value && parsed_value->IsType(Value::TYPE_DICTIONARY)) {
- action->set_other(make_scoped_ptr(
- static_cast<DictionaryValue*>(parsed_value.release())));
- } else {
- LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7)
- << "'";
- }
- }
-
- action->set_count(query.ColumnInt(8));
-
- actions->push_back(action);
- }
-
- return actions.Pass();
-}
-
void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
sql::Connection* db = GetDatabaseConnection();
if (!db) {
@@ -656,26 +596,13 @@ void CountingPolicy::DoDeleteDatabase() {
}
}
-void CountingPolicy::ReadData(
- const std::string& extension_id,
- const int day,
- const base::Callback<void(scoped_ptr<Action::ActionVector>)>& callback) {
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::DB,
- FROM_HERE,
- base::Bind(&CountingPolicy::DoReadData,
- base::Unretained(this),
- extension_id,
- day),
- callback);
-}
-
void CountingPolicy::ReadFilteredData(
const std::string& extension_id,
const Action::ActionType type,
const std::string& api_name,
const std::string& page_url,
const std::string& arg_url,
+ const int days_ago,
const base::Callback
<void(scoped_ptr<Action::ActionVector>)>& callback) {
BrowserThread::PostTaskAndReplyWithResult(
@@ -687,7 +614,8 @@ void CountingPolicy::ReadFilteredData(
type,
api_name,
page_url,
- arg_url),
+ arg_url,
+ days_ago),
callback);
}

Powered by Google App Engine
This is Rietveld 408576698