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 <string> | |
6 #include "base/logging.h" | |
7 #include "chrome/browser/extensions/blocked_actions.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 | |
10 using content::BrowserThread; | |
11 | |
12 namespace extensions { | |
13 | |
14 const char* BlockedAction::kTableName = "activitylog_blocked"; | |
15 const char* BlockedAction::kTableStructure = "(" | |
16 "extension_id LONGVARCHAR NOT NULL, " | |
17 "time INTEGER NOT NULL, " | |
18 "blocked_action LONGVARCHAR NOT NULL, " | |
19 "reason LONGVARCHAR NOT NULL, " | |
20 "extra LONGVARCHAR NOT NULL)"; | |
21 | |
22 BlockedAction::BlockedAction(const std::string& extension_id, | |
23 const base::Time& time, | |
24 const std::string& blocked_action, | |
25 const std::string& reason, | |
26 const std::string& extra) | |
27 : extension_id_(extension_id), | |
28 time_(time), | |
29 blocked_action_(blocked_action), | |
30 reason_(reason), | |
31 extra_(extra) { } | |
32 | |
33 BlockedAction::~BlockedAction() { | |
34 } | |
35 | |
36 void BlockedAction::Record(sql::Connection* db) { | |
37 std::string sql_str = "INSERT INTO " + std::string(kTableName) | |
38 + " (extension_id, time, blocked_action, reason, extra) VALUES (?,?,?,?,?)"; | |
39 sql::Statement statement(db->GetCachedStatement( | |
40 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
41 statement.BindString(0, extension_id_); | |
42 statement.BindInt64(1, time().ToInternalValue()); | |
43 statement.BindString(2, blocked_action_); | |
44 statement.BindString(3, reason_); | |
45 statement.BindString(4, extra_); | |
46 if (!statement.Run()) | |
47 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; | |
48 } | |
49 | |
50 std::string BlockedAction::PrettyPrintFori18n() { | |
51 // TODO(felt): implement this for real when the UI is redesigned. | |
52 return PrettyPrintForDebug(); | |
53 } | |
54 | |
55 std::string BlockedAction::PrettyPrintForDebug() { | |
56 // TODO(felt): implement this for real when the UI is redesigned. | |
57 return "ID: " + extension_id_ + ", blocked action " + blocked_action_ + | |
58 ", reason: " + reason_; | |
59 } | |
60 | |
61 } // namespace extensions | |
62 | |
OLD | NEW |