| 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 // A policy for storing activity log data to a database that performs | 5 // A policy for storing activity log data to a database that performs |
| 6 // aggregation to reduce the size of the database. The database layout is | 6 // aggregation to reduce the size of the database. The database layout is |
| 7 // nearly the same as FullStreamUIPolicy, which stores a complete log, with a | 7 // nearly the same as FullStreamUIPolicy, which stores a complete log, with a |
| 8 // few changes: | 8 // few changes: |
| 9 // - a "count" column is added to track how many log records were merged | 9 // - a "count" column is added to track how many log records were merged |
| 10 // together into this row | 10 // together into this row |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 {Action::ACTION_API_CALL, "types.ChromeSetting.clear"}, | 80 {Action::ACTION_API_CALL, "types.ChromeSetting.clear"}, |
| 81 {Action::ACTION_API_CALL, "types.ChromeSetting.get"}, | 81 {Action::ACTION_API_CALL, "types.ChromeSetting.get"}, |
| 82 {Action::ACTION_API_CALL, "types.ChromeSetting.set"}, | 82 {Action::ACTION_API_CALL, "types.ChromeSetting.set"}, |
| 83 {Action::ACTION_CONTENT_SCRIPT, ""}, | 83 {Action::ACTION_CONTENT_SCRIPT, ""}, |
| 84 {Action::ACTION_DOM_ACCESS, "Document.createElement"}, | 84 {Action::ACTION_DOM_ACCESS, "Document.createElement"}, |
| 85 {Action::ACTION_DOM_ACCESS, "Document.createElementNS"}, | 85 {Action::ACTION_DOM_ACCESS, "Document.createElementNS"}, |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // Columns in the main database table. See the file-level comment for a | 88 // Columns in the main database table. See the file-level comment for a |
| 89 // discussion of how data is stored and the meanings of the _x columns. | 89 // discussion of how data is stored and the meanings of the _x columns. |
| 90 const char* kTableContentFields[] = { | 90 const char* const kTableContentFields[] = { |
| 91 "count", "extension_id_x", "time", "action_type", "api_name_x", "args_x", | 91 "count", "extension_id_x", "time", "action_type", "api_name_x", "args_x", |
| 92 "page_url_x", "page_title_x", "arg_url_x", "other_x"}; | 92 "page_url_x", "page_title_x", "arg_url_x", "other_x"}; |
| 93 const char* kTableFieldTypes[] = { | 93 const char* const kTableFieldTypes[] = { |
| 94 "INTEGER NOT NULL DEFAULT 1", "INTEGER NOT NULL", "INTEGER", "INTEGER", | 94 "INTEGER NOT NULL DEFAULT 1", "INTEGER NOT NULL", "INTEGER", "INTEGER", |
| 95 "INTEGER", "INTEGER", "INTEGER", "INTEGER", "INTEGER", | 95 "INTEGER", "INTEGER", "INTEGER", "INTEGER", "INTEGER", |
| 96 "INTEGER"}; | 96 "INTEGER"}; |
| 97 | 97 |
| 98 // Miscellaneous SQL commands for initializing the database; these should be | 98 // Miscellaneous SQL commands for initializing the database; these should be |
| 99 // idempotent. | 99 // idempotent. |
| 100 static const char kPolicyMiscSetup[] = | 100 static const char kPolicyMiscSetup[] = |
| 101 // The activitylog_uncompressed view performs string lookups for simpler | 101 // The activitylog_uncompressed view performs string lookups for simpler |
| 102 // access to the log data. | 102 // access to the log data. |
| 103 "DROP VIEW IF EXISTS activitylog_uncompressed;\n" | 103 "DROP VIEW IF EXISTS activitylog_uncompressed;\n" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 "DELETE FROM url_ids WHERE id NOT IN\n" | 147 "DELETE FROM url_ids WHERE id NOT IN\n" |
| 148 "(SELECT page_url_x FROM activitylog_compressed\n" | 148 "(SELECT page_url_x FROM activitylog_compressed\n" |
| 149 " WHERE page_url_x IS NOT NULL\n" | 149 " WHERE page_url_x IS NOT NULL\n" |
| 150 " UNION SELECT arg_url_x FROM activitylog_compressed\n" | 150 " UNION SELECT arg_url_x FROM activitylog_compressed\n" |
| 151 " WHERE arg_url_x IS NOT NULL)"; | 151 " WHERE arg_url_x IS NOT NULL)"; |
| 152 | 152 |
| 153 } // namespace | 153 } // namespace |
| 154 | 154 |
| 155 namespace extensions { | 155 namespace extensions { |
| 156 | 156 |
| 157 const char* CountingPolicy::kTableName = "activitylog_compressed"; | 157 const char CountingPolicy::kTableName[] = "activitylog_compressed"; |
| 158 const char* CountingPolicy::kReadViewName = "activitylog_uncompressed"; | 158 const char CountingPolicy::kReadViewName[] = "activitylog_uncompressed"; |
| 159 | 159 |
| 160 CountingPolicy::CountingPolicy(Profile* profile) | 160 CountingPolicy::CountingPolicy(Profile* profile) |
| 161 : ActivityLogDatabasePolicy( | 161 : ActivityLogDatabasePolicy( |
| 162 profile, | 162 profile, |
| 163 base::FilePath(chrome::kExtensionActivityLogFilename)), | 163 base::FilePath(chrome::kExtensionActivityLogFilename)), |
| 164 string_table_("string_ids"), | 164 string_table_("string_ids"), |
| 165 url_table_("url_ids"), | 165 url_table_("url_ids"), |
| 166 retention_time_(base::TimeDelta::FromHours(60)) { | 166 retention_time_(base::TimeDelta::FromHours(60)) { |
| 167 for (size_t i = 0; i < arraysize(kAlwaysLog); i++) { | 167 for (size_t i = 0; i < arraysize(kAlwaysLog); i++) { |
| 168 api_arg_whitelist_.insert( | 168 api_arg_whitelist_.insert( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 queued_entry->first->set_time( | 223 queued_entry->first->set_time( |
| 224 max(queued_entry->first->time(), action->time())); | 224 max(queued_entry->first->time(), action->time())); |
| 225 queued_entry->second++; | 225 queued_entry->second++; |
| 226 } | 226 } |
| 227 activity_database()->AdviseFlush(queued_actions_.size()); | 227 activity_database()->AdviseFlush(queued_actions_.size()); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool CountingPolicy::FlushDatabase(sql::Connection* db) { | 231 bool CountingPolicy::FlushDatabase(sql::Connection* db) { |
| 232 // Columns that must match exactly for database rows to be coalesced. | 232 // Columns that must match exactly for database rows to be coalesced. |
| 233 static const char* matched_columns[] = { | 233 static const char* const matched_columns[] = { |
| 234 "extension_id_x", "action_type", "api_name_x", "args_x", "page_url_x", | 234 "extension_id_x", "action_type", "api_name_x", "args_x", "page_url_x", |
| 235 "page_title_x", "arg_url_x", "other_x"}; | 235 "page_title_x", "arg_url_x", "other_x"}; |
| 236 ActionQueue queue; | 236 ActionQueue queue; |
| 237 queue.swap(queued_actions_); | 237 queue.swap(queued_actions_); |
| 238 | 238 |
| 239 // Whether to clean old records out of the activity log database. Do this | 239 // Whether to clean old records out of the activity log database. Do this |
| 240 // much less frequently than database flushes since it is expensive, but | 240 // much less frequently than database flushes since it is expensive, but |
| 241 // always check on the first database flush (since there might be a large | 241 // always check on the first database flush (since there might be a large |
| 242 // amount of data to clear). | 242 // amount of data to clear). |
| 243 bool clean_database = (last_database_cleaning_time_.is_null() || | 243 bool clean_database = (last_database_cleaning_time_.is_null() || |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 return true; | 792 return true; |
| 793 } | 793 } |
| 794 | 794 |
| 795 void CountingPolicy::Close() { | 795 void CountingPolicy::Close() { |
| 796 // The policy object should have never been created if there's no DB thread. | 796 // The policy object should have never been created if there's no DB thread. |
| 797 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 797 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
| 798 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 798 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
| 799 } | 799 } |
| 800 | 800 |
| 801 } // namespace extensions | 801 } // namespace extensions |
| OLD | NEW |