| Index: chrome/browser/extensions/activity_log/blocked_actions.cc
|
| diff --git a/chrome/browser/extensions/activity_log/blocked_actions.cc b/chrome/browser/extensions/activity_log/blocked_actions.cc
|
| index e8c7bda8fbff56e2a630bd020c663ee806271c75..3ac47a1dd04179d467fc10c9b222f3f92faea34a 100644
|
| --- a/chrome/browser/extensions/activity_log/blocked_actions.cc
|
| +++ b/chrome/browser/extensions/activity_log/blocked_actions.cc
|
| @@ -2,9 +2,11 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/json/json_string_value_serializer.h"
|
| #include "base/logging.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "chrome/browser/extensions/activity_log/blocked_actions.h"
|
| +#include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| using content::BrowserThread;
|
| @@ -16,12 +18,6 @@ using api::activity_log_private::DomActivityDetail;
|
| using api::activity_log_private::ChromeActivityDetail;
|
| using api::activity_log_private::BlockedChromeActivityDetail;
|
|
|
| -const char* BlockedAction::kTableName = "activitylog_blocked";
|
| -const char* BlockedAction::kTableContentFields[] =
|
| - {"api_call", "args", "reason", "extra"};
|
| -const char* BlockedAction::kTableFieldTypes[] =
|
| - {"LONGVARCHAR", "LONGVARCHAR", "INTEGER", "LONGVARCHAR"};
|
| -
|
| BlockedAction::BlockedAction(const std::string& extension_id,
|
| const base::Time& time,
|
| const std::string& api_call,
|
| @@ -36,15 +32,6 @@ BlockedAction::BlockedAction(const std::string& extension_id,
|
| reason_(reason),
|
| extra_(extra) { }
|
|
|
| -BlockedAction::BlockedAction(const sql::Statement& s)
|
| - : Action(s.ColumnString(0),
|
| - base::Time::FromInternalValue(s.ColumnInt64(1)),
|
| - ExtensionActivity::ACTIVITY_TYPE_BLOCKED_CHROME),
|
| - api_call_(s.ColumnString(2)),
|
| - args_(s.ColumnString(3)),
|
| - reason_(static_cast<Reason>(s.ColumnInt(4))),
|
| - extra_(s.ColumnString(5)) { }
|
| -
|
| BlockedAction::~BlockedAction() {
|
| }
|
|
|
| @@ -65,55 +52,32 @@ scoped_ptr<ExtensionActivity> BlockedAction::ConvertToExtensionActivity() {
|
| return formatted_activity.Pass();
|
| }
|
|
|
| -// 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;
|
| - }
|
| - // We also now use INTEGER instead of VARCHAR for url_action_type.
|
| - if (db->DoesColumnExist(kTableName, "reason")) {
|
| - std::string select = base::StringPrintf(
|
| - "SELECT reason FROM %s ORDER BY rowid LIMIT 1", kTableName);
|
| - sql::Statement statement(db->GetUniqueStatement(select.c_str()));
|
| - if (statement.DeclaredColumnType(0) != sql::COLUMN_TYPE_INTEGER) {
|
| - std::string drop_table = base::StringPrintf("DROP TABLE %s", kTableName);
|
| - if (!db->Execute(drop_table.c_str()))
|
| - return false;
|
| - }
|
| - }
|
| - return InitializeTableInternal(db,
|
| - kTableName,
|
| - kTableContentFields,
|
| - kTableFieldTypes,
|
| - arraysize(kTableContentFields));
|
| -}
|
| -
|
| bool BlockedAction::Record(sql::Connection* db) {
|
| - std::string sql_str = "INSERT INTO " + std::string(kTableName)
|
| - + " (extension_id, time, api_call, args, reason, extra)"
|
| - " VALUES (?,?,?,?,?,?)";
|
| + std::string sql_str =
|
| + "INSERT INTO " + std::string(FullStreamUIPolicy::kTableName) +
|
| + " (extension_id, time, action_type, api_name, args, other) 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, api_call_);
|
| - statement.BindString(3, args_);
|
| - statement.BindInt(4, static_cast<int>(reason_));
|
| - statement.BindString(5, extra_);
|
| + statement.BindInt(2, static_cast<int>(Action::ACTION_API_BLOCKED));
|
| + statement.BindString(3, api_call_);
|
| + statement.BindString(4, args_);
|
| +
|
| + DictionaryValue other;
|
| + other.SetInteger("reason", static_cast<int>(reason_));
|
| + std::string other_string;
|
| + JSONStringValueSerializer other_serializer(&other_string);
|
| + other_serializer.SerializeAndOmitBinaryValues(other);
|
| + statement.BindString(5, other_string);
|
| +
|
| if (!statement.Run()) {
|
| LOG(ERROR) << "Activity log database I/O failed: " << sql_str;
|
| statement.Clear();
|
| return false;
|
| - } else {
|
| - return true;
|
| }
|
| + return true;
|
| }
|
|
|
| std::string BlockedAction::PrintForDebug() {
|
|
|