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

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

Issue 18660004: Extension activity log database refactoring (step 1) (Closed) Base URL: http://git.chromium.org/chromium/src.git@incognito-tests
Patch Set: Delegate renaming and comment cleanup 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <string> 5 #include <string>
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 16 matching lines...) Expand all
27 27
28 bool SortActionsByTime(const scoped_refptr<extensions::Action> a, 28 bool SortActionsByTime(const scoped_refptr<extensions::Action> a,
29 const scoped_refptr<extensions::Action> b) { 29 const scoped_refptr<extensions::Action> b) {
30 return a->time() > b->time(); 30 return a->time() > b->time();
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 namespace extensions { 35 namespace extensions {
36 36
37 ActivityDatabase::ActivityDatabase() 37 ActivityDatabase::ActivityDatabase(ActivityDatabase::Delegate* delegate)
38 : testing_clock_(NULL), 38 : delegate_(delegate),
39 testing_clock_(NULL),
39 valid_db_(false), 40 valid_db_(false),
40 already_closed_(false), 41 already_closed_(false),
41 did_init_(false) { 42 did_init_(false) {
42 // We don't batch commits when in testing mode. 43 // We don't batch commits when in testing mode.
43 batch_mode_ = !(CommandLine::ForCurrentProcess()-> 44 batch_mode_ = !(CommandLine::ForCurrentProcess()->
44 HasSwitch(switches::kEnableExtensionActivityLogTesting)); 45 HasSwitch(switches::kEnableExtensionActivityLogTesting));
45 } 46 }
46 47
47 ActivityDatabase::~ActivityDatabase() {} 48 ActivityDatabase::~ActivityDatabase() {}
48 49
(...skipping 20 matching lines...) Expand all
69 if (!committer.Begin()) 70 if (!committer.Begin())
70 return LogInitFailure(); 71 return LogInitFailure();
71 72
72 #if defined(OS_MACOSX) 73 #if defined(OS_MACOSX)
73 // Exclude the database from backups. 74 // Exclude the database from backups.
74 base::mac::SetFileBackupExclusion(db_name); 75 base::mac::SetFileBackupExclusion(db_name);
75 #endif 76 #endif
76 77
77 db_.Preload(); 78 db_.Preload();
78 79
79 // Create the DOMAction database. 80 if (!delegate_->OnDatabaseInit(&db_))
80 if (!DOMAction::InitializeTable(&db_))
81 return LogInitFailure();
82
83 // Create the APIAction database.
84 if (!APIAction::InitializeTable(&db_))
85 return LogInitFailure();
86
87 // Create the BlockedAction database.
88 if (!BlockedAction::InitializeTable(&db_))
89 return LogInitFailure(); 81 return LogInitFailure();
90 82
91 sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; 83 sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
92 if (stat != sql::INIT_OK) 84 if (stat != sql::INIT_OK)
93 return LogInitFailure(); 85 return LogInitFailure();
94 86
95 valid_db_ = true; 87 valid_db_ = true;
96 timer_.Start(FROM_HERE, 88 timer_.Start(FROM_HERE,
97 base::TimeDelta::FromMinutes(2), 89 base::TimeDelta::FromMinutes(2),
98 this, 90 this,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 206 }
215 207
216 void ActivityDatabase::Close() { 208 void ActivityDatabase::Close() {
217 timer_.Stop(); 209 timer_.Stop();
218 if (!already_closed_) { 210 if (!already_closed_) {
219 RecordBatchedActions(); 211 RecordBatchedActions();
220 db_.reset_error_callback(); 212 db_.reset_error_callback();
221 } 213 }
222 valid_db_ = false; 214 valid_db_ = false;
223 already_closed_ = true; 215 already_closed_ = true;
216 // Call DatabaseCloseCallback() just before deleting the ActivityDatabase
217 // itself--these two objects should have the same lifetime.
218 delegate_->OnDatabaseClose();
224 delete this; 219 delete this;
225 } 220 }
226 221
227 void ActivityDatabase::HardFailureClose() { 222 void ActivityDatabase::HardFailureClose() {
228 if (already_closed_) return; 223 if (already_closed_) return;
229 valid_db_ = false; 224 valid_db_ = false;
230 timer_.Stop(); 225 timer_.Stop();
231 db_.reset_error_callback(); 226 db_.reset_error_callback();
232 db_.RazeAndClose(); 227 db_.RazeAndClose();
233 already_closed_ = true; 228 already_closed_ = true;
(...skipping 26 matching lines...) Expand all
260 255
261 void ActivityDatabase::SetTimerForTesting(int ms) { 256 void ActivityDatabase::SetTimerForTesting(int ms) {
262 timer_.Stop(); 257 timer_.Stop();
263 timer_.Start(FROM_HERE, 258 timer_.Start(FROM_HERE,
264 base::TimeDelta::FromMilliseconds(ms), 259 base::TimeDelta::FromMilliseconds(ms),
265 this, 260 this,
266 &ActivityDatabase::RecordBatchedActionsWhileTesting); 261 &ActivityDatabase::RecordBatchedActionsWhileTesting);
267 } 262 }
268 263
269 } // namespace extensions 264 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698