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

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

Issue 19234003: Extension activity log database refactoring (step 2) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 5 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 554d201801c3f9af62c43f46fd876cd4f1fca38f..23ee4de90dd22076b0993fd71cecf546cc66a476 100644
--- a/chrome/browser/extensions/activity_log/fullstream_ui_policy.cc
+++ b/chrome/browser/extensions/activity_log/fullstream_ui_policy.cc
@@ -6,6 +6,7 @@
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/strings/string16.h"
+#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/activity_log/activity_database.h"
#include "chrome/browser/extensions/activity_log/api_actions.h"
#include "chrome/browser/extensions/activity_log/blocked_actions.h"
@@ -32,10 +33,26 @@ const char kKeyDomainAction[] = "fsuip.domact";
const char kKeyURLTitle[] = "fsuip.urltitle";
const char kKeyDetailsString[] = "fsuip.details";
+// Obsolete database tables: these should be dropped from the database if
+// found.
+const char* kObsoleteTables[] = {"activitylog_apis", "activitylog_blocked",
+ "activitylog_urls"};
+
} // namespace
namespace extensions {
+const char* FullStreamUIPolicy::kTableName = "activitylog_full";
+const char* FullStreamUIPolicy::kTableContentFields[] = {
+ "extension_id", "time", "action_type", "api_name", "args", "page_url",
+ "arg_url", "other"
+};
+const char* FullStreamUIPolicy::kTableFieldTypes[] = {
+ "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR", "LONGVARCHAR",
+ "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR"
+};
+const int FullStreamUIPolicy::kTableFieldCount = arraysize(kTableContentFields);
+
// TODO(dbabic) This would be a fine error handler for all sql-based policies,
felt 2013/07/16 06:44:03 can you delete this todo? At this point it seems t
mvrable 2013/07/16 18:12:35 Done.
// so it would make sense to introduce another class in the hierarchy,
// SQLiteBasedPolicy as a super class of FullStreamUIPolicy and move this
@@ -50,14 +67,24 @@ FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile)
}
bool FullStreamUIPolicy::OnDatabaseInit(sql::Connection* db) {
- if (!DOMAction::InitializeTable(db))
- return false;
- if (!APIAction::InitializeTable(db))
- return false;
- if (!BlockedAction::InitializeTable(db))
- return false;
-
- return true;
+ // Drop old database tables.
+ for (size_t i = 0; i < arraysize(kObsoleteTables); i++) {
+ const char* table_name = kObsoleteTables[i];
+ if (db->DoesTableExist(table_name)) {
+ std::string drop_statement =
+ base::StringPrintf("DROP TABLE %s", table_name);
+ if (!db->Execute(drop_statement.c_str())) {
+ return false;
+ }
+ }
+ }
+
+ // Create the unified activity log entry table.
+ return ActivityDatabase::InitializeTable(db,
+ kTableName,
+ kTableContentFields,
+ kTableFieldTypes,
+ arraysize(kTableContentFields));
}
void FullStreamUIPolicy::OnDatabaseClose() {
@@ -101,7 +128,18 @@ std::string FullStreamUIPolicy::GetKey(ActivityLogPolicy::KeyType key_ty) const
}
}
-std::string FullStreamUIPolicy::ProcessArguments(
+scoped_ptr<base::ListValue> FullStreamUIPolicy::ProcessArguments(
+ ActionType action_type,
+ const std::string& name,
+ const base::ListValue* args) const {
+ if (args) {
felt 2013/07/16 06:44:03 nit: don't need { }
mvrable 2013/07/16 18:12:35 Done.
+ return make_scoped_ptr(args->DeepCopy());
+ } else {
+ return scoped_ptr<base::ListValue>();
+ }
+}
+
+std::string FullStreamUIPolicy::JoinArguments(
ActionType action_type,
const std::string& name,
const base::ListValue* args) const {
@@ -136,9 +174,11 @@ void FullStreamUIPolicy::ProcessAction(
const std::string& extension_id,
const std::string& name,
const GURL& url_param,
- const base::ListValue* args,
+ const base::ListValue* args_in,
const DictionaryValue* details) {
- std::string concatenated_args = ProcessArguments(action_type, name, args);
+ scoped_ptr<base::ListValue> args =
+ ProcessArguments(action_type, name, args_in);
+ std::string concatenated_args = JoinArguments(action_type, name, args.get());
const Time now = Time::Now();
scoped_refptr<Action> action;
std::string extra;
@@ -154,6 +194,7 @@ void FullStreamUIPolicy::ProcessAction(
APIAction::CALL,
name,
concatenated_args,
+ *args,
extra);
break;
}
@@ -164,6 +205,7 @@ void FullStreamUIPolicy::ProcessAction(
APIAction::EVENT_CALLBACK,
name,
concatenated_args,
+ *args,
extra);
break;
}

Powered by Google App Engine
This is Rietveld 408576698