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

Unified Diff: chrome/browser/extensions/activity_log/fullstream_ui_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/fullstream_ui_policy.cc
diff --git a/chrome/browser/extensions/activity_log/fullstream_ui_policy.cc b/chrome/browser/extensions/activity_log/fullstream_ui_policy.cc
index 1fd12b10d7f307d010403d0a3c4162e169353b85..84f8a9ea6564562867f2329b0406ba0c679d58cd 100644
--- a/chrome/browser/extensions/activity_log/fullstream_ui_policy.cc
+++ b/chrome/browser/extensions/activity_log/fullstream_ui_policy.cc
@@ -123,7 +123,8 @@ scoped_ptr<Action::ActionVector> FullStreamUIPolicy::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);
@@ -156,6 +157,8 @@ scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData(
if (!arg_url.empty()) {
where_str += where_next + "arg_url LIKE ?";
}
+ 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 FROM %s %s %s ORDER BY time DESC LIMIT 300",
@@ -174,6 +177,13 @@ scoped_ptr<Action::ActionVector> FullStreamUIPolicy::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()) {
@@ -210,75 +220,6 @@ scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData(
return actions.Pass();
}
-scoped_ptr<Action::ActionVector> FullStreamUIPolicy::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 "
- "FROM %s WHERE extension_id=? AND time>? AND time<=? "
- "ORDER BY time DESC",
- kTableName);
- 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)
- << "'";
- }
- }
-
- actions->push_back(action);
- }
- return actions.Pass();
-}
-
void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
sql::Connection* db = GetDatabaseConnection();
if (!db) {
@@ -383,27 +324,13 @@ void FullStreamUIPolicy::Close() {
ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
}
-// Get data as a set of key-value pairs. The keys are policy-specific.
-void FullStreamUIPolicy::ReadData(
- const std::string& extension_id,
- const int day,
- const Callback<void(scoped_ptr<Action::ActionVector>)>& callback) {
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::DB,
- FROM_HERE,
- base::Bind(&FullStreamUIPolicy::DoReadData,
- base::Unretained(this),
- extension_id,
- day),
- callback);
-}
-
void FullStreamUIPolicy::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(
@@ -415,7 +342,8 @@ void FullStreamUIPolicy::ReadFilteredData(
type,
api_name,
page_url,
- arg_url),
+ arg_url,
+ days_ago),
callback);
}

Powered by Google App Engine
This is Rietveld 408576698