| Index: chrome/browser/extensions/blocked_actions.cc
|
| diff --git a/chrome/browser/extensions/blocked_actions.cc b/chrome/browser/extensions/blocked_actions.cc
|
| index 54be11a6316843e811a3d70ba7930250c109f77f..756d9e8d5394abcbe5cdefc539d93a42d7b9a6de 100644
|
| --- a/chrome/browser/extensions/blocked_actions.cc
|
| +++ b/chrome/browser/extensions/blocked_actions.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include <string>
|
| #include "base/logging.h"
|
| +#include "base/stringprintf.h"
|
| #include "chrome/browser/extensions/blocked_actions.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| @@ -12,37 +13,59 @@ using content::BrowserThread;
|
| namespace extensions {
|
|
|
| const char* BlockedAction::kTableName = "activitylog_blocked";
|
| -const char* BlockedAction::kTableStructure = "("
|
| +const char* BlockedAction::kTableBasicFields =
|
| "extension_id LONGVARCHAR NOT NULL, "
|
| - "time INTEGER NOT NULL, "
|
| - "blocked_action LONGVARCHAR NOT NULL, "
|
| - "reason LONGVARCHAR NOT NULL, "
|
| - "extra LONGVARCHAR NOT NULL)";
|
| + "time INTEGER NOT NULL";
|
| +const char* BlockedAction::kTableContentFields[] =
|
| + {"api_call", "args", "reason", "extra"};
|
|
|
| BlockedAction::BlockedAction(const std::string& extension_id,
|
| const base::Time& time,
|
| - const std::string& blocked_action,
|
| + const std::string& api_call,
|
| + const std::string& args,
|
| const std::string& reason,
|
| const std::string& extra)
|
| : extension_id_(extension_id),
|
| time_(time),
|
| - blocked_action_(blocked_action),
|
| + api_call_(api_call),
|
| + args_(args),
|
| reason_(reason),
|
| extra_(extra) { }
|
|
|
| BlockedAction::~BlockedAction() {
|
| }
|
|
|
| +// static
|
| +bool BlockedAction::InitializeTable(sql::Connection* db) {
|
| + // The original table schema was different than the existing one.
|
| + // Sqlite doesn't let you delete or modify existing columns, so we drop it.
|
| + // The old version can be identified because it had a field named
|
| + // blocked_action. Any data loss incurred here doesn't matter since these
|
| + // fields existed before we started using the AL for anything.
|
| + if (db->DoesColumnExist(kTableName, "blocked_action")) {
|
| + std::string drop_table = base::StringPrintf("DROP TABLE %s", kTableName);
|
| + if (!db->Execute(drop_table.c_str()))
|
| + return false;
|
| + }
|
| + return InitializeTableInternal(db,
|
| + kTableName,
|
| + kTableBasicFields,
|
| + kTableContentFields,
|
| + arraysize(kTableContentFields));
|
| +}
|
| +
|
| void BlockedAction::Record(sql::Connection* db) {
|
| std::string sql_str = "INSERT INTO " + std::string(kTableName)
|
| - + " (extension_id, time, blocked_action, reason, extra) VALUES (?,?,?,?,?)";
|
| + + " (extension_id, time, api_call, args, reason, extra)"
|
| + " VALUES (?,?,?,?,?,?)";
|
| sql::Statement statement(db->GetCachedStatement(
|
| sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
|
| statement.BindString(0, extension_id_);
|
| statement.BindInt64(1, time().ToInternalValue());
|
| - statement.BindString(2, blocked_action_);
|
| - statement.BindString(3, reason_);
|
| - statement.BindString(4, extra_);
|
| + statement.BindString(2, api_call_);
|
| + statement.BindString(3, args_);
|
| + statement.BindString(4, reason_);
|
| + statement.BindString(5, extra_);
|
| if (!statement.Run())
|
| LOG(ERROR) << "Activity log database I/O failed: " << sql_str;
|
| }
|
| @@ -54,7 +77,7 @@ std::string BlockedAction::PrettyPrintFori18n() {
|
|
|
| std::string BlockedAction::PrettyPrintForDebug() {
|
| // TODO(felt): implement this for real when the UI is redesigned.
|
| - return "ID: " + extension_id_ + ", blocked action " + blocked_action_ +
|
| + return "ID: " + extension_id_ + ", blocked action " + api_call_ +
|
| ", reason: " + reason_;
|
| }
|
|
|
|
|