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

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

Issue 19234003: Extension activity log database refactoring (step 2) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address some reviewer comments 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_DATABASE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 // Need to call Init to actually use the ActivityDatabase. The Delegate 91 // Need to call Init to actually use the ActivityDatabase. The Delegate
92 // provides hooks for an ActivityLogPolicy to control the database schema and 92 // provides hooks for an ActivityLogPolicy to control the database schema and
93 // reads/writes. 93 // reads/writes.
94 explicit ActivityDatabase(Delegate* delegate); 94 explicit ActivityDatabase(Delegate* delegate);
95 95
96 // Opens the DB. This invokes OnDatabaseInit in the delegate to create or 96 // Opens the DB. This invokes OnDatabaseInit in the delegate to create or
97 // update the database schema if needed. 97 // update the database schema if needed.
98 void Init(const base::FilePath& db_name); 98 void Init(const base::FilePath& db_name);
99 99
100 // The ActivityLog should call this to kill the ActivityDatabase. 100 // An ActivityLogPolicy should call this to kill the ActivityDatabase.
101 void Close(); 101 void Close();
102 102
103 // Record a DOMAction in the database.
104 void RecordDOMAction(scoped_refptr<DOMAction> action);
105
106 // Record an APIAction in the database.
107 void RecordAPIAction(scoped_refptr<APIAction> action);
108
109 // Record a BlockedAction in the database.
110 void RecordBlockedAction(scoped_refptr<BlockedAction> action);
111
112 // Record an Action in the database. 103 // Record an Action in the database.
113 void RecordAction(scoped_refptr<Action> action); 104 void RecordAction(scoped_refptr<Action> action);
114 105
115 // Turns off batch I/O writing mode. This should only be used in unit tests, 106 // Turns off batch I/O writing mode. This should only be used in unit tests,
116 // browser tests, or in our special --enable-extension-activity-log-testing 107 // browser tests, or in our special --enable-extension-activity-log-testing
117 // policy state. 108 // policy state.
118 void SetBatchModeForTesting(bool batch_mode); 109 void SetBatchModeForTesting(bool batch_mode);
119 110
120 // Gets all actions for a given extension for the specified day. 0 = today, 111 // Gets all actions for a given extension for the specified day. 0 = today,
121 // 1 = yesterday, etc. Only returns 1 day at a time. Actions are sorted from 112 // 1 = yesterday, etc. Only returns 1 day at a time. Actions are sorted from
122 // newest to oldest. 113 // newest to oldest.
123 scoped_ptr<ActionVector> GetActions(const std::string& extension_id, 114 scoped_ptr<ActionVector> GetActions(const std::string& extension_id,
124 const int days_ago); 115 const int days_ago);
125 116
126 bool is_db_valid() const { return valid_db_; } 117 bool is_db_valid() const { return valid_db_; }
127 118
119 // A helper method for initializing or upgrading a database table. The
120 // content_fields array should list the names of all of the columns in the
121 // database. The field_types should specify the types of the corresponding
122 // columns (e.g., INTEGER or LONGVARCHAR). There should be the same number of
123 // field_types as content_fields, since the two arrays should correspond.
124 static bool InitializeTable(sql::Connection* db,
125 const char* table_name,
126 const char* content_fields[],
127 const char* field_types[],
128 const int num_content_fields);
129
128 private: 130 private:
129 // This should never be invoked by another class. Use Close() to order a 131 // This should never be invoked by another class. Use Close() to order a
130 // suicide. 132 // suicide.
131 virtual ~ActivityDatabase(); 133 virtual ~ActivityDatabase();
132 134
133 // Used by the Init() method as a convenience for handling a failied 135 // Used by the Init() method as a convenience for handling a failed database
134 // database initialization attempt. Prints an error and puts us in the soft 136 // initialization attempt. Prints an error and puts us in the soft failure
135 // failure state. 137 // state.
136 void LogInitFailure(); 138 void LogInitFailure();
137 139
138 sql::InitStatus InitializeTable(const char* table_name,
139 const char* table_structure);
140
141 // When we're in batched mode (which is on by default), we write to the db 140 // When we're in batched mode (which is on by default), we write to the db
142 // every X minutes instead of on every API call. This prevents the annoyance 141 // every X minutes instead of on every API call. This prevents the annoyance
143 // of writing to disk multiple times a second. 142 // of writing to disk multiple times a second.
144 void RecordBatchedActions(); 143 void RecordBatchedActions();
145 144
146 // If an error is unrecoverable or occurred while we were trying to close 145 // If an error is unrecoverable or occurred while we were trying to close
147 // the database properly, we take "emergency" actions: break any outstanding 146 // the database properly, we take "emergency" actions: break any outstanding
148 // transactions, raze the database, and close. When next opened, the 147 // transactions, raze the database, and close. When next opened, the
149 // database will be empty. 148 // database will be empty.
150 void HardFailureClose(); 149 void HardFailureClose();
(...skipping 25 matching lines...) Expand all
176 bool already_closed_; 175 bool already_closed_;
177 bool did_init_; 176 bool did_init_;
178 177
179 FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOff); 178 FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOff);
180 FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOn); 179 FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOn);
181 DISALLOW_COPY_AND_ASSIGN(ActivityDatabase); 180 DISALLOW_COPY_AND_ASSIGN(ActivityDatabase);
182 }; 181 };
183 182
184 } // namespace extensions 183 } // namespace extensions
185 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ 184 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698