Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(ActivityPolicyCallbacks* callbacks) |
| 38 : testing_clock_(NULL), | 38 : policy_callbacks_(callbacks), |
| 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 Loading... | |
| 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 (!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(); | 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 actions->push_back(action); | 201 actions->push_back(action); |
| 210 } | 202 } |
| 211 // Sort by time (from newest to oldest). | 203 // Sort by time (from newest to oldest). |
| 212 std::sort(actions->begin(), actions->end(), SortActionsByTime); | 204 std::sort(actions->begin(), actions->end(), SortActionsByTime); |
| 213 return actions.Pass(); | 205 return actions.Pass(); |
| 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(); |
|
felt
2013/07/09 22:14:51
Is it going to be a problem to call DatabaseCloseC
mvrable
2013/07/09 23:03:22
I think we want this to happen on the database thr
felt
2013/07/10 00:14:36
OK, can you add a comment to ~ActivityLogPolicy()
mvrable
2013/07/10 17:49:17
Done.
| |
| 212 policy_callbacks_->DatabaseCloseCallback(); | |
|
felt
2013/07/09 22:14:51
Note that if we've hit a HardFailureClose(), alrea
mvrable
2013/07/09 23:03:22
You are right about already_closed_ and HardFailur
| |
| 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; |
| 224 delete this; | 217 delete this; |
| 225 } | 218 } |
| 226 | 219 |
| 227 void ActivityDatabase::HardFailureClose() { | 220 void ActivityDatabase::HardFailureClose() { |
| 228 if (already_closed_) return; | 221 if (already_closed_) return; |
| 229 valid_db_ = false; | 222 valid_db_ = false; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 260 | 253 |
| 261 void ActivityDatabase::SetTimerForTesting(int ms) { | 254 void ActivityDatabase::SetTimerForTesting(int ms) { |
| 262 timer_.Stop(); | 255 timer_.Stop(); |
| 263 timer_.Start(FROM_HERE, | 256 timer_.Start(FROM_HERE, |
| 264 base::TimeDelta::FromMilliseconds(ms), | 257 base::TimeDelta::FromMilliseconds(ms), |
| 265 this, | 258 this, |
| 266 &ActivityDatabase::RecordBatchedActionsWhileTesting); | 259 &ActivityDatabase::RecordBatchedActionsWhileTesting); |
| 267 } | 260 } |
| 268 | 261 |
| 269 } // namespace extensions | 262 } // namespace extensions |
| OLD | NEW |