Index: chrome/browser/extensions/api_actions.cc |
diff --git a/chrome/browser/extensions/api_actions.cc b/chrome/browser/extensions/api_actions.cc |
index b628afa8384be40c752c9ed2723574b9ba10c4c1..7897696f4a0a554dc708c93ca30aaf85fa6427d7 100644 |
--- a/chrome/browser/extensions/api_actions.cc |
+++ b/chrome/browser/extensions/api_actions.cc |
@@ -4,6 +4,7 @@ |
#include <string> |
#include "base/logging.h" |
+#include "base/stringprintf.h" |
#include "chrome/browser/extensions/api_actions.h" |
#include "content/public/browser/browser_thread.h" |
@@ -15,6 +16,7 @@ const char* APIAction::kTableName = "activitylog_apis"; |
const char* APIAction::kTableStructure = "(" |
"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, " |
@@ -22,12 +24,14 @@ const char* APIAction::kTableStructure = "(" |
APIAction::APIAction(const std::string& extension_id, |
const base::Time& time, |
- const APIActionType verb, |
- const APITargetType target, |
+ const Type type, |
+ const Verb verb, |
+ const Target target, |
const std::string& api_call, |
const std::string& extra) |
: extension_id_(extension_id), |
time_(time), |
+ type_(type), |
verb_(verb), |
target_(target), |
api_call_(api_call), |
@@ -36,18 +40,42 @@ APIAction::APIAction(const std::string& extension_id, |
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; |
+} |
+ |
void APIAction::Record(sql::Connection* db) { |
std::string sql_str = "INSERT INTO " + std::string(kTableName) |
- + " (extension_id, time, api_action_type, target_type, api_call, extra)" |
- " VALUES (?,?,?,?,?,?)"; |
+ + " (extension_id, time, api_type, api_action_type, target_type," |
+ " api_call, 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, VerbAsString()); |
- statement.BindString(3, TargetAsString()); |
- statement.BindString(4, api_call_); |
- statement.BindString(5, extra_); |
+ statement.BindString(2, TypeAsString()); |
+ statement.BindString(3, VerbAsString()); |
+ statement.BindString(4, TargetAsString()); |
+ statement.BindString(5, api_call_); |
+ statement.BindString(6, extra_); |
if (!statement.Run()) |
LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
@@ -60,8 +88,20 @@ std::string APIAction::PrettyPrintFori18n() { |
std::string APIAction::PrettyPrintForDebug() { |
// TODO(felt): implement this for real when the UI is redesigned. |
- return "ID: " + extension_id_ + ", VERB: " + VerbAsString() + |
- ", TARGET: " + TargetAsString() + ", API: " + api_call_; |
+ return "ID: " + extension_id_ + + ", CATEGORY: " + TypeAsString() + |
+ ", VERB: " + VerbAsString() + ", TARGET: " + TargetAsString() + |
+ ", API: " + api_call_; |
+} |
+ |
+std::string APIAction::TypeAsString() const { |
+ switch (type_) { |
+ case CALL: |
+ return "CALL"; |
+ case EVENT_CALLBACK: |
+ return "EVENT_CALLBACK"; |
+ default: |
+ return "UNKNOWN_TYPE"; |
+ } |
} |
std::string APIAction::VerbAsString() const { |
@@ -81,7 +121,7 @@ std::string APIAction::VerbAsString() const { |
case CREATED: |
return "CREATED"; |
default: |
- return "UNKNOWN_ACTION"; |
+ return "UNKNOWN_VERB"; |
} |
} |
@@ -106,7 +146,18 @@ std::string APIAction::TargetAsString() const { |
} |
} |
-APIAction::APIActionType APIAction::StringAsActionType( |
+APIAction::Type APIAction::StringAsType( |
+ const std::string& str) { |
+ if (str == "CALL") { |
+ return CALL; |
+ } else if (str == "EVENT_CALLBACK") { |
+ return EVENT_CALLBACK; |
+ } else { |
+ return UNKNOWN_TYPE; |
+ } |
+} |
+ |
+APIAction::Verb APIAction::StringAsVerb( |
const std::string& str) { |
if (str == "READ") { |
return READ; |
@@ -123,13 +174,13 @@ APIAction::APIActionType APIAction::StringAsActionType( |
} else if (str == "CREATED") { |
return CREATED; |
} else { |
- return UNKNOWN_ACTION; |
+ return UNKNOWN_VERB; |
} |
} |
// The all-caps strings match the enum names. The lowercase strings match the |
// actual object names (e.g., cookies.remove(...);). |
-APIAction::APITargetType APIAction::StringAsTargetType( |
+APIAction::Target APIAction::StringAsTarget( |
const std::string& str) { |
if (str == "BOOKMARK" || str == "bookmark") { |
return BOOKMARK; |
@@ -151,4 +202,3 @@ APIAction::APITargetType APIAction::StringAsTargetType( |
} |
} // namespace extensions |
- |