| 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_ACTIVITY_ACTIONS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/common/extensions/api/activity_log_private.h" | 12 #include "chrome/common/extensions/api/activity_log_private.h" |
| 13 #include "sql/connection.h" | 13 #include "sql/connection.h" |
| 14 #include "sql/statement.h" | 14 #include "sql/statement.h" |
| 15 #include "sql/transaction.h" | 15 #include "sql/transaction.h" |
| 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 // This is the interface for extension actions that are to be recorded in | 20 // This is the interface for extension actions that are to be recorded in |
| 20 // the activity log. | 21 // the activity log. |
| 21 class Action : public base::RefCountedThreadSafe<Action> { | 22 class Action : public base::RefCountedThreadSafe<Action> { |
| 22 public: | 23 public: |
| 23 static const char* kTableBasicFields; | 24 // Types of log entries that can be stored. The numeric values are stored in |
| 24 | 25 // the database, so keep them stable. Append values only. |
| 25 // Initialize the table for a given action type. | 26 enum ActionType { |
| 26 static bool InitializeTableInternal(sql::Connection* db); | 27 ACTION_API_CALL = 0, |
| 28 ACTION_API_EVENT = 1, |
| 29 ACTION_API_BLOCKED = 2, |
| 30 ACTION_CONTENT_SCRIPT = 3, |
| 31 ACTION_DOM_ACCESS = 4, |
| 32 ACTION_DOM_EVENT = 5, |
| 33 ACTION_DOM_XHR = 6, |
| 34 ACTION_WEB_REQUEST = 7, |
| 35 }; |
| 27 | 36 |
| 28 // Record the action in the database. | 37 // Record the action in the database. |
| 29 virtual bool Record(sql::Connection* db) = 0; | 38 virtual bool Record(sql::Connection* db) = 0; |
| 30 | 39 |
| 31 // Flatten the activity's type-specific fields into an ExtensionActivity. | 40 // Flatten the activity's type-specific fields into an ExtensionActivity. |
| 32 virtual scoped_ptr<api::activity_log_private::ExtensionActivity> | 41 virtual scoped_ptr<api::activity_log_private::ExtensionActivity> |
| 33 ConvertToExtensionActivity() = 0; | 42 ConvertToExtensionActivity() = 0; |
| 34 | 43 |
| 35 // Print an action as a regular string for debugging purposes. | 44 // Print an action as a regular string for debugging purposes. |
| 36 virtual std::string PrintForDebug() = 0; | 45 virtual std::string PrintForDebug() = 0; |
| 37 | 46 |
| 38 const std::string& extension_id() const { return extension_id_; } | 47 const std::string& extension_id() const { return extension_id_; } |
| 39 const base::Time& time() const { return time_; } | 48 const base::Time& time() const { return time_; } |
| 40 api::activity_log_private::ExtensionActivity::ActivityType activity_type() | 49 api::activity_log_private::ExtensionActivity::ActivityType activity_type() |
| 41 const { return activity_type_; } | 50 const { return activity_type_; } |
| 42 | 51 |
| 43 protected: | 52 protected: |
| 44 Action(const std::string& extension_id, | 53 Action(const std::string& extension_id, |
| 45 const base::Time& time, | 54 const base::Time& time, |
| 46 api::activity_log_private::ExtensionActivity::ActivityType type); | 55 api::activity_log_private::ExtensionActivity::ActivityType type); |
| 47 virtual ~Action() {} | 56 virtual ~Action() {} |
| 48 | 57 |
| 49 // Initialize the table for a given action type. | |
| 50 // The content_fields array should list the names of all of the columns in | |
| 51 // the database. The field_types should specify the types of the corresponding | |
| 52 // columns (e.g., INTEGER or LONGVARCHAR). There should be the same number of | |
| 53 // field_types as content_fields, since the two arrays should correspond. | |
| 54 static bool InitializeTableInternal(sql::Connection* db, | |
| 55 const char* table_name, | |
| 56 const char* content_fields[], | |
| 57 const char* field_types[], | |
| 58 const int num_content_fields); | |
| 59 | |
| 60 private: | 58 private: |
| 61 friend class base::RefCountedThreadSafe<Action>; | 59 friend class base::RefCountedThreadSafe<Action>; |
| 62 | 60 |
| 63 std::string extension_id_; | 61 std::string extension_id_; |
| 64 base::Time time_; | 62 base::Time time_; |
| 65 api::activity_log_private::ExtensionActivity::ActivityType activity_type_; | 63 api::activity_log_private::ExtensionActivity::ActivityType activity_type_; |
| 66 | 64 |
| 67 DISALLOW_COPY_AND_ASSIGN(Action); | 65 DISALLOW_COPY_AND_ASSIGN(Action); |
| 68 }; | 66 }; |
| 69 | 67 |
| 68 // TODO(mvrable): This is a temporary class used to represent Actions which |
| 69 // have been loaded from the SQLite database. Soon the entire Action hierarchy |
| 70 // will be flattened out as the type-specific classes are eliminated, at which |
| 71 // time some of the logic here will be moved. |
| 72 class WatchdogAction : public Action { |
| 73 public: |
| 74 WatchdogAction(const std::string& extension_id, |
| 75 const base::Time& time, |
| 76 const ActionType action_type, |
| 77 const std::string& api_name, // full method name |
| 78 scoped_ptr<ListValue> args, // the argument list |
| 79 const GURL& page_url, // page the action occurred on |
| 80 const GURL& arg_url, // URL extracted from the argument list |
| 81 scoped_ptr<DictionaryValue> other); // any extra logging info |
| 82 |
| 83 virtual bool Record(sql::Connection* db) OVERRIDE; |
| 84 virtual scoped_ptr<api::activity_log_private::ExtensionActivity> |
| 85 ConvertToExtensionActivity() OVERRIDE; |
| 86 virtual std::string PrintForDebug() OVERRIDE; |
| 87 |
| 88 protected: |
| 89 virtual ~WatchdogAction(); |
| 90 |
| 91 private: |
| 92 ActionType action_type_; |
| 93 std::string api_name_; |
| 94 scoped_ptr<ListValue> args_; |
| 95 GURL page_url_; |
| 96 GURL arg_url_; |
| 97 scoped_ptr<DictionaryValue> other_; |
| 98 }; |
| 99 |
| 70 } // namespace extensions | 100 } // namespace extensions |
| 71 | 101 |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_ | 102 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_ |
| 73 | 103 |
| OLD | NEW |