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 #ifndef CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/extensions/activity_actions.h" | 10 #include "chrome/browser/extensions/activity_actions.h" |
11 | 11 |
12 namespace extensions { | 12 namespace extensions { |
13 | 13 |
14 // This class describes API calls that did not run into permissions or quota | 14 // This class describes API calls that did not run into permissions or quota |
15 // problems. See BlockedActions for API calls that did not succeed. | 15 // problems. See BlockedActions for API calls that did not succeed. |
16 class APIAction : public Action { | 16 class APIAction : public Action { |
17 public: | 17 public: |
18 // TODO(mvrable): Come up with a good name for this; I'm not entirely happy | |
Eric Dingle
2013/01/24 16:16:34
Maybe use APIActionType here and use APIActionVerb
mvrable
2013/01/24 18:12:31
That sounds good to me. Adrienne, are you fine wi
| |
19 // with APICategory but "type" is already used. | |
20 enum APICategory { | |
21 CALL, | |
22 EVENT_CALLBACK, | |
23 UNKNOWN_CATEGORY | |
24 }; | |
25 | |
18 // TODO(felt): I'll finalize this list when making the UI. | 26 // TODO(felt): I'll finalize this list when making the UI. |
19 enum APIActionType { | 27 enum APIActionType { |
20 READ, | 28 READ, |
21 MODIFIED, | 29 MODIFIED, |
22 DELETED, | 30 DELETED, |
23 ADDED, | 31 ADDED, |
24 ENABLED, | 32 ENABLED, |
25 DISABLED, | 33 DISABLED, |
26 CREATED, | 34 CREATED, |
27 UNKNOWN_ACTION | 35 UNKNOWN_ACTION |
28 }; | 36 }; |
29 | 37 |
30 // TODO(felt): I'll finalize this list when making the UI. | 38 // TODO(felt): I'll finalize this list when making the UI. |
31 enum APITargetType { | 39 enum APITargetType { |
32 BOOKMARK, | 40 BOOKMARK, |
33 TABS, | 41 TABS, |
34 HISTORY, | 42 HISTORY, |
35 COOKIES, | 43 COOKIES, |
36 BROWSER_ACTION, | 44 BROWSER_ACTION, |
37 NOTIFICATION, | 45 NOTIFICATION, |
38 OMNIBOX, | 46 OMNIBOX, |
39 UNKNOWN_TARGET | 47 UNKNOWN_TARGET |
40 }; | 48 }; |
41 | 49 |
42 static const char* kTableName; | 50 static const char* kTableName; |
43 static const char* kTableStructure; | 51 static const char* kTableStructure; |
44 | 52 |
53 // Create the database table for storing APIActions, or update the schema if | |
54 // it is out of date. Any existing data is preserved. | |
55 static bool InitializeTable(sql::Connection* db); | |
56 | |
45 // Create a new APIAction to describe a successful API call. All | 57 // Create a new APIAction to describe a successful API call. All |
46 // parameters are required. | 58 // parameters are required. |
47 APIAction(const std::string& extension_id, | 59 APIAction(const std::string& extension_id, |
48 const base::Time& time, | 60 const base::Time& time, |
61 const APICategory category, // e.g. "CALL" | |
49 const APIActionType verb, // e.g. "ADDED" | 62 const APIActionType verb, // e.g. "ADDED" |
50 const APITargetType target, // e.g. "BOOKMARK" | 63 const APITargetType target, // e.g. "BOOKMARK" |
51 const std::string& api_call, // full method signature incl args | 64 const std::string& api_call, // full method signature incl args |
52 const std::string& extra); // any extra logging info | 65 const std::string& extra); // any extra logging info |
53 | 66 |
54 // Record the action in the database. | 67 // Record the action in the database. |
55 virtual void Record(sql::Connection* db) OVERRIDE; | 68 virtual void Record(sql::Connection* db) OVERRIDE; |
56 | 69 |
57 // Print a APIAction with il8n substitutions for display. | 70 // Print a APIAction with il8n substitutions for display. |
58 virtual std::string PrettyPrintFori18n() OVERRIDE; | 71 virtual std::string PrettyPrintFori18n() OVERRIDE; |
59 | 72 |
60 // Print a APIAction as a regular string for debugging purposes. | 73 // Print a APIAction as a regular string for debugging purposes. |
61 virtual std::string PrettyPrintForDebug() OVERRIDE; | 74 virtual std::string PrettyPrintForDebug() OVERRIDE; |
62 | 75 |
63 // Helper methods for recording the values into the db. | 76 // Helper methods for recording the values into the db. |
64 const std::string& extension_id() const { return extension_id_; } | 77 const std::string& extension_id() const { return extension_id_; } |
65 const base::Time& time() const { return time_; } | 78 const base::Time& time() const { return time_; } |
66 const std::string& api_call() const { return api_call_; } | 79 const std::string& api_call() const { return api_call_; } |
80 std::string CategoryAsString() const; | |
67 std::string VerbAsString() const; | 81 std::string VerbAsString() const; |
68 std::string TargetAsString() const; | 82 std::string TargetAsString() const; |
69 std::string extra() const { return extra_; } | 83 std::string extra() const { return extra_; } |
70 | 84 |
71 // Helper methods for creating a APIAction. | 85 // Helper methods for creating a APIAction. |
86 static APICategory StringAsCategory(const std::string& str); | |
72 static APIActionType StringAsActionType(const std::string& str); | 87 static APIActionType StringAsActionType(const std::string& str); |
73 static APITargetType StringAsTargetType(const std::string& str); | 88 static APITargetType StringAsTargetType(const std::string& str); |
74 | 89 |
75 protected: | 90 protected: |
76 virtual ~APIAction(); | 91 virtual ~APIAction(); |
77 | 92 |
78 private: | 93 private: |
79 std::string extension_id_; | 94 std::string extension_id_; |
80 base::Time time_; | 95 base::Time time_; |
96 APICategory category_; | |
81 APIActionType verb_; | 97 APIActionType verb_; |
82 APITargetType target_; | 98 APITargetType target_; |
83 std::string api_call_; | 99 std::string api_call_; |
84 std::string extra_; | 100 std::string extra_; |
85 | 101 |
86 DISALLOW_COPY_AND_ASSIGN(APIAction); | 102 DISALLOW_COPY_AND_ASSIGN(APIAction); |
87 }; | 103 }; |
88 | 104 |
89 } // namespace | 105 } // namespace |
90 | 106 |
91 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ | 107 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ |
92 | 108 |
Eric Dingle
2013/01/24 16:16:34
You can remove this extra blank line.
mvrable
2013/01/24 18:12:31
Done (and fixed a couple of other files too).
| |
OLD | NEW |