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

Side by Side Diff: chrome/browser/extensions/api_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/api_actions.h ('k') | chrome/browser/extensions/blocked_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 "base/stringprintf.h"
8 #include "chrome/browser/extensions/api_actions.h" 8 #include "chrome/browser/extensions/api_actions.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 10
11 using content::BrowserThread; 11 using content::BrowserThread;
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 const char* APIAction::kTableName = "activitylog_apis"; 15 const char* APIAction::kTableName = "activitylog_apis";
16 const char* APIAction::kTableStructure = "(" 16 const char* APIAction::kTableBasicFields =
17 "extension_id LONGVARCHAR NOT NULL, " 17 "extension_id LONGVARCHAR NOT NULL, "
18 "time INTEGER NOT NULL, " 18 "time INTEGER NOT NULL";
19 "api_type LONGVARCHAR NOT NULL, " 19 const char* APIAction::kTableContentFields[] =
20 "api_action_type LONGVARCHAR NOT NULL, " 20 {"api_type", "api_action_type", "target_type", "api_call", "args", "extra"};
21 "target_type LONGVARCHAR NOT NULL, "
22 "api_call LONGVARCHAR NOT NULL, "
23 "extra LONGVARCHAR NOT NULL)";
24 21
25 APIAction::APIAction(const std::string& extension_id, 22 APIAction::APIAction(const std::string& extension_id,
26 const base::Time& time, 23 const base::Time& time,
27 const Type type, 24 const Type type,
28 const Verb verb, 25 const Verb verb,
29 const Target target, 26 const Target target,
30 const std::string& api_call, 27 const std::string& api_call,
28 const std::string& args,
31 const std::string& extra) 29 const std::string& extra)
32 : extension_id_(extension_id), 30 : extension_id_(extension_id),
33 time_(time), 31 time_(time),
34 type_(type), 32 type_(type),
35 verb_(verb), 33 verb_(verb),
36 target_(target), 34 target_(target),
37 api_call_(api_call), 35 api_call_(api_call),
36 args_(args),
38 extra_(extra) { } 37 extra_(extra) { }
39 38
40 APIAction::~APIAction() { 39 APIAction::~APIAction() {
41 } 40 }
42 41
43 // static 42 // static
44 bool APIAction::InitializeTable(sql::Connection* db) { 43 bool APIAction::InitializeTable(sql::Connection* db) {
45 if (!db->DoesTableExist(kTableName)) { 44 return InitializeTableInternal(db,
46 std::string table_creator = base::StringPrintf( 45 kTableName,
47 "CREATE TABLE %s %s", kTableName, kTableStructure); 46 kTableBasicFields,
48 if (!db->Execute(table_creator.c_str())) 47 kTableContentFields,
49 return false; 48 arraysize(kTableContentFields));
50 } else if (!db->DoesColumnExist(kTableName, "api_type")) {
51 // Old versions of the table lack the api_type column. Add it if
52 // needed, with values defaulting to "CALL".
53 //
54 // TODO(mvrable): Remove this update code once we're fairly certain that
55 // everyone will have converted to the new schema.
56 std::string table_updater = base::StringPrintf(
57 "ALTER TABLE %s ADD COLUMN api_type LONGVARCHAR; "
58 "UPDATE %s SET api_type = 'CALL'",
59 kTableName, kTableName);
60 if (!db->Execute(table_updater.c_str()))
61 return false;
62 }
63 return true;
64 } 49 }
65 50
66 void APIAction::Record(sql::Connection* db) { 51 void APIAction::Record(sql::Connection* db) {
67 std::string sql_str = "INSERT INTO " + std::string(kTableName) 52 std::string sql_str = "INSERT INTO " + std::string(kTableName)
68 + " (extension_id, time, api_type, api_action_type, target_type," 53 + " (extension_id, time, api_type, api_action_type, target_type,"
69 " api_call, extra) VALUES (?,?,?,?,?,?,?)"; 54 " api_call, args, extra) VALUES (?,?,?,?,?,?,?,?)";
70 sql::Statement statement(db->GetCachedStatement( 55 sql::Statement statement(db->GetCachedStatement(
71 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); 56 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
72 statement.BindString(0, extension_id_); 57 statement.BindString(0, extension_id_);
73 statement.BindInt64(1, time_.ToInternalValue()); 58 statement.BindInt64(1, time_.ToInternalValue());
74 statement.BindString(2, TypeAsString()); 59 statement.BindString(2, TypeAsString());
75 statement.BindString(3, VerbAsString()); 60 statement.BindString(3, VerbAsString());
76 statement.BindString(4, TargetAsString()); 61 statement.BindString(4, TargetAsString());
77 statement.BindString(5, api_call_); 62 statement.BindString(5, api_call_);
78 statement.BindString(6, extra_); 63 statement.BindString(6, args_);
79 64 statement.BindString(7, extra_);
80 if (!statement.Run()) 65 if (!statement.Run())
81 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; 66 LOG(ERROR) << "Activity log database I/O failed: " << sql_str;
82 } 67 }
83 68
84 std::string APIAction::PrettyPrintFori18n() { 69 std::string APIAction::PrettyPrintFori18n() {
85 // TODO(felt): implement this for real when the UI is redesigned. 70 // TODO(felt): implement this for real when the UI is redesigned.
86 return PrettyPrintForDebug(); 71 return PrettyPrintForDebug();
87 } 72 }
88 73
89 std::string APIAction::PrettyPrintForDebug() { 74 std::string APIAction::PrettyPrintForDebug() {
90 // TODO(felt): implement this for real when the UI is redesigned. 75 // TODO(felt): implement this for real when the UI is redesigned.
91 return "ID: " + extension_id_ + + ", CATEGORY: " + TypeAsString() + 76 return "ID: " + extension_id_ + + ", CATEGORY: " + TypeAsString() +
92 ", VERB: " + VerbAsString() + ", TARGET: " + TargetAsString() + 77 ", VERB: " + VerbAsString() + ", TARGET: " + TargetAsString() +
93 ", API: " + api_call_; 78 ", API: " + api_call_ + ", ARGS: " + args_;
94 } 79 }
95 80
96 std::string APIAction::TypeAsString() const { 81 std::string APIAction::TypeAsString() const {
97 switch (type_) { 82 switch (type_) {
98 case CALL: 83 case CALL:
99 return "CALL"; 84 return "CALL";
100 case EVENT_CALLBACK: 85 case EVENT_CALLBACK:
101 return "EVENT_CALLBACK"; 86 return "EVENT_CALLBACK";
102 default: 87 default:
103 return "UNKNOWN_TYPE"; 88 return "UNKNOWN_TYPE";
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } else if (str == "NOTIFICATION" || str == "notification") { 180 } else if (str == "NOTIFICATION" || str == "notification") {
196 return NOTIFICATION; 181 return NOTIFICATION;
197 } else if (str == "OMNIBOX" || str == "omnibox") { 182 } else if (str == "OMNIBOX" || str == "omnibox") {
198 return OMNIBOX; 183 return OMNIBOX;
199 } else { 184 } else {
200 return UNKNOWN_TARGET; 185 return UNKNOWN_TARGET;
201 } 186 }
202 } 187 }
203 188
204 } // namespace extensions 189 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api_actions.h ('k') | chrome/browser/extensions/blocked_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698