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 28 matching lines...) Expand all Loading... |
39 #include "base/json/json_reader.h" | 39 #include "base/json/json_reader.h" |
40 #include "base/json/json_string_value_serializer.h" | 40 #include "base/json/json_string_value_serializer.h" |
41 #include "base/strings/string_util.h" | 41 #include "base/strings/string_util.h" |
42 #include "base/strings/stringprintf.h" | 42 #include "base/strings/stringprintf.h" |
43 #include "chrome/common/chrome_constants.h" | 43 #include "chrome/common/chrome_constants.h" |
44 | 44 |
45 using content::BrowserThread; | 45 using content::BrowserThread; |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
| 49 using extensions::Action; |
| 50 |
49 // Delay between cleaning passes (to delete old action records) through the | 51 // Delay between cleaning passes (to delete old action records) through the |
50 // database. | 52 // database. |
51 const int kCleaningDelayInHours = 12; | 53 const int kCleaningDelayInHours = 12; |
52 | 54 |
53 // We should log the arguments to these API calls. Be careful when | 55 // We should log the arguments to these API calls. Be careful when |
54 // constructing this whitelist to not keep arguments that might compromise | 56 // constructing this whitelist to not keep arguments that might compromise |
55 // privacy by logging too much data to the activity log. | 57 // privacy by logging too much data to the activity log. |
56 // | 58 // |
57 // TODO(mvrable): The contents of this whitelist should be reviewed and | 59 // TODO(mvrable): The contents of this whitelist should be reviewed and |
58 // expanded as needed. | 60 // expanded as needed. |
59 const char* kAlwaysLog[] = {"extension.connect", "extension.sendMessage", | 61 struct ApiList { |
60 "tabs.executeScript", "tabs.insertCSS"}; | 62 Action::ActionType type; |
| 63 const char* name; |
| 64 }; |
| 65 |
| 66 const ApiList kAlwaysLog[] = { |
| 67 {Action::ACTION_API_CALL, "extension.connect"}, |
| 68 {Action::ACTION_API_CALL, "extension.sendMessage"}, |
| 69 {Action::ACTION_API_CALL, "tabs.executeScript"}, |
| 70 {Action::ACTION_API_CALL, "tabs.insertCSS"}, |
| 71 {Action::ACTION_CONTENT_SCRIPT, ""}, |
| 72 {Action::ACTION_DOM_ACCESS, "XMLHttpRequest.open"}, |
| 73 }; |
61 | 74 |
62 // Columns in the main database table. See the file-level comment for a | 75 // Columns in the main database table. See the file-level comment for a |
63 // discussion of how data is stored and the meanings of the _x columns. | 76 // discussion of how data is stored and the meanings of the _x columns. |
64 const char* kTableContentFields[] = { | 77 const char* kTableContentFields[] = { |
65 "count", "extension_id_x", "time", "action_type", "api_name_x", "args_x", | 78 "count", "extension_id_x", "time", "action_type", "api_name_x", "args_x", |
66 "page_url_x", "page_title_x", "arg_url_x", "other_x"}; | 79 "page_url_x", "page_title_x", "arg_url_x", "other_x"}; |
67 const char* kTableFieldTypes[] = { | 80 const char* kTableFieldTypes[] = { |
68 "INTEGER NOT NULL DEFAULT 1", "INTEGER NOT NULL", "INTEGER", "INTEGER", | 81 "INTEGER NOT NULL DEFAULT 1", "INTEGER NOT NULL", "INTEGER", "INTEGER", |
69 "INTEGER", "INTEGER", "INTEGER", "INTEGER", "INTEGER", | 82 "INTEGER", "INTEGER", "INTEGER", "INTEGER", "INTEGER", |
70 "INTEGER"}; | 83 "INTEGER"}; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 const char* CountingPolicy::kReadViewName = "activitylog_uncompressed"; | 144 const char* CountingPolicy::kReadViewName = "activitylog_uncompressed"; |
132 | 145 |
133 CountingPolicy::CountingPolicy(Profile* profile) | 146 CountingPolicy::CountingPolicy(Profile* profile) |
134 : ActivityLogDatabasePolicy( | 147 : ActivityLogDatabasePolicy( |
135 profile, | 148 profile, |
136 base::FilePath(chrome::kExtensionActivityLogFilename)), | 149 base::FilePath(chrome::kExtensionActivityLogFilename)), |
137 string_table_("string_ids"), | 150 string_table_("string_ids"), |
138 url_table_("url_ids"), | 151 url_table_("url_ids"), |
139 retention_time_(base::TimeDelta::FromHours(60)) { | 152 retention_time_(base::TimeDelta::FromHours(60)) { |
140 for (size_t i = 0; i < arraysize(kAlwaysLog); i++) { | 153 for (size_t i = 0; i < arraysize(kAlwaysLog); i++) { |
141 api_arg_whitelist_.insert(kAlwaysLog[i]); | 154 api_arg_whitelist_.insert( |
| 155 std::make_pair(kAlwaysLog[i].type, kAlwaysLog[i].name)); |
142 } | 156 } |
143 } | 157 } |
144 | 158 |
145 CountingPolicy::~CountingPolicy() {} | 159 CountingPolicy::~CountingPolicy() {} |
146 | 160 |
147 bool CountingPolicy::InitDatabase(sql::Connection* db) { | 161 bool CountingPolicy::InitDatabase(sql::Connection* db) { |
148 if (!Util::DropObsoleteTables(db)) | 162 if (!Util::DropObsoleteTables(db)) |
149 return false; | 163 return false; |
150 | 164 |
151 if (!string_table_.Initialize(db)) | 165 if (!string_table_.Initialize(db)) |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 return true; | 696 return true; |
683 } | 697 } |
684 | 698 |
685 void CountingPolicy::Close() { | 699 void CountingPolicy::Close() { |
686 // The policy object should have never been created if there's no DB thread. | 700 // The policy object should have never been created if there's no DB thread. |
687 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 701 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
688 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 702 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
689 } | 703 } |
690 | 704 |
691 } // namespace extensions | 705 } // namespace extensions |
OLD | NEW |