Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/json/json_string_value_serializer.h" | 6 #include "base/json/json_string_value_serializer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "chrome/browser/extensions/activity_log/activity_database.h" | 9 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 10 #include "chrome/browser/extensions/activity_log/api_actions.h" | 10 #include "chrome/browser/extensions/activity_log/api_actions.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 namespace extensions { | 37 namespace extensions { |
| 38 | 38 |
| 39 // TODO(dbabic) This would be a fine error handler for all sql-based policies, | 39 // TODO(dbabic) This would be a fine error handler for all sql-based policies, |
| 40 // so it would make sense to introduce another class in the hierarchy, | 40 // so it would make sense to introduce another class in the hierarchy, |
| 41 // SQLiteBasedPolicy as a super class of FullStreamUIPolicy and move this | 41 // SQLiteBasedPolicy as a super class of FullStreamUIPolicy and move this |
| 42 // error handler (as well as other SQLite-related functionality) there. | 42 // error handler (as well as other SQLite-related functionality) there. |
| 43 | 43 |
| 44 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) | 44 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) |
| 45 : ActivityLogPolicy(profile) { | 45 : ActivityLogPolicy(profile) { |
| 46 db_ = new ActivityDatabase(); | 46 db_ = new ActivityDatabase(this); |
| 47 FilePath database_name = profile_base_path_.Append( | 47 FilePath database_name = profile_base_path_.Append( |
| 48 chrome::kExtensionActivityLogFilename); | 48 chrome::kExtensionActivityLogFilename); |
| 49 ScheduleAndForget(db_, &ActivityDatabase::Init, database_name); | 49 ScheduleAndForget(db_, &ActivityDatabase::Init, database_name); |
| 50 } | 50 } |
| 51 | 51 |
| 52 FullStreamUIPolicy::~FullStreamUIPolicy() { | 52 bool FullStreamUIPolicy::DatabaseInitCallback(sql::Connection* db) { |
| 53 // Create the DOMAction database. | |
|
Matt Perry
2013/07/10 23:19:30
nit: these comments are redundant
mvrable
2013/07/11 17:30:33
Deleted, though all this code will be gone soon in
| |
| 54 if (!DOMAction::InitializeTable(db)) | |
| 55 return false; | |
| 56 | |
| 57 // Create the APIAction database. | |
| 58 if (!APIAction::InitializeTable(db)) | |
| 59 return false; | |
| 60 | |
| 61 // Create the BlockedAction database. | |
| 62 if (!BlockedAction::InitializeTable(db)) | |
| 63 return false; | |
| 64 | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 void FullStreamUIPolicy::DatabaseCloseCallback() { | |
| 69 delete this; | |
| 70 } | |
| 71 | |
| 72 void FullStreamUIPolicy::Close() { | |
| 53 // The policy object should have never been created if there's no DB thread. | 73 // The policy object should have never been created if there's no DB thread. |
| 54 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 74 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
| 55 ScheduleAndForget(db_, &ActivityDatabase::Close); | 75 ScheduleAndForget(db_, &ActivityDatabase::Close); |
| 56 } | 76 } |
| 57 | 77 |
| 58 // Get data as a set of key-value pairs. The keys are policy-specific. | 78 // Get data as a set of key-value pairs. The keys are policy-specific. |
| 59 void FullStreamUIPolicy::ReadData( | 79 void FullStreamUIPolicy::ReadData( |
| 60 const std::string& extension_id, | 80 const std::string& extension_id, |
| 61 const int day, | 81 const int day, |
| 62 const Callback | 82 const Callback |
| 63 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) | 83 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) |
| 64 const { | 84 const { |
| 65 BrowserThread::PostTaskAndReplyWithResult( | 85 BrowserThread::PostTaskAndReplyWithResult( |
| 66 BrowserThread::DB, | 86 BrowserThread::DB, |
| 67 FROM_HERE, | 87 FROM_HERE, |
| 68 base::Bind(&ActivityDatabase::GetActions, Unretained(db_), | 88 base::Bind(&ActivityDatabase::GetActions, Unretained(db_), |
| 69 extension_id, day), | 89 extension_id, day), |
| 70 callback); | 90 callback); |
| 71 } | 91 } |
| 72 | 92 |
| 73 void FullStreamUIPolicy::SetSaveStateOnRequestOnly() { | |
| 74 ScheduleAndForget(db_, &ActivityDatabase::SetBatchModeForTesting, false); | |
| 75 ActivityLogPolicy::SetSaveStateOnRequestOnly(); | |
| 76 } | |
| 77 | |
| 78 std::string FullStreamUIPolicy::GetKey(ActivityLogPolicy::KeyType key_ty) const | 93 std::string FullStreamUIPolicy::GetKey(ActivityLogPolicy::KeyType key_ty) const |
| 79 { | 94 { |
| 80 switch (key_ty) { | 95 switch (key_ty) { |
| 81 case PARAM_KEY_REASON: | 96 case PARAM_KEY_REASON: |
| 82 return std::string(kKeyReason); | 97 return std::string(kKeyReason); |
| 83 case PARAM_KEY_DOM_ACTION: | 98 case PARAM_KEY_DOM_ACTION: |
| 84 return std::string(kKeyDomainAction); | 99 return std::string(kKeyDomainAction); |
| 85 case PARAM_KEY_URL_TITLE: | 100 case PARAM_KEY_URL_TITLE: |
| 86 return std::string(kKeyURLTitle); | 101 return std::string(kKeyURLTitle); |
| 87 case PARAM_KEY_DETAILS_STRING: | 102 case PARAM_KEY_DETAILS_STRING: |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 break; | 228 break; |
| 214 } | 229 } |
| 215 default: | 230 default: |
| 216 NOTREACHED(); | 231 NOTREACHED(); |
| 217 } | 232 } |
| 218 | 233 |
| 219 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); | 234 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); |
| 220 } | 235 } |
| 221 | 236 |
| 222 } // namespace extensions | 237 } // namespace extensions |
| OLD | NEW |