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

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: 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // Need to call Init to actually use the ActivityDatabase. The Delegate 87 // Need to call Init to actually use the ActivityDatabase. The Delegate
88 // provides hooks for an ActivityLogPolicy to control the database schema and 88 // provides hooks for an ActivityLogPolicy to control the database schema and
89 // reads/writes. 89 // reads/writes.
90 explicit ActivityDatabase(Delegate* delegate); 90 explicit ActivityDatabase(Delegate* delegate);
91 91
92 // Opens the DB. This invokes OnDatabaseInit in the delegate to create or 92 // Opens the DB. This invokes OnDatabaseInit in the delegate to create or
93 // update the database schema if needed. 93 // update the database schema if needed.
94 void Init(const base::FilePath& db_name); 94 void Init(const base::FilePath& db_name);
95 95
96 // The ActivityLog should call this to kill the ActivityDatabase. 96 // An ActivityLogPolicy should call this to kill the ActivityDatabase.
97 void Close(); 97 void Close();
98 98
99 void LogInitFailure();
100
101 // Record a DOMction in the database.
102 void RecordDOMAction(scoped_refptr<DOMAction> action);
103
104 // Record a APIAction in the database.
105 void RecordAPIAction(scoped_refptr<APIAction> action);
106
107 // Record a BlockedAction in the database.
108 void RecordBlockedAction(scoped_refptr<BlockedAction> action);
109
110 // Record an Action in the database. 99 // Record an Action in the database.
111 void RecordAction(scoped_refptr<Action> action); 100 void RecordAction(scoped_refptr<Action> action);
112 101
113 // Gets all actions for a given extension for the specified day. 0 = today, 102 // Gets all actions for a given extension for the specified day. 0 = today,
114 // 1 = yesterday, etc. Only returns 1 day at a time. Actions are sorted from 103 // 1 = yesterday, etc. Only returns 1 day at a time. Actions are sorted from
115 // newest to oldest. 104 // newest to oldest.
116 scoped_ptr<std::vector<scoped_refptr<Action> > > GetActions( 105 scoped_ptr<std::vector<scoped_refptr<Action> > > GetActions(
117 const std::string& extension_id, const int days_ago); 106 const std::string& extension_id, const int days_ago);
118 107
119 // Handle errors in database writes. 108 // Handle errors in database writes.
120 void DatabaseErrorCallback(int error, sql::Statement* stmt); 109 void DatabaseErrorCallback(int error, sql::Statement* stmt);
121 110
122 bool is_db_valid() const { return valid_db_; } 111 bool is_db_valid() const { return valid_db_; }
123 112
124 // For unit testing only. 113 // For unit testing only.
125 void SetBatchModeForTesting(bool batch_mode); 114 void SetBatchModeForTesting(bool batch_mode);
126 void SetClockForTesting(base::Clock* clock); 115 void SetClockForTesting(base::Clock* clock);
127 void SetTimerForTesting(int milliseconds); 116 void SetTimerForTesting(int milliseconds);
128 117
118 // A helper method for initializing or upgrading a database table. The
119 // content_fields array should list the names of all of the columns in the
120 // database. The field_types should specify the types of the corresponding
121 // columns (e.g., INTEGER or LONGVARCHAR). There should be the same number of
122 // field_types as content_fields, since the two arrays should correspond.
123 static bool InitializeTable(sql::Connection* db,
124 const char* table_name,
125 const char* content_fields[],
126 const char* field_types[],
127 const int num_content_fields);
128
129 private: 129 private:
130 // This should never be invoked by another class. Use Close() to order a 130 // This should never be invoked by another class. Use Close() to order a
131 // suicide. 131 // suicide.
132 virtual ~ActivityDatabase(); 132 virtual ~ActivityDatabase();
133 133
134 sql::InitStatus InitializeTable(const char* table_name,
135 const char* table_structure);
136
137 // When we're in batched mode (which is on by default), we write to the db 134 // When we're in batched mode (which is on by default), we write to the db
138 // every X minutes instead of on every API call. This prevents the annoyance 135 // every X minutes instead of on every API call. This prevents the annoyance
139 // of writing to disk multiple times a second. 136 // of writing to disk multiple times a second.
140 void StartTimer(); 137 void StartTimer();
141 void RecordBatchedActions(); 138 void RecordBatchedActions();
142 139
140 void LogInitFailure();
141
143 // If an error is unrecoverable or occurred while we were trying to close 142 // If an error is unrecoverable or occurred while we were trying to close
144 // the database properly, we take "emergency" actions: break any outstanding 143 // the database properly, we take "emergency" actions: break any outstanding
145 // transactions, raze the database, and close. When next opened, the 144 // transactions, raze the database, and close. When next opened, the
146 // database will be empty. 145 // database will be empty.
147 void HardFailureClose(); 146 void HardFailureClose();
148 147
149 // Doesn't actually close the DB, but changes bools to prevent further writes 148 // Doesn't actually close the DB, but changes bools to prevent further writes
150 // or changes to it. 149 // or changes to it.
151 void SoftFailureClose(); 150 void SoftFailureClose();
152 151
(...skipping 11 matching lines...) Expand all
164 std::vector<scoped_refptr<Action> > batched_actions_; 163 std::vector<scoped_refptr<Action> > batched_actions_;
165 base::RepeatingTimer<ActivityDatabase> timer_; 164 base::RepeatingTimer<ActivityDatabase> timer_;
166 bool already_closed_; 165 bool already_closed_;
167 bool did_init_; 166 bool did_init_;
168 167
169 DISALLOW_COPY_AND_ASSIGN(ActivityDatabase); 168 DISALLOW_COPY_AND_ASSIGN(ActivityDatabase);
170 }; 169 };
171 170
172 } // namespace extensions 171 } // namespace extensions
173 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ 172 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698