| 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 |
| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 |
| 45 // Create a new APIAction to describe a successful API call. All | 53 // Create a new APIAction to describe a successful API call. All |
| 46 // parameters are required. | 54 // parameters are required. |
| 47 APIAction(const std::string& extension_id, | 55 APIAction(const std::string& extension_id, |
| 48 const base::Time& time, | 56 const base::Time& time, |
| 57 const APICategory category, // e.g. "CALL" |
| 49 const APIActionType verb, // e.g. "ADDED" | 58 const APIActionType verb, // e.g. "ADDED" |
| 50 const APITargetType target, // e.g. "BOOKMARK" | 59 const APITargetType target, // e.g. "BOOKMARK" |
| 51 const std::string& api_call, // full method signature incl args | 60 const std::string& api_call, // full method signature incl args |
| 52 const std::string& extra); // any extra logging info | 61 const std::string& extra); // any extra logging info |
| 53 | 62 |
| 54 // Record the action in the database. | 63 // Record the action in the database. |
| 55 virtual void Record(sql::Connection* db) OVERRIDE; | 64 virtual void Record(sql::Connection* db) OVERRIDE; |
| 56 | 65 |
| 57 // Print a APIAction with il8n substitutions for display. | 66 // Print a APIAction with il8n substitutions for display. |
| 58 virtual std::string PrettyPrintFori18n() OVERRIDE; | 67 virtual std::string PrettyPrintFori18n() OVERRIDE; |
| 59 | 68 |
| 60 // Print a APIAction as a regular string for debugging purposes. | 69 // Print a APIAction as a regular string for debugging purposes. |
| 61 virtual std::string PrettyPrintForDebug() OVERRIDE; | 70 virtual std::string PrettyPrintForDebug() OVERRIDE; |
| 62 | 71 |
| 63 // Helper methods for recording the values into the db. | 72 // Helper methods for recording the values into the db. |
| 64 const std::string& extension_id() const { return extension_id_; } | 73 const std::string& extension_id() const { return extension_id_; } |
| 65 const base::Time& time() const { return time_; } | 74 const base::Time& time() const { return time_; } |
| 66 const std::string& api_call() const { return api_call_; } | 75 const std::string& api_call() const { return api_call_; } |
| 76 std::string CategoryAsString() const; |
| 67 std::string VerbAsString() const; | 77 std::string VerbAsString() const; |
| 68 std::string TargetAsString() const; | 78 std::string TargetAsString() const; |
| 69 std::string extra() const { return extra_; } | 79 std::string extra() const { return extra_; } |
| 70 | 80 |
| 71 // Helper methods for creating a APIAction. | 81 // Helper methods for creating a APIAction. |
| 82 static APICategory StringAsCategory(const std::string& str); |
| 72 static APIActionType StringAsActionType(const std::string& str); | 83 static APIActionType StringAsActionType(const std::string& str); |
| 73 static APITargetType StringAsTargetType(const std::string& str); | 84 static APITargetType StringAsTargetType(const std::string& str); |
| 74 | 85 |
| 75 protected: | 86 protected: |
| 76 virtual ~APIAction(); | 87 virtual ~APIAction(); |
| 77 | 88 |
| 78 private: | 89 private: |
| 79 std::string extension_id_; | 90 std::string extension_id_; |
| 80 base::Time time_; | 91 base::Time time_; |
| 92 APICategory category_; |
| 81 APIActionType verb_; | 93 APIActionType verb_; |
| 82 APITargetType target_; | 94 APITargetType target_; |
| 83 std::string api_call_; | 95 std::string api_call_; |
| 84 std::string extra_; | 96 std::string extra_; |
| 85 | 97 |
| 86 DISALLOW_COPY_AND_ASSIGN(APIAction); | 98 DISALLOW_COPY_AND_ASSIGN(APIAction); |
| 87 }; | 99 }; |
| 88 | 100 |
| 89 } // namespace | 101 } // namespace |
| 90 | 102 |
| 91 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIONS_H_ |
| 92 | 104 |
| OLD | NEW |