| 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_ACTIVITY_LOG_BLOCKED_ACTIONS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_BLOCKED_ACTIONS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_BLOCKED_ACTIONS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_BLOCKED_ACTIONS_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 8 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| 11 | 11 |
| 12 // This class describes API calls that ran into permissions or quota problems. | 12 // This class describes API calls that ran into permissions or quota problems. |
| 13 // See APIActions for API calls that succeeded. | 13 // See APIActions for API calls that succeeded. |
| 14 class BlockedAction : public Action { | 14 class BlockedAction : public Action { |
| 15 public: | 15 public: |
| 16 // These values should not be changed. Append any additional values to the |
| 17 // end with sequential numbers. |
| 16 enum Reason { | 18 enum Reason { |
| 17 UNKNOWN, | 19 UNKNOWN = 0, |
| 18 ACCESS_DENIED, | 20 ACCESS_DENIED = 1, |
| 19 QUOTA_EXCEEDED, | 21 QUOTA_EXCEEDED = 2, |
| 20 }; | 22 }; |
| 21 | 23 |
| 22 static const char* kTableName; | 24 static const char* kTableName; |
| 23 static const char* kTableContentFields[]; | 25 static const char* kTableContentFields[]; |
| 26 static const char* kTableFieldTypes[]; |
| 24 | 27 |
| 25 // Create a new database table for storing BlockedActions, or update the | 28 // Create a new database table for storing BlockedActions, or update the |
| 26 // schema if it is out of date. Any existing data is preserved. | 29 // schema if it is out of date. Any existing data is preserved. |
| 27 static bool InitializeTable(sql::Connection* db); | 30 static bool InitializeTable(sql::Connection* db); |
| 28 | 31 |
| 29 // You must supply the id, time, api_call, and reason. | 32 // You must supply the id, time, api_call, and reason. |
| 30 BlockedAction(const std::string& extension_id, | 33 BlockedAction(const std::string& extension_id, |
| 31 const base::Time& time, | 34 const base::Time& time, |
| 32 const std::string& api_call, // the blocked API call | 35 const std::string& api_call, // the blocked API call |
| 33 const std::string& args, // the arguments | 36 const std::string& args, // the arguments |
| 34 const Reason reason, // the reason it's blocked | 37 const Reason reason, // the reason it's blocked |
| 35 const std::string& extra); // any extra logging info | 38 const std::string& extra); // any extra logging info |
| 36 | 39 |
| 37 // Create a new BlockedAction from a database row. | 40 // Create a new BlockedAction from a database row. |
| 38 explicit BlockedAction(const sql::Statement& s); | 41 explicit BlockedAction(const sql::Statement& s); |
| 39 | 42 |
| 40 // Record the action in the database. | 43 // Record the action in the database. |
| 41 virtual void Record(sql::Connection* db) OVERRIDE; | 44 virtual void Record(sql::Connection* db) OVERRIDE; |
| 42 | 45 |
| 43 // Print a BlockedAction as a string for debugging purposes. | 46 // Print a BlockedAction as a string for debugging purposes. |
| 44 virtual std::string PrintForDebug() OVERRIDE; | 47 virtual std::string PrintForDebug() OVERRIDE; |
| 45 | 48 |
| 46 // Helper methods for recording the values into the db. | 49 // Helper methods for recording the values into the db. |
| 47 const std::string& api_call() const { return api_call_; } | 50 const std::string& api_call() const { return api_call_; } |
| 48 const std::string& args() const { return args_; } | 51 const std::string& args() const { return args_; } |
| 49 const std::string& extra() const { return extra_; } | 52 const std::string& extra() const { return extra_; } |
| 50 | 53 |
| 51 // Helper methods for handling the Reason. | 54 // Helper method for debugging. |
| 52 std::string ReasonAsString() const; | 55 std::string ReasonAsString() const; |
| 53 static Reason StringAsReason(const std::string& reason); | |
| 54 | 56 |
| 55 protected: | 57 protected: |
| 56 virtual ~BlockedAction(); | 58 virtual ~BlockedAction(); |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 std::string api_call_; | 61 std::string api_call_; |
| 60 std::string args_; | 62 std::string args_; |
| 61 Reason reason_; | 63 Reason reason_; |
| 62 std::string extra_; | 64 std::string extra_; |
| 63 | 65 |
| 64 DISALLOW_COPY_AND_ASSIGN(BlockedAction); | 66 DISALLOW_COPY_AND_ASSIGN(BlockedAction); |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 } // namespace extensions | 69 } // namespace extensions |
| 68 | 70 |
| 69 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_BLOCKED_ACTIONS_H_ | 71 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_BLOCKED_ACTIONS_H_ |
| 70 | 72 |
| OLD | NEW |