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

Side by Side Diff: chrome/browser/extensions/blocked_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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/blocked_actions.h ('k') | chrome/browser/extensions/dom_actions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/stringprintf.h"
7 #include "chrome/browser/extensions/blocked_actions.h" 8 #include "chrome/browser/extensions/blocked_actions.h"
8 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
9 10
10 using content::BrowserThread; 11 using content::BrowserThread;
11 12
12 namespace extensions { 13 namespace extensions {
13 14
14 const char* BlockedAction::kTableName = "activitylog_blocked"; 15 const char* BlockedAction::kTableName = "activitylog_blocked";
15 const char* BlockedAction::kTableStructure = "(" 16 const char* BlockedAction::kTableBasicFields =
16 "extension_id LONGVARCHAR NOT NULL, " 17 "extension_id LONGVARCHAR NOT NULL, "
17 "time INTEGER NOT NULL, " 18 "time INTEGER NOT NULL";
18 "blocked_action LONGVARCHAR NOT NULL, " 19 const char* BlockedAction::kTableContentFields[] =
19 "reason LONGVARCHAR NOT NULL, " 20 {"api_call", "args", "reason", "extra"};
20 "extra LONGVARCHAR NOT NULL)";
21 21
22 BlockedAction::BlockedAction(const std::string& extension_id, 22 BlockedAction::BlockedAction(const std::string& extension_id,
23 const base::Time& time, 23 const base::Time& time,
24 const std::string& blocked_action, 24 const std::string& api_call,
25 const std::string& args,
25 const std::string& reason, 26 const std::string& reason,
26 const std::string& extra) 27 const std::string& extra)
27 : extension_id_(extension_id), 28 : extension_id_(extension_id),
28 time_(time), 29 time_(time),
29 blocked_action_(blocked_action), 30 api_call_(api_call),
31 args_(args),
30 reason_(reason), 32 reason_(reason),
31 extra_(extra) { } 33 extra_(extra) { }
32 34
33 BlockedAction::~BlockedAction() { 35 BlockedAction::~BlockedAction() {
34 } 36 }
35 37
38 // static
39 bool BlockedAction::InitializeTable(sql::Connection* db) {
40 // The original table schema was different than the existing one.
41 // Sqlite doesn't let you delete or modify existing columns, so we drop it.
42 // The old version can be identified because it had a field named
43 // blocked_action. Any data loss incurred here doesn't matter since these
44 // fields existed before we started using the AL for anything.
45 if (db->DoesColumnExist(kTableName, "blocked_action")) {
46 std::string drop_table = base::StringPrintf("DROP TABLE %s", kTableName);
47 if (!db->Execute(drop_table.c_str()))
48 return false;
49 }
50 return InitializeTableInternal(db,
51 kTableName,
52 kTableBasicFields,
53 kTableContentFields,
54 arraysize(kTableContentFields));
55 }
56
36 void BlockedAction::Record(sql::Connection* db) { 57 void BlockedAction::Record(sql::Connection* db) {
37 std::string sql_str = "INSERT INTO " + std::string(kTableName) 58 std::string sql_str = "INSERT INTO " + std::string(kTableName)
38 + " (extension_id, time, blocked_action, reason, extra) VALUES (?,?,?,?,?)"; 59 + " (extension_id, time, api_call, args, reason, extra)"
60 " VALUES (?,?,?,?,?,?)";
39 sql::Statement statement(db->GetCachedStatement( 61 sql::Statement statement(db->GetCachedStatement(
40 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); 62 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
41 statement.BindString(0, extension_id_); 63 statement.BindString(0, extension_id_);
42 statement.BindInt64(1, time().ToInternalValue()); 64 statement.BindInt64(1, time().ToInternalValue());
43 statement.BindString(2, blocked_action_); 65 statement.BindString(2, api_call_);
44 statement.BindString(3, reason_); 66 statement.BindString(3, args_);
45 statement.BindString(4, extra_); 67 statement.BindString(4, reason_);
68 statement.BindString(5, extra_);
46 if (!statement.Run()) 69 if (!statement.Run())
47 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; 70 LOG(ERROR) << "Activity log database I/O failed: " << sql_str;
48 } 71 }
49 72
50 std::string BlockedAction::PrettyPrintFori18n() { 73 std::string BlockedAction::PrettyPrintFori18n() {
51 // TODO(felt): implement this for real when the UI is redesigned. 74 // TODO(felt): implement this for real when the UI is redesigned.
52 return PrettyPrintForDebug(); 75 return PrettyPrintForDebug();
53 } 76 }
54 77
55 std::string BlockedAction::PrettyPrintForDebug() { 78 std::string BlockedAction::PrettyPrintForDebug() {
56 // TODO(felt): implement this for real when the UI is redesigned. 79 // TODO(felt): implement this for real when the UI is redesigned.
57 return "ID: " + extension_id_ + ", blocked action " + blocked_action_ + 80 return "ID: " + extension_id_ + ", blocked action " + api_call_ +
58 ", reason: " + reason_; 81 ", reason: " + reason_;
59 } 82 }
60 83
61 } // namespace extensions 84 } // namespace extensions
62 85
OLDNEW
« no previous file with comments | « chrome/browser/extensions/blocked_actions.h ('k') | chrome/browser/extensions/dom_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698