Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2297)

Unified Diff: chrome/browser/extensions/dom_actions.cc

Issue 12262025: Alter the ActivityLog db table schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/dom_actions.h ('k') | chrome/browser/extensions/url_actions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/dom_actions.cc
diff --git a/chrome/browser/extensions/dom_actions.cc b/chrome/browser/extensions/dom_actions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9bbf77113b991c2f27c9d00291e8421e0f3ad964
--- /dev/null
+++ b/chrome/browser/extensions/dom_actions.cc
@@ -0,0 +1,133 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/extensions/dom_actions.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+namespace extensions {
+
+const char* DOMAction::kTableName = "activitylog_urls";
+const char* DOMAction::kTableBasicFields =
+ "extension_id LONGVARCHAR NOT NULL, "
+ "time INTEGER NOT NULL";
+const char* DOMAction::kTableContentFields[] =
+ {"url_action_type", "url", "url_title", "api_call", "args", "extra"};
+
+DOMAction::DOMAction(const std::string& extension_id,
+ const base::Time& time,
+ const DOMActionType verb,
+ const GURL& url,
+ const string16& url_title,
+ 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),
+ api_call_(api_call),
+ args_(args),
+ extra_(extra) { }
+
+DOMAction::~DOMAction() {
+}
+
+// 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, api_call, args,"
+ " 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, history::URLDatabase::GURLToDatabaseURL(url_));
+ statement.BindString16(4, url_title_);
+ 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 DOMAction::PrettyPrintFori18n() {
+ // TODO(felt): implement this for real when the UI is redesigned.
+ return PrettyPrintForDebug();
+}
+
+std::string DOMAction::PrettyPrintForDebug() {
+ // TODO(felt): implement this for real when the UI is redesigned.
+ if (verb_ == INSERTED)
+ return "Injected scripts (" + args_ + ") onto "
+ + std::string(url_.spec());
+ else
+ return "DOM API CALL: " + api_call_ + ", ARGS: " + args_;
+}
+
+std::string DOMAction::VerbAsString() const {
+ switch (verb_) {
+ case MODIFIED:
+ return "MODIFIED";
+ case READ:
+ return "READ";
+ case INSERTED:
+ return "INSERTED";
+ case XHR:
+ return "XHR";
+ default:
+ NOTREACHED();
+ return NULL;
+ }
+}
+
+DOMAction::DOMActionType DOMAction::StringAsDOMActionType(
+ const std::string& str) {
+ if (str == "MODIFIED") {
+ return MODIFIED;
+ } else if (str == "READ") {
+ return READ;
+ } else if (str == "INSERTED") {
+ return INSERTED;
+ } else if (str == "XHR") {
+ return XHR;
+ } else {
+ NOTREACHED();
+ return MODIFIED; // this should never happen!
+ }
+}
+
+} // namespace extensions
+
« no previous file with comments | « chrome/browser/extensions/dom_actions.h ('k') | chrome/browser/extensions/url_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698