| 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::OnDatabaseInit(sql::Connection* db) { |
| 53 if (!DOMAction::InitializeTable(db)) |
| 54 return false; |
| 55 if (!APIAction::InitializeTable(db)) |
| 56 return false; |
| 57 if (!BlockedAction::InitializeTable(db)) |
| 58 return false; |
| 59 |
| 60 return true; |
| 61 } |
| 62 |
| 63 void FullStreamUIPolicy::OnDatabaseClose() { |
| 64 delete this; |
| 65 } |
| 66 |
| 67 void FullStreamUIPolicy::Close() { |
| 53 // The policy object should have never been created if there's no DB thread. | 68 // The policy object should have never been created if there's no DB thread. |
| 54 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 69 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
| 55 ScheduleAndForget(db_, &ActivityDatabase::Close); | 70 ScheduleAndForget(db_, &ActivityDatabase::Close); |
| 56 } | 71 } |
| 57 | 72 |
| 58 // Get data as a set of key-value pairs. The keys are policy-specific. | 73 // Get data as a set of key-value pairs. The keys are policy-specific. |
| 59 void FullStreamUIPolicy::ReadData( | 74 void FullStreamUIPolicy::ReadData( |
| 60 const std::string& extension_id, | 75 const std::string& extension_id, |
| 61 const int day, | 76 const int day, |
| 62 const Callback | 77 const Callback |
| 63 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) | 78 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) |
| 64 const { | 79 const { |
| 65 BrowserThread::PostTaskAndReplyWithResult( | 80 BrowserThread::PostTaskAndReplyWithResult( |
| 66 BrowserThread::DB, | 81 BrowserThread::DB, |
| 67 FROM_HERE, | 82 FROM_HERE, |
| 68 base::Bind(&ActivityDatabase::GetActions, Unretained(db_), | 83 base::Bind(&ActivityDatabase::GetActions, Unretained(db_), |
| 69 extension_id, day), | 84 extension_id, day), |
| 70 callback); | 85 callback); |
| 71 } | 86 } |
| 72 | 87 |
| 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 | 88 std::string FullStreamUIPolicy::GetKey(ActivityLogPolicy::KeyType key_ty) const |
| 79 { | 89 { |
| 80 switch (key_ty) { | 90 switch (key_ty) { |
| 81 case PARAM_KEY_REASON: | 91 case PARAM_KEY_REASON: |
| 82 return std::string(kKeyReason); | 92 return std::string(kKeyReason); |
| 83 case PARAM_KEY_DOM_ACTION: | 93 case PARAM_KEY_DOM_ACTION: |
| 84 return std::string(kKeyDomainAction); | 94 return std::string(kKeyDomainAction); |
| 85 case PARAM_KEY_URL_TITLE: | 95 case PARAM_KEY_URL_TITLE: |
| 86 return std::string(kKeyURLTitle); | 96 return std::string(kKeyURLTitle); |
| 87 case PARAM_KEY_DETAILS_STRING: | 97 case PARAM_KEY_DETAILS_STRING: |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 break; | 223 break; |
| 214 } | 224 } |
| 215 default: | 225 default: |
| 216 NOTREACHED(); | 226 NOTREACHED(); |
| 217 } | 227 } |
| 218 | 228 |
| 219 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); | 229 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); |
| 220 } | 230 } |
| 221 | 231 |
| 222 } // namespace extensions | 232 } // namespace extensions |
| OLD | NEW |