Index: chrome/browser/extensions/dom_actions.cc |
=================================================================== |
--- chrome/browser/extensions/dom_actions.cc (revision 181016) |
+++ chrome/browser/extensions/dom_actions.cc (working copy) |
@@ -3,46 +3,67 @@ |
// found in the LICENSE file. |
#include "base/logging.h" |
+#include "base/stringprintf.h" |
#include "base/utf_string_conversions.h" |
-#include "chrome/browser/extensions/url_actions.h" |
+#include "chrome/browser/extensions/dom_actions.h" |
#include "content/public/browser/browser_thread.h" |
using content::BrowserThread; |
namespace extensions { |
-const char* UrlAction::kTableName = "activitylog_urls"; |
-const char* UrlAction::kTableStructure = "(" |
+const char* DOMAction::kTableName = "activitylog_urls"; |
+const char* DOMAction::kTableBasicFields = |
"extension_id LONGVARCHAR NOT NULL, " |
- "time INTEGER NOT NULL, " |
- "url_action_type LONGVARCHAR NOT NULL, " |
- "url LONGVARCHAR NOT NULL, " |
- "url_title LONGVARCHAR, " |
- "tech_message LONGVARCHAR NOT NULL, " |
- "extra LONGCHAR VAR NOT NULL)"; |
+ "time INTEGER NOT NULL"; |
+const char* DOMAction::kTableContentFields[] = |
+ {"url_action_type", "url", "url_title", "api_call", "args", "extra"}; |
-UrlAction::UrlAction(const std::string& extension_id, |
+DOMAction::DOMAction(const std::string& extension_id, |
const base::Time& time, |
- const UrlActionType verb, |
+ const DOMActionType verb, |
const GURL& url, |
const string16& url_title, |
- const std::string& tech_message, |
+ const std::string& api_call, |
+ const std::string& args, |
const std::string& extra) |
: extension_id_(extension_id), |
time_(time), |
verb_(verb), |
url_(url), |
url_title_(url_title), |
- technical_message_(tech_message), |
+ api_call_(api_call), |
+ args_(args), |
extra_(extra) { } |
-UrlAction::~UrlAction() { |
+DOMAction::~DOMAction() { |
} |
-void UrlAction::Record(sql::Connection* db) { |
+// static |
+bool DOMAction::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 |
+ // tech_message. Any data loss incurred here doesn't matter since these |
+ // fields existed before we started using the AL for anything. |
+ if (db->DoesColumnExist(kTableName, "tech_message")) { |
+ std::string drop_table = base::StringPrintf("DROP TABLE %s", kTableName); |
+ if (!db->Execute(drop_table.c_str())) |
+ return false; |
+ } |
+ // Now initialize the table. |
+ bool initialized = InitializeTableInternal(db, |
+ kTableName, |
+ kTableBasicFields, |
+ kTableContentFields, |
+ arraysize(kTableContentFields)); |
+ return initialized; |
+} |
+ |
+void DOMAction::Record(sql::Connection* db) { |
std::string sql_str = "INSERT INTO " + std::string(kTableName) + |
- " (extension_id, time, url_action_type, url, url_title, tech_message," |
- " extra) VALUES (?,?,?,?,?,?,?)"; |
+ " (extension_id, time, url_action_type, url, url_title, api_call, args," |
+ " extra) VALUES (?,?,?,?,?,?,?,?)"; |
sql::Statement statement(db->GetCachedStatement( |
sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
statement.BindString(0, extension_id_); |
@@ -50,24 +71,33 @@ |
statement.BindString(2, VerbAsString()); |
statement.BindString(3, history::URLDatabase::GURLToDatabaseURL(url_)); |
statement.BindString16(4, url_title_); |
- statement.BindString(5, technical_message_); |
- statement.BindString(6, extra_); |
- if (!statement.Run()) |
+ statement.BindString(5, api_call_); |
+ statement.BindString(6, args_); |
+ statement.BindString(7, "sdf"); |
+ if (!statement.Run()) { |
LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
+ LOG(ERROR) << "extension_id: " << extension_id_ << "; verb: " << |
+ VerbAsString() << "; url: " << |
+ history::URLDatabase::GURLToDatabaseURL(url_) << "; title: " << url_title_ |
+ << "; api_call: " << api_call_ << "; args: " << args_; |
+ } |
} |
-std::string UrlAction::PrettyPrintFori18n() { |
+std::string DOMAction::PrettyPrintFori18n() { |
// TODO(felt): implement this for real when the UI is redesigned. |
return PrettyPrintForDebug(); |
} |
-std::string UrlAction::PrettyPrintForDebug() { |
+std::string DOMAction::PrettyPrintForDebug() { |
// TODO(felt): implement this for real when the UI is redesigned. |
- return "Injected scripts (" + technical_message_ + ") onto " |
+ if (verb_ == INSERTED) |
+ return "Injected scripts (" + args_ + ") onto " |
+ std::string(url_.spec()); |
+ else |
+ return "DOM API CALL: " + api_call_ + ", ARGS: " + args_; |
} |
-std::string UrlAction::VerbAsString() const { |
+std::string DOMAction::VerbAsString() const { |
switch (verb_) { |
case MODIFIED: |
return "MODIFIED"; |
@@ -83,7 +113,7 @@ |
} |
} |
-UrlAction::UrlActionType UrlAction::StringAsUrlActionType( |
+DOMAction::DOMActionType DOMAction::StringAsDOMActionType( |
const std::string& str) { |
if (str == "MODIFIED") { |
return MODIFIED; |