OLD | NEW |
---|---|
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 "chrome/browser/extensions/api_actions.h" | 7 #include "chrome/browser/extensions/api_actions.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 using content::BrowserThread; | 10 using content::BrowserThread; |
11 | 11 |
12 namespace extensions { | 12 namespace extensions { |
13 | 13 |
14 const char* APIAction::kTableName = "activitylog_apis"; | 14 const char* APIAction::kTableName = "activitylog_apis"; |
15 const char* APIAction::kTableStructure = "(" | 15 const char* APIAction::kTableStructure = "(" |
16 "extension_id LONGVARCHAR NOT NULL, " | 16 "extension_id LONGVARCHAR NOT NULL, " |
17 "time INTEGER NOT NULL, " | 17 "time INTEGER NOT NULL, " |
18 "api_category LONGVARCHAR NOT NULL, " | |
felt
2013/01/22 23:02:11
I think that the schema change is good.
| |
18 "api_action_type LONGVARCHAR NOT NULL, " | 19 "api_action_type LONGVARCHAR NOT NULL, " |
19 "target_type LONGVARCHAR NOT NULL, " | 20 "target_type LONGVARCHAR NOT NULL, " |
20 "api_call LONGVARCHAR NOT NULL, " | 21 "api_call LONGVARCHAR NOT NULL, " |
21 "extra LONGVARCHAR NOT NULL)"; | 22 "extra LONGVARCHAR NOT NULL)"; |
22 | 23 |
23 APIAction::APIAction(const std::string& extension_id, | 24 APIAction::APIAction(const std::string& extension_id, |
24 const base::Time& time, | 25 const base::Time& time, |
26 const APICategory category, | |
25 const APIActionType verb, | 27 const APIActionType verb, |
26 const APITargetType target, | 28 const APITargetType target, |
27 const std::string& api_call, | 29 const std::string& api_call, |
28 const std::string& extra) | 30 const std::string& extra) |
29 : extension_id_(extension_id), | 31 : extension_id_(extension_id), |
30 time_(time), | 32 time_(time), |
33 category_(category), | |
31 verb_(verb), | 34 verb_(verb), |
32 target_(target), | 35 target_(target), |
33 api_call_(api_call), | 36 api_call_(api_call), |
34 extra_(extra) { } | 37 extra_(extra) { } |
35 | 38 |
36 APIAction::~APIAction() { | 39 APIAction::~APIAction() { |
37 } | 40 } |
38 | 41 |
39 void APIAction::Record(sql::Connection* db) { | 42 void APIAction::Record(sql::Connection* db) { |
40 std::string sql_str = "INSERT INTO " + std::string(kTableName) | 43 std::string sql_str = "INSERT INTO " + std::string(kTableName) |
41 + " (extension_id, time, api_action_type, target_type, api_call, extra)" | 44 + " (extension_id, time, api_category, api_action_type, target_type," |
42 " VALUES (?,?,?,?,?,?)"; | 45 " api_call, extra) VALUES (?,?,?,?,?,?,?)"; |
felt
2013/01/22 23:02:11
What happens if you had the table created with the
mvrable
2013/01/23 16:54:07
I've added some code to update the database schema
| |
43 sql::Statement statement(db->GetCachedStatement( | 46 sql::Statement statement(db->GetCachedStatement( |
44 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | 47 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
45 statement.BindString(0, extension_id_); | 48 statement.BindString(0, extension_id_); |
46 statement.BindInt64(1, time_.ToInternalValue()); | 49 statement.BindInt64(1, time_.ToInternalValue()); |
47 statement.BindString(2, VerbAsString()); | 50 statement.BindString(2, CategoryAsString()); |
48 statement.BindString(3, TargetAsString()); | 51 statement.BindString(3, VerbAsString()); |
49 statement.BindString(4, api_call_); | 52 statement.BindString(4, TargetAsString()); |
50 statement.BindString(5, extra_); | 53 statement.BindString(5, api_call_); |
54 statement.BindString(6, extra_); | |
51 | 55 |
52 if (!statement.Run()) | 56 if (!statement.Run()) |
53 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; | 57 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
54 } | 58 } |
55 | 59 |
56 std::string APIAction::PrettyPrintFori18n() { | 60 std::string APIAction::PrettyPrintFori18n() { |
57 // TODO(felt): implement this for real when the UI is redesigned. | 61 // TODO(felt): implement this for real when the UI is redesigned. |
58 return PrettyPrintForDebug(); | 62 return PrettyPrintForDebug(); |
59 } | 63 } |
60 | 64 |
61 std::string APIAction::PrettyPrintForDebug() { | 65 std::string APIAction::PrettyPrintForDebug() { |
62 // TODO(felt): implement this for real when the UI is redesigned. | 66 // TODO(felt): implement this for real when the UI is redesigned. |
63 return "ID: " + extension_id_ + ", VERB: " + VerbAsString() + | 67 return "ID: " + extension_id_ + + ", CATEGORY: " + CategoryAsString() + |
64 ", TARGET: " + TargetAsString() + ", API: " + api_call_; | 68 ", VERB: " + VerbAsString() + ", TARGET: " + TargetAsString() + |
69 ", API: " + api_call_; | |
70 } | |
71 | |
72 std::string APIAction::CategoryAsString() const { | |
73 switch (category_) { | |
74 case CALL: | |
75 return "CALL"; | |
76 case EVENT_CALLBACK: | |
77 return "EVENT_CALLBACK"; | |
78 default: | |
79 return "UNKNOWN_CATEGORY"; | |
80 } | |
65 } | 81 } |
66 | 82 |
67 std::string APIAction::VerbAsString() const { | 83 std::string APIAction::VerbAsString() const { |
68 switch (verb_) { | 84 switch (verb_) { |
69 case READ: | 85 case READ: |
70 return "READ"; | 86 return "READ"; |
71 case MODIFIED: | 87 case MODIFIED: |
72 return "MODIFIED"; | 88 return "MODIFIED"; |
73 case DELETED: | 89 case DELETED: |
74 return "DELETED"; | 90 return "DELETED"; |
(...skipping 24 matching lines...) Expand all Loading... | |
99 return "BROWSER_ACTION"; | 115 return "BROWSER_ACTION"; |
100 case NOTIFICATION: | 116 case NOTIFICATION: |
101 return "NOTIFICATION"; | 117 return "NOTIFICATION"; |
102 case OMNIBOX: | 118 case OMNIBOX: |
103 return "OMNIBOX"; | 119 return "OMNIBOX"; |
104 default: | 120 default: |
105 return "UNKNOWN_TARGET"; | 121 return "UNKNOWN_TARGET"; |
106 } | 122 } |
107 } | 123 } |
108 | 124 |
125 APIAction::APICategory APIAction::StringAsCategory( | |
126 const std::string& str) { | |
127 if (str == "CALL") { | |
128 return CALL; | |
129 } else if (str == "EVENT_CALLBACK") { | |
130 return EVENT_CALLBACK; | |
131 } else { | |
132 return UNKNOWN_CATEGORY; | |
133 } | |
134 } | |
135 | |
109 APIAction::APIActionType APIAction::StringAsActionType( | 136 APIAction::APIActionType APIAction::StringAsActionType( |
110 const std::string& str) { | 137 const std::string& str) { |
111 if (str == "READ") { | 138 if (str == "READ") { |
112 return READ; | 139 return READ; |
113 } else if (str == "MODIFIED") { | 140 } else if (str == "MODIFIED") { |
114 return MODIFIED; | 141 return MODIFIED; |
115 } else if (str == "DELETED") { | 142 } else if (str == "DELETED") { |
116 return DELETED; | 143 return DELETED; |
117 } else if (str == "ADDED") { | 144 } else if (str == "ADDED") { |
118 return ADDED; | 145 return ADDED; |
(...skipping 26 matching lines...) Expand all Loading... | |
145 return NOTIFICATION; | 172 return NOTIFICATION; |
146 } else if (str == "OMNIBOX" || str == "omnibox") { | 173 } else if (str == "OMNIBOX" || str == "omnibox") { |
147 return OMNIBOX; | 174 return OMNIBOX; |
148 } else { | 175 } else { |
149 return UNKNOWN_TARGET; | 176 return UNKNOWN_TARGET; |
150 } | 177 } |
151 } | 178 } |
152 | 179 |
153 } // namespace extensions | 180 } // namespace extensions |
154 | 181 |
OLD | NEW |