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

Unified Diff: trunk/src/chrome/browser/extensions/activity_log/activity_database.cc

Issue 16756004: Revert 205059 "We were seeing ActivityLog memory leaks and assor..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/chrome/browser/extensions/activity_log/activity_database.cc
===================================================================
--- trunk/src/chrome/browser/extensions/activity_log/activity_database.cc (revision 205306)
+++ trunk/src/chrome/browser/extensions/activity_log/activity_database.cc (working copy)
@@ -13,9 +13,7 @@
#include "base/time/clock.h"
#include "chrome/browser/extensions/activity_log/activity_database.h"
#include "chrome/common/chrome_switches.h"
-#include "sql/error_delegate_util.h"
#include "sql/transaction.h"
-#include "third_party/sqlite/sqlite3.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
@@ -36,9 +34,7 @@
ActivityDatabase::ActivityDatabase()
: testing_clock_(NULL),
- valid_db_(false),
- already_closed_(false),
- did_init_(false) {
+ initialized_(false) {
// We don't batch commits when in testing mode.
batch_mode_ = !(CommandLine::ForCurrentProcess()->
HasSwitch(switches::kEnableExtensionActivityLogTesting));
@@ -46,14 +42,14 @@
ActivityDatabase::~ActivityDatabase() {}
+void ActivityDatabase::SetErrorCallback(
+ const sql::Connection::ErrorCallback& error_callback) {
+ db_.set_error_callback(error_callback);
+}
+
void ActivityDatabase::Init(const base::FilePath& db_name) {
- if (did_init_) return;
- did_init_ = true;
if (BrowserThread::IsMessageLoopValid(BrowserThread::DB))
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
- db_.set_error_callback(
- base::Bind(&ActivityDatabase::DatabaseErrorCallback,
- base::Unretained(this)));
db_.set_page_size(4096);
db_.set_cache_size(32);
@@ -91,7 +87,7 @@
if (stat != sql::INIT_OK)
return LogInitFailure();
- valid_db_ = true;
+ initialized_ = true;
timer_.Start(FROM_HERE,
base::TimeDelta::FromMinutes(2),
this,
@@ -100,30 +96,23 @@
void ActivityDatabase::LogInitFailure() {
LOG(ERROR) << "Couldn't initialize the activity log database.";
- SoftFailureClose();
}
void ActivityDatabase::RecordAction(scoped_refptr<Action> action) {
- if (!valid_db_) return;
- if (batch_mode_) {
- batched_actions_.push_back(action);
- } else {
- if (!action->Record(&db_)) SoftFailureClose();
+ if (initialized_) {
+ if (batch_mode_)
+ batched_actions_.push_back(action);
+ else
+ action->Record(&db_);
}
}
void ActivityDatabase::RecordBatchedActions() {
- if (!valid_db_) return;
- bool failure = false;
std::vector<scoped_refptr<Action> >::size_type i;
for (i = 0; i != batched_actions_.size(); ++i) {
- if (!batched_actions_.at(i)->Record(&db_)) {
- failure = true;
- break;
- }
+ batched_actions_.at(i)->Record(&db_);
}
batched_actions_.clear();
- if (failure) SoftFailureClose();
}
void ActivityDatabase::SetBatchModeForTesting(bool batch_mode) {
@@ -146,7 +135,7 @@
DCHECK_GE(days_ago, 0);
scoped_ptr<std::vector<scoped_refptr<Action> > >
actions(new std::vector<scoped_refptr<Action> >());
- if (!valid_db_)
+ if (!initialized_)
return actions.Pass();
// Compute the time bounds for that day.
base::Time morning_midnight = testing_clock_ ?
@@ -175,7 +164,7 @@
dom_statement.BindString(0, extension_id);
dom_statement.BindInt64(1, early_bound);
dom_statement.BindInt64(2, late_bound);
- while (dom_statement.is_valid() && dom_statement.Step()) {
+ while (dom_statement.Step()) {
scoped_refptr<DOMAction> action = new DOMAction(dom_statement);
actions->push_back(action);
}
@@ -189,7 +178,7 @@
api_statement.BindString(0, extension_id);
api_statement.BindInt64(1, early_bound);
api_statement.BindInt64(2, late_bound);
- while (api_statement.is_valid() && api_statement.Step()) {
+ while (api_statement.Step()) {
scoped_refptr<APIAction> action = new APIAction(api_statement);
actions->push_back(action);
}
@@ -203,7 +192,7 @@
blocked_statement.BindString(0, extension_id);
blocked_statement.BindInt64(1, early_bound);
blocked_statement.BindInt64(2, late_bound);
- while (blocked_statement.is_valid() && blocked_statement.Step()) {
+ while (blocked_statement.Step()) {
scoped_refptr<BlockedAction> action = new BlockedAction(blocked_statement);
actions->push_back(action);
}
@@ -212,42 +201,34 @@
return actions.Pass();
}
+void ActivityDatabase::BeginTransaction() {
+ db_.BeginTransaction();
+}
+
+void ActivityDatabase::CommitTransaction() {
+ db_.CommitTransaction();
+}
+
+void ActivityDatabase::RollbackTransaction() {
+ db_.RollbackTransaction();
+}
+
+bool ActivityDatabase::Raze() {
+ return db_.Raze();
+}
+
void ActivityDatabase::Close() {
timer_.Stop();
- if (!already_closed_) {
- RecordBatchedActions();
- db_.reset_error_callback();
- }
- valid_db_ = false;
- already_closed_ = true;
+ RecordBatchedActions();
+ db_.Close();
delete this;
}
-void ActivityDatabase::HardFailureClose() {
- if (already_closed_) return;
- valid_db_ = false;
+void ActivityDatabase::KillDatabase() {
timer_.Stop();
- db_.reset_error_callback();
db_.RazeAndClose();
- already_closed_ = true;
}
-void ActivityDatabase::SoftFailureClose() {
- valid_db_ = false;
- timer_.Stop();
-}
-
-void ActivityDatabase::DatabaseErrorCallback(int error, sql::Statement* stmt) {
- if (sql::IsErrorCatastrophic(error)) {
- LOG(ERROR) << "Killing the ActivityDatabase due to catastrophic error.";
- HardFailureClose();
- } else if (error != SQLITE_BUSY) {
- // We ignore SQLITE_BUSY errors because they are presumably transient.
- LOG(ERROR) << "Closing the ActivityDatabase due to error.";
- SoftFailureClose();
- }
-}
-
void ActivityDatabase::SetClockForTesting(base::Clock* clock) {
testing_clock_ = clock;
}

Powered by Google App Engine
This is Rietveld 408576698