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

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: 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(
38 : testing_clock_(NULL), 38 ActivityDatabaseCallbacks* callbacks)
39 : policy_callbacks_(callbacks),
40 testing_clock_(NULL),
39 valid_db_(false), 41 valid_db_(false),
40 already_closed_(false), 42 already_closed_(false),
41 did_init_(false) { 43 did_init_(false) {
42 // We don't batch commits when in testing mode. 44 // We don't batch commits when in testing mode.
43 batch_mode_ = !(CommandLine::ForCurrentProcess()-> 45 batch_mode_ = !(CommandLine::ForCurrentProcess()->
44 HasSwitch(switches::kEnableExtensionActivityLogTesting)); 46 HasSwitch(switches::kEnableExtensionActivityLogTesting));
45 } 47 }
46 48
47 ActivityDatabase::~ActivityDatabase() {} 49 ActivityDatabase::~ActivityDatabase() {}
48 50
(...skipping 20 matching lines...) Expand all
69 if (!committer.Begin()) 71 if (!committer.Begin())
70 return LogInitFailure(); 72 return LogInitFailure();
71 73
72 #if defined(OS_MACOSX) 74 #if defined(OS_MACOSX)
73 // Exclude the database from backups. 75 // Exclude the database from backups.
74 base::mac::SetFileBackupExclusion(db_name); 76 base::mac::SetFileBackupExclusion(db_name);
75 #endif 77 #endif
76 78
77 db_.Preload(); 79 db_.Preload();
78 80
79 // Create the DOMAction database. 81 if (!policy_callbacks_->DatabaseInitCallback(&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(); 82 return LogInitFailure();
90 83
91 sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; 84 sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
92 if (stat != sql::INIT_OK) 85 if (stat != sql::INIT_OK)
93 return LogInitFailure(); 86 return LogInitFailure();
94 87
95 valid_db_ = true; 88 valid_db_ = true;
96 timer_.Start(FROM_HERE, 89 timer_.Start(FROM_HERE,
97 base::TimeDelta::FromMinutes(2), 90 base::TimeDelta::FromMinutes(2),
98 this, 91 this,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 207 }
215 208
216 void ActivityDatabase::Close() { 209 void ActivityDatabase::Close() {
217 timer_.Stop(); 210 timer_.Stop();
218 if (!already_closed_) { 211 if (!already_closed_) {
219 RecordBatchedActions(); 212 RecordBatchedActions();
220 db_.reset_error_callback(); 213 db_.reset_error_callback();
221 } 214 }
222 valid_db_ = false; 215 valid_db_ = false;
223 already_closed_ = true; 216 already_closed_ = true;
217 // Call DatabaseCloseCallback() just before deleting the ActivityDatabase
218 // itself--these two objects should have the same lifetime.
219 policy_callbacks_->DatabaseCloseCallback();
224 delete this; 220 delete this;
225 } 221 }
226 222
227 void ActivityDatabase::HardFailureClose() { 223 void ActivityDatabase::HardFailureClose() {
228 if (already_closed_) return; 224 if (already_closed_) return;
229 valid_db_ = false; 225 valid_db_ = false;
230 timer_.Stop(); 226 timer_.Stop();
231 db_.reset_error_callback(); 227 db_.reset_error_callback();
232 db_.RazeAndClose(); 228 db_.RazeAndClose();
233 already_closed_ = true; 229 already_closed_ = true;
(...skipping 26 matching lines...) Expand all
260 256
261 void ActivityDatabase::SetTimerForTesting(int ms) { 257 void ActivityDatabase::SetTimerForTesting(int ms) {
262 timer_.Stop(); 258 timer_.Stop();
263 timer_.Start(FROM_HERE, 259 timer_.Start(FROM_HERE,
264 base::TimeDelta::FromMilliseconds(ms), 260 base::TimeDelta::FromMilliseconds(ms),
265 this, 261 this,
266 &ActivityDatabase::RecordBatchedActionsWhileTesting); 262 &ActivityDatabase::RecordBatchedActionsWhileTesting);
267 } 263 }
268 264
269 } // namespace extensions 265 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698