| 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 enum Type { |
| 19 CALL, |
| 20 EVENT_CALLBACK, |
| 21 UNKNOWN_TYPE |
| 22 }; |
| 23 |
| 18 // TODO(felt): I'll finalize this list when making the UI. | 24 // TODO(felt): I'll finalize this list when making the UI. |
| 19 enum APIActionType { | 25 enum Verb { |
| 20 READ, | 26 READ, |
| 21 MODIFIED, | 27 MODIFIED, |
| 22 DELETED, | 28 DELETED, |
| 23 ADDED, | 29 ADDED, |
| 24 ENABLED, | 30 ENABLED, |
| 25 DISABLED, | 31 DISABLED, |
| 26 CREATED, | 32 CREATED, |
| 27 UNKNOWN_ACTION | 33 UNKNOWN_VERB |
| 28 }; | 34 }; |
| 29 | 35 |
| 30 // TODO(felt): I'll finalize this list when making the UI. | 36 // TODO(felt): I'll finalize this list when making the UI. |
| 31 enum APITargetType { | 37 enum Target { |
| 32 BOOKMARK, | 38 BOOKMARK, |
| 33 TABS, | 39 TABS, |
| 34 HISTORY, | 40 HISTORY, |
| 35 COOKIES, | 41 COOKIES, |
| 36 BROWSER_ACTION, | 42 BROWSER_ACTION, |
| 37 NOTIFICATION, | 43 NOTIFICATION, |
| 38 OMNIBOX, | 44 OMNIBOX, |
| 39 UNKNOWN_TARGET | 45 UNKNOWN_TARGET |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 static const char* kTableName; | 48 static const char* kTableName; |
| 43 static const char* kTableStructure; | 49 static const char* kTableStructure; |
| 44 | 50 |
| 51 // Create the database table for storing APIActions, or update the schema if |
| 52 // it is out of date. Any existing data is preserved. |
| 53 static bool InitializeTable(sql::Connection* db); |
| 54 |
| 45 // Create a new APIAction to describe a successful API call. All | 55 // Create a new APIAction to describe a successful API call. All |
| 46 // parameters are required. | 56 // parameters are required. |
| 47 APIAction(const std::string& extension_id, | 57 APIAction(const std::string& extension_id, |
| 48 const base::Time& time, | 58 const base::Time& time, |
| 49 const APIActionType verb, // e.g. "ADDED" | 59 const Type type, // e.g. "CALL" |
| 50 const APITargetType target, // e.g. "BOOKMARK" | 60 const Verb verb, // e.g. "ADDED" |
| 51 const std::string& api_call, // full method signature incl args | 61 const Target target, // e.g. "BOOKMARK" |
| 52 const std::string& extra); // any extra logging info | 62 const std::string& api_call, // full method signature incl args |
| 63 const std::string& extra); // any extra logging info |
| 53 | 64 |
| 54 // Record the action in the database. | 65 // Record the action in the database. |
| 55 virtual void Record(sql::Connection* db) OVERRIDE; | 66 virtual void Record(sql::Connection* db) OVERRIDE; |
| 56 | 67 |
| 57 // Print a APIAction with il8n substitutions for display. | 68 // Print a APIAction with il8n substitutions for display. |
| 58 virtual std::string PrettyPrintFori18n() OVERRIDE; | 69 virtual std::string PrettyPrintFori18n() OVERRIDE; |
| 59 | 70 |
| 60 // Print a APIAction as a regular string for debugging purposes. | 71 // Print a APIAction as a regular string for debugging purposes. |
| 61 virtual std::string PrettyPrintForDebug() OVERRIDE; | 72 virtual std::string PrettyPrintForDebug() OVERRIDE; |
| 62 | 73 |
| 63 // Helper methods for recording the values into the db. | 74 // Helper methods for recording the values into the db. |
| 64 const std::string& extension_id() const { return extension_id_; } | 75 const std::string& extension_id() const { return extension_id_; } |
| 65 const base::Time& time() const { return time_; } | 76 const base::Time& time() const { return time_; } |
| 66 const std::string& api_call() const { return api_call_; } | 77 const std::string& api_call() const { return api_call_; } |
| 78 std::string TypeAsString() const; |
| 67 std::string VerbAsString() const; | 79 std::string VerbAsString() const; |
| 68 std::string TargetAsString() const; | 80 std::string TargetAsString() const; |
| 69 std::string extra() const { return extra_; } | 81 std::string extra() const { return extra_; } |
| 70 | 82 |
| 71 // Helper methods for creating a APIAction. | 83 // Helper methods for creating a APIAction. |
| 72 static APIActionType StringAsActionType(const std::string& str); | 84 static Type StringAsType(const std::string& str); |
| 73 static APITargetType StringAsTargetType(const std::string& str); | 85 static Verb StringAsVerb(const std::string& str); |
| 86 static Target StringAsTarget(const std::string& str); |
| 74 | 87 |
| 75 protected: | 88 protected: |
| 76 virtual ~APIAction(); | 89 virtual ~APIAction(); |
| 77 | 90 |
| 78 private: | 91 private: |
| 79 std::string extension_id_; | 92 std::string extension_id_; |
| 80 base::Time time_; | 93 base::Time time_; |
| 81 APIActionType verb_; | 94 Type type_; |
| 82 APITargetType target_; | 95 Verb verb_; |
| 96 Target target_; |
| 83 std::string api_call_; | 97 std::string api_call_; |
| 84 std::string extra_; | 98 std::string extra_; |
| 85 | 99 |
| 86 DISALLOW_COPY_AND_ASSIGN(APIAction); | 100 DISALLOW_COPY_AND_ASSIGN(APIAction); |
| 87 }; | 101 }; |
| 88 | 102 |
| 89 } // namespace | 103 } // namespace |
| 90 | 104 |
| 91 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ | 105 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ |
| 92 | |
| OLD | NEW |