OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/extensions/url_actions.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 |
| 10 using content::BrowserThread; |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 const char* UrlAction::kTableName = "activitylog_urls"; |
| 15 const char* UrlAction::kTableStructure = "(" |
| 16 "extension_id LONGVARCHAR NOT NULL, " |
| 17 "time INTEGER NOT NULL, " |
| 18 "url_action_type LONGVARCHAR NOT NULL, " |
| 19 "url LONGVARCHAR NOT NULL, " |
| 20 "url_title LONGVARCHAR, " |
| 21 "tech_message LONGVARCHAR NOT NULL, " |
| 22 "extra LONGCHAR VAR NOT NULL)"; |
| 23 |
| 24 UrlAction::UrlAction(const std::string& extension_id, |
| 25 const base::Time& time, |
| 26 const UrlActionType verb, |
| 27 const GURL& url, |
| 28 const string16& url_title, |
| 29 const std::string& tech_message, |
| 30 const std::string& extra) |
| 31 : extension_id_(extension_id), |
| 32 time_(time), |
| 33 verb_(verb), |
| 34 url_(url), |
| 35 url_title_(url_title), |
| 36 technical_message_(tech_message), |
| 37 extra_(extra) { } |
| 38 |
| 39 UrlAction::~UrlAction() { |
| 40 } |
| 41 |
| 42 void UrlAction::Record(sql::Connection* db) { |
| 43 std::string sql_str = "INSERT INTO " + std::string(kTableName) + |
| 44 " (extension_id, time, url_action_type, url, url_title, tech_message," |
| 45 " extra) VALUES (?,?,?,?,?,?,?)"; |
| 46 sql::Statement statement(db->GetCachedStatement( |
| 47 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
| 48 statement.BindString(0, extension_id_); |
| 49 statement.BindInt64(1, time_.ToInternalValue()); |
| 50 statement.BindString(2, VerbAsString()); |
| 51 statement.BindString(3, history::URLDatabase::GURLToDatabaseURL(url_)); |
| 52 statement.BindString16(4, url_title_); |
| 53 statement.BindString(5, technical_message_); |
| 54 statement.BindString(6, extra_); |
| 55 if (!statement.Run()) |
| 56 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
| 57 } |
| 58 |
| 59 std::string UrlAction::PrettyPrintFori18n() { |
| 60 // TODO(felt): implement this for real when the UI is redesigned. |
| 61 return PrettyPrintForDebug(); |
| 62 } |
| 63 |
| 64 std::string UrlAction::PrettyPrintForDebug() { |
| 65 // TODO(felt): implement this for real when the UI is redesigned. |
| 66 return "Injected scripts (" + technical_message_ + ") onto " |
| 67 + std::string(url_.spec()); |
| 68 } |
| 69 |
| 70 std::string UrlAction::VerbAsString() const { |
| 71 switch (verb_) { |
| 72 case MODIFIED: |
| 73 return "MODIFIED"; |
| 74 case READ: |
| 75 return "READ"; |
| 76 case INSERTED: |
| 77 return "INSERTED"; |
| 78 case XHR: |
| 79 return "XHR"; |
| 80 default: |
| 81 NOTREACHED(); |
| 82 return NULL; |
| 83 } |
| 84 } |
| 85 |
| 86 UrlAction::UrlActionType UrlAction::StringAsUrlActionType( |
| 87 const std::string& str) { |
| 88 if (str == "MODIFIED") { |
| 89 return MODIFIED; |
| 90 } else if (str == "READ") { |
| 91 return READ; |
| 92 } else if (str == "INSERTED") { |
| 93 return INSERTED; |
| 94 } else if (str == "XHR") { |
| 95 return XHR; |
| 96 } else { |
| 97 NOTREACHED(); |
| 98 return MODIFIED; // this should never happen! |
| 99 } |
| 100 } |
| 101 |
| 102 } // namespace extensions |
| 103 |
OLD | NEW |