Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_actions.h

Issue 19234003: Extension activity log database refactoring (step 2) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
25 // Initialize the table for a given action type. 26 enum ActionType {
26 static bool InitializeTableInternal(sql::Connection* db); 27 ACTION_WEB_REQUEST = 0,
28 ACTION_CONTENT_SCRIPT = 1,
29 ACTION_API_BLOCKED = 2,
30 ACTION_DOM_EVENT = 3,
31 ACTION_DOM_XHR = 4,
32 ACTION_DOM_OTHER = 5,
33 ACTION_API = 6,
34 ACTION_API_URL = 7,
35 ACTION_API_EVENT = 8,
36 };
27 37
28 // Record the action in the database. 38 // Record the action in the database.
29 virtual bool Record(sql::Connection* db) = 0; 39 virtual bool Record(sql::Connection* db) = 0;
30 40
31 // Flatten the activity's type-specific fields into an ExtensionActivity. 41 // Flatten the activity's type-specific fields into an ExtensionActivity.
32 virtual scoped_ptr<api::activity_log_private::ExtensionActivity> 42 virtual scoped_ptr<api::activity_log_private::ExtensionActivity>
33 ConvertToExtensionActivity() = 0; 43 ConvertToExtensionActivity() = 0;
34 44
35 // Print an action as a regular string for debugging purposes. 45 // Print an action as a regular string for debugging purposes.
36 virtual std::string PrintForDebug() = 0; 46 virtual std::string PrintForDebug() = 0;
37 47
38 const std::string& extension_id() const { return extension_id_; } 48 const std::string& extension_id() const { return extension_id_; }
39 const base::Time& time() const { return time_; } 49 const base::Time& time() const { return time_; }
40 api::activity_log_private::ExtensionActivity::ActivityType activity_type() 50 api::activity_log_private::ExtensionActivity::ActivityType activity_type()
41 const { return activity_type_; } 51 const { return activity_type_; }
42 52
43 protected: 53 protected:
44 Action(const std::string& extension_id, 54 Action(const std::string& extension_id,
45 const base::Time& time, 55 const base::Time& time,
46 api::activity_log_private::ExtensionActivity::ActivityType type); 56 api::activity_log_private::ExtensionActivity::ActivityType type);
47 virtual ~Action() {} 57 virtual ~Action() {}
48 58
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: 59 private:
61 friend class base::RefCountedThreadSafe<Action>; 60 friend class base::RefCountedThreadSafe<Action>;
62 61
63 std::string extension_id_; 62 std::string extension_id_;
64 base::Time time_; 63 base::Time time_;
65 api::activity_log_private::ExtensionActivity::ActivityType activity_type_; 64 api::activity_log_private::ExtensionActivity::ActivityType activity_type_;
66 65
67 DISALLOW_COPY_AND_ASSIGN(Action); 66 DISALLOW_COPY_AND_ASSIGN(Action);
68 }; 67 };
69 68
69 // This is a temporary class used to represent Actions which have been loaded
70 // from the SQLite database. Soon the entire Action hierarchy will be
71 // flattened out as the type-specific classes are eliminated, at which time
72 // some of the logic here will be moved.
73 class WatchdogAction : public Action {
felt 2013/07/16 06:44:03 Is this named WatchdogAction specifically b/c it s
mvrable 2013/07/16 18:12:35 Not any particularly good reason, I just needed an
74 public:
75 WatchdogAction(const std::string& extension_id,
76 const base::Time& time,
77 const ActionType action_type,
78 const std::string& api_name, // full method name
79 scoped_ptr<ListValue> args, // the argument list
80 const GURL& page_url, // page the action occurred on
81 const GURL& arg_url, // URL extracted from the argument list
82 scoped_ptr<DictionaryValue> other); // any extra logging info
83
84 virtual bool Record(sql::Connection* db) OVERRIDE;
85 virtual scoped_ptr<api::activity_log_private::ExtensionActivity>
86 ConvertToExtensionActivity() OVERRIDE;
87 virtual std::string PrintForDebug() OVERRIDE;
88
89 private:
90 ActionType action_type_;
91 std::string api_name_;
92 scoped_ptr<ListValue> args_;
93 GURL page_url_;
94 GURL arg_url_;
95 scoped_ptr<DictionaryValue> other_;
96 };
97
70 } // namespace extensions 98 } // namespace extensions
71 99
72 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_ 100 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_ACTIONS_H_
73 101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698