Index: chrome/browser/extensions/api_actions.cc |
diff --git a/chrome/browser/extensions/api_actions.cc b/chrome/browser/extensions/api_actions.cc |
index 7897696f4a0a554dc708c93ca30aaf85fa6427d7..ebd47258ccea62dc5c9329ce086fd1e4cd9332c9 100644 |
--- a/chrome/browser/extensions/api_actions.cc |
+++ b/chrome/browser/extensions/api_actions.cc |
@@ -13,14 +13,11 @@ using content::BrowserThread; |
namespace extensions { |
const char* APIAction::kTableName = "activitylog_apis"; |
-const char* APIAction::kTableStructure = "(" |
+const char* APIAction::kTableBasicFields = |
"extension_id LONGVARCHAR NOT NULL, " |
- "time INTEGER NOT NULL, " |
- "api_type LONGVARCHAR NOT NULL, " |
- "api_action_type LONGVARCHAR NOT NULL, " |
- "target_type LONGVARCHAR NOT NULL, " |
- "api_call LONGVARCHAR NOT NULL, " |
- "extra LONGVARCHAR NOT NULL)"; |
+ "time INTEGER NOT NULL"; |
+const char* APIAction::kTableContentFields[] = |
+ {"api_type", "api_action_type", "target_type", "api_call", "args", "extra"}; |
APIAction::APIAction(const std::string& extension_id, |
const base::Time& time, |
@@ -28,6 +25,7 @@ APIAction::APIAction(const std::string& extension_id, |
const Verb verb, |
const Target target, |
const std::string& api_call, |
+ const std::string& args, |
const std::string& extra) |
: extension_id_(extension_id), |
time_(time), |
@@ -35,6 +33,7 @@ APIAction::APIAction(const std::string& extension_id, |
verb_(verb), |
target_(target), |
api_call_(api_call), |
+ args_(args), |
extra_(extra) { } |
APIAction::~APIAction() { |
@@ -42,31 +41,17 @@ APIAction::~APIAction() { |
// static |
bool APIAction::InitializeTable(sql::Connection* db) { |
- if (!db->DoesTableExist(kTableName)) { |
- std::string table_creator = base::StringPrintf( |
- "CREATE TABLE %s %s", kTableName, kTableStructure); |
- if (!db->Execute(table_creator.c_str())) |
- return false; |
- } else if (!db->DoesColumnExist(kTableName, "api_type")) { |
- // Old versions of the table lack the api_type column. Add it if |
- // needed, with values defaulting to "CALL". |
- // |
- // TODO(mvrable): Remove this update code once we're fairly certain that |
- // everyone will have converted to the new schema. |
- std::string table_updater = base::StringPrintf( |
- "ALTER TABLE %s ADD COLUMN api_type LONGVARCHAR; " |
- "UPDATE %s SET api_type = 'CALL'", |
- kTableName, kTableName); |
- if (!db->Execute(table_updater.c_str())) |
- return false; |
- } |
- return true; |
+ return InitializeTableInternal(db, |
+ kTableName, |
+ kTableBasicFields, |
+ kTableContentFields, |
+ arraysize(kTableContentFields)); |
} |
void APIAction::Record(sql::Connection* db) { |
std::string sql_str = "INSERT INTO " + std::string(kTableName) |
+ " (extension_id, time, api_type, api_action_type, target_type," |
- " api_call, extra) VALUES (?,?,?,?,?,?,?)"; |
+ " api_call, args, extra) VALUES (?,?,?,?,?,?,?,?)"; |
sql::Statement statement(db->GetCachedStatement( |
sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
statement.BindString(0, extension_id_); |
@@ -75,8 +60,8 @@ void APIAction::Record(sql::Connection* db) { |
statement.BindString(3, VerbAsString()); |
statement.BindString(4, TargetAsString()); |
statement.BindString(5, api_call_); |
- statement.BindString(6, extra_); |
- |
+ statement.BindString(6, args_); |
+ statement.BindString(7, extra_); |
if (!statement.Run()) |
LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
} |
@@ -90,7 +75,7 @@ std::string APIAction::PrettyPrintForDebug() { |
// TODO(felt): implement this for real when the UI is redesigned. |
return "ID: " + extension_id_ + + ", CATEGORY: " + TypeAsString() + |
", VERB: " + VerbAsString() + ", TARGET: " + TargetAsString() + |
- ", API: " + api_call_; |
+ ", API: " + api_call_ + ", ARGS: " + args_; |
} |
std::string APIAction::TypeAsString() const { |