Commit a3590560 authored by felt@chromium.org's avatar felt@chromium.org

Added memory limit for chrome.activityLogPrivate returned results

The Activity Log will only send a max of 300 rows per lookup. This should be completely satisfactory for the Watchdog app -- we can't display more than 300 rows of data in any meaninful way anyway. This is also below the IPC memory boundary.

BUG=241672

Review URL: https://chromiumcodereview.appspot.com/23874008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221406 0039d316-1c4b-4281-b951-d872f2087c98
parent ec7dfef2
...@@ -442,7 +442,8 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData( ...@@ -442,7 +442,8 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
where_str += where_next + "arg_url LIKE ?"; where_str += where_next + "arg_url LIKE ?";
std::string query_str = base::StringPrintf( std::string query_str = base::StringPrintf(
"SELECT extension_id,time, action_type, api_name, args, page_url," "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", "page_title, arg_url, other, count FROM %s WHERE %s ORDER BY count DESC "
"LIMIT 300",
kReadViewName, kReadViewName,
where_str.c_str()); where_str.c_str());
sql::Statement query(db->GetUniqueStatement(query_str.c_str())); sql::Statement query(db->GetUniqueStatement(query_str.c_str()));
......
...@@ -186,6 +186,11 @@ class CountingPolicyTest : public testing::Test { ...@@ -186,6 +186,11 @@ class CountingPolicyTest : public testing::Test {
ASSERT_EQ(2, static_cast<int>(i->size())); ASSERT_EQ(2, static_cast<int>(i->size()));
} }
static void RetrieveActions_FetchFilteredActions300(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
ASSERT_EQ(300, static_cast<int>(i->size()));
}
static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) {
scoped_refptr<Action> last = i->front(); scoped_refptr<Action> last = i->front();
std::string args = std::string args =
...@@ -782,6 +787,31 @@ TEST_F(CountingPolicyTest, EarlyFlush) { ...@@ -782,6 +787,31 @@ TEST_F(CountingPolicyTest, EarlyFlush) {
policy->Close(); policy->Close();
} }
TEST_F(CountingPolicyTest, CapReturns) {
CountingPolicy* policy = new CountingPolicy(profile_.get());
for (int i = 0; i < 305; i++) {
scoped_refptr<Action> action =
new Action("punky",
base::Time::Now(),
Action::ACTION_API_CALL,
base::StringPrintf("apicall_%d", i));
policy->ProcessAction(action);
}
policy->Flush();
CheckReadFilteredData(
policy,
"punky",
Action::ACTION_ANY,
"",
"",
"",
base::Bind(
&CountingPolicyTest::RetrieveActions_FetchFilteredActions300));
policy->Close();
}
TEST_F(CountingPolicyTest, RemoveAllURLs) { TEST_F(CountingPolicyTest, RemoveAllURLs) {
ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); ActivityLogPolicy* policy = new CountingPolicy(profile_.get());
......
...@@ -158,7 +158,7 @@ scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData( ...@@ -158,7 +158,7 @@ scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData(
} }
std::string query_str = base::StringPrintf( std::string query_str = base::StringPrintf(
"SELECT extension_id,time,action_type,api_name,args,page_url,page_title," "SELECT extension_id,time,action_type,api_name,args,page_url,page_title,"
"arg_url,other FROM %s WHERE %s ORDER BY time DESC", "arg_url,other FROM %s WHERE %s ORDER BY time DESC LIMIT 300",
kTableName, kTableName,
where_str.c_str()); where_str.c_str());
sql::Statement query(db->GetUniqueStatement(query_str.c_str())); sql::Statement query(db->GetUniqueStatement(query_str.c_str()));
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/simple_test_clock.h" #include "base/test/simple_test_clock.h"
#include "chrome/browser/extensions/activity_log/activity_log.h" #include "chrome/browser/extensions/activity_log/activity_log.h"
...@@ -156,6 +157,11 @@ class FullStreamUIPolicyTest : public testing::Test { ...@@ -156,6 +157,11 @@ class FullStreamUIPolicyTest : public testing::Test {
ASSERT_EQ(2, static_cast<int>(i->size())); ASSERT_EQ(2, static_cast<int>(i->size()));
} }
static void RetrieveActions_FetchFilteredActions300(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
ASSERT_EQ(300, static_cast<int>(i->size()));
}
static void Arguments_Present(scoped_ptr<Action::ActionVector> i) { static void Arguments_Present(scoped_ptr<Action::ActionVector> i) {
scoped_refptr<Action> last = i->front(); scoped_refptr<Action> last = i->front();
std::string args = std::string args =
...@@ -642,4 +648,29 @@ TEST_F(FullStreamUIPolicyTest, RemoveSpecificURLs) { ...@@ -642,4 +648,29 @@ TEST_F(FullStreamUIPolicyTest, RemoveSpecificURLs) {
policy->Close(); policy->Close();
} }
TEST_F(FullStreamUIPolicyTest, CapReturns) {
FullStreamUIPolicy* policy = new FullStreamUIPolicy(profile_.get());
for (int i = 0; i < 305; i++) {
scoped_refptr<Action> action =
new Action("punky",
base::Time::Now(),
Action::ACTION_API_CALL,
base::StringPrintf("apicall_%d", i));
policy->ProcessAction(action);
}
policy->Flush();
CheckReadFilteredData(
policy,
"punky",
Action::ACTION_ANY,
"",
"",
"",
base::Bind(
&FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions300));
policy->Close();
}
} // namespace extensions } // namespace extensions
...@@ -163,12 +163,8 @@ void ActivityLogPrivateGetExtensionActivitiesFunction::OnLookupCompleted( ...@@ -163,12 +163,8 @@ void ActivityLogPrivateGetExtensionActivitiesFunction::OnLookupCompleted(
} }
// Populate the return object. // Populate the return object.
// TODO(felt): Implement paging. Right now max_time and more_results are
// placeholder values.
scoped_ptr<ActivityResultSet> result_set(new ActivityResultSet); scoped_ptr<ActivityResultSet> result_set(new ActivityResultSet);
result_set->activities = result_arr; result_set->activities = result_arr;
result_set->max_time = scoped_ptr<int>(new int(0));
result_set->more_results = false;
results_ = activity_log_private::GetExtensionActivities::Results::Create( results_ = activity_log_private::GetExtensionActivities::Results::Create(
*result_set); *result_set);
......
...@@ -41,9 +41,7 @@ ...@@ -41,9 +41,7 @@
"type": "object", "type": "object",
"description": "This holds the results of a lookup, the filter of the lookup, the time of the lookup, and whether there are more results that match.", "description": "This holds the results of a lookup, the filter of the lookup, the time of the lookup, and whether there are more results that match.",
"properties": { "properties": {
"activities": {"type": "array", "items": {"$ref": "ExtensionActivity"}}, "activities": {"type": "array", "items": {"$ref": "ExtensionActivity"}}
"maxTime": {"type": "integer", "optional": true},
"moreResults": {"type": "boolean"}
} }
} }
], ],
...@@ -58,12 +56,6 @@ ...@@ -58,12 +56,6 @@
"$ref": "Filter", "$ref": "Filter",
"description": "Fill out the fields that you want to search for in the database." "description": "Fill out the fields that you want to search for in the database."
}, },
{
"name": "maxTime",
"type": "integer",
"optional": true,
"description": "Specify this if you want results that weren't available in the first page."
},
{ {
"name": "callback", "name": "callback",
"type": "function", "type": "function",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment