| 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 9188b48ad8bd2b69543ae0f190ed5e9a7c60b324..a4c4699efe4681d4235d9e6643aa0b75da842bc5 100644
|
| --- a/chrome/browser/extensions/activity_log/counting_policy.cc
|
| +++ b/chrome/browser/extensions/activity_log/counting_policy.cc
|
| @@ -409,7 +409,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);
|
| @@ -438,8 +439,13 @@ 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 WHERE %s ORDER BY time DESC",
|
| @@ -457,6 +463,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()) {
|
| @@ -494,79 +507,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<CountedAction> action =
|
| - new CountedAction(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) {
|
| @@ -639,26 +579,13 @@ void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
|
| CleanStringTables(db);
|
| }
|
|
|
| -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(
|
| @@ -670,7 +597,8 @@ void CountingPolicy::ReadFilteredData(
|
| type,
|
| api_name,
|
| page_url,
|
| - arg_url),
|
| + arg_url,
|
| + days_ago),
|
| callback);
|
| }
|
|
|
|
|