| 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 "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" | 5 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 const char* FullStreamUIPolicy::kTableName = "activitylog_full"; | 62 const char* FullStreamUIPolicy::kTableName = "activitylog_full"; |
| 63 const char* FullStreamUIPolicy::kTableContentFields[] = { | 63 const char* FullStreamUIPolicy::kTableContentFields[] = { |
| 64 "extension_id", "time", "action_type", "api_name", "args", "page_url", | 64 "extension_id", "time", "action_type", "api_name", "args", "page_url", |
| 65 "page_title", "arg_url", "other" | 65 "page_title", "arg_url", "other" |
| 66 }; | 66 }; |
| 67 const char* FullStreamUIPolicy::kTableFieldTypes[] = { | 67 const char* FullStreamUIPolicy::kTableFieldTypes[] = { |
| 68 "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR", "LONGVARCHAR", | 68 "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR", "LONGVARCHAR", |
| 69 "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR" | 69 "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR" |
| 70 }; | 70 }; |
| 71 const int FullStreamUIPolicy::kTableFieldCount = arraysize(kTableContentFields); | 71 const int FullStreamUIPolicy::kTableFieldCount = |
| 72 arraysize(FullStreamUIPolicy::kTableContentFields); |
| 72 | 73 |
| 73 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) | 74 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) |
| 74 : ActivityLogDatabasePolicy( | 75 : ActivityLogDatabasePolicy( |
| 75 profile, | 76 profile, |
| 76 FilePath(chrome::kExtensionActivityLogFilename)) {} | 77 FilePath(chrome::kExtensionActivityLogFilename)), |
| 78 string_table_("string_ids"), |
| 79 url_table_("url_ids") {} |
| 77 | 80 |
| 78 FullStreamUIPolicy::~FullStreamUIPolicy() {} | 81 FullStreamUIPolicy::~FullStreamUIPolicy() {} |
| 79 | 82 |
| 80 bool FullStreamUIPolicy::InitDatabase(sql::Connection* db) { | 83 bool FullStreamUIPolicy::InitDatabase(sql::Connection* db) { |
| 81 // Drop old database tables. | 84 // Drop old database tables. |
| 82 for (size_t i = 0; i < arraysize(kObsoleteTables); i++) { | 85 for (size_t i = 0; i < arraysize(kObsoleteTables); i++) { |
| 83 const char* table_name = kObsoleteTables[i]; | 86 const char* table_name = kObsoleteTables[i]; |
| 84 if (db->DoesTableExist(table_name)) { | 87 if (db->DoesTableExist(table_name)) { |
| 85 std::string drop_statement = | 88 std::string drop_statement = |
| 86 base::StringPrintf("DROP TABLE %s", table_name); | 89 base::StringPrintf("DROP TABLE %s", table_name); |
| 87 if (!db->Execute(drop_statement.c_str())) { | 90 if (!db->Execute(drop_statement.c_str())) { |
| 88 return false; | 91 return false; |
| 89 } | 92 } |
| 90 } | 93 } |
| 91 } | 94 } |
| 92 | 95 |
| 96 if (!string_table_.Initialize(db)) |
| 97 return false; |
| 98 if (!url_table_.Initialize(db)) |
| 99 return false; |
| 100 |
| 93 // Create the unified activity log entry table. | 101 // Create the unified activity log entry table. |
| 94 return ActivityDatabase::InitializeTable(db, | 102 return ActivityDatabase::InitializeTable(db, |
| 95 kTableName, | 103 kTableName, |
| 96 kTableContentFields, | 104 kTableContentFields, |
| 97 kTableFieldTypes, | 105 kTableFieldTypes, |
| 98 arraysize(kTableContentFields)); | 106 arraysize(kTableContentFields)); |
| 99 } | 107 } |
| 100 | 108 |
| 101 bool FullStreamUIPolicy::FlushDatabase(sql::Connection* db) { | 109 bool FullStreamUIPolicy::FlushDatabase(sql::Connection* db) { |
| 102 if (queued_actions_.empty()) | 110 if (queued_actions_.empty()) |
| 103 return true; | 111 return true; |
| 104 | 112 |
| 105 sql::Transaction transaction(db); | 113 sql::Transaction transaction(db); |
| 106 if (!transaction.Begin()) | 114 if (!transaction.Begin()) |
| 107 return false; | 115 return false; |
| 108 | 116 |
| 109 std::string sql_str = | 117 std::string sql_str = |
| 110 "INSERT INTO " + std::string(FullStreamUIPolicy::kTableName) + | 118 "INSERT INTO " + std::string(FullStreamUIPolicy::kTableName) + |
| 111 " (extension_id, time, action_type, api_name, args, " | 119 " (extension_id, time, action_type, api_name, args, " |
| 112 "page_url, page_title, arg_url, other) VALUES (?,?,?,?,?,?,?,?,?)"; | 120 "page_url, page_title, arg_url, other) VALUES (?,?,?,?,?,?,?,?,?)"; |
| 113 sql::Statement statement(db->GetCachedStatement( | 121 sql::Statement statement(db->GetCachedStatement( |
| 114 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | 122 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
| 115 | 123 |
| 124 // TODO(mvrable): Should be moved to a utility function, perhaps. |
| 116 url_canon::Replacements<char> url_sanitizer; | 125 url_canon::Replacements<char> url_sanitizer; |
| 117 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 126 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 118 switches::kEnableExtensionActivityLogTesting)) { | 127 switches::kEnableExtensionActivityLogTesting)) { |
| 119 url_sanitizer.ClearQuery(); | 128 url_sanitizer.ClearQuery(); |
| 120 url_sanitizer.ClearRef(); | 129 url_sanitizer.ClearRef(); |
| 121 } | 130 } |
| 122 | 131 |
| 123 Action::ActionVector::size_type i; | 132 Action::ActionVector::size_type i; |
| 124 for (i = 0; i != queued_actions_.size(); ++i) { | 133 for (i = 0; i != queued_actions_.size(); ++i) { |
| 125 const Action& action = *queued_actions_[i]; | 134 const Action& action = *queued_actions_[i]; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 317 } |
| 309 | 318 |
| 310 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 319 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
| 311 if (activity_database()->is_db_valid()) { | 320 if (activity_database()->is_db_valid()) { |
| 312 queued_actions_.push_back(action); | 321 queued_actions_.push_back(action); |
| 313 activity_database()->NotifyAction(); | 322 activity_database()->NotifyAction(); |
| 314 } | 323 } |
| 315 } | 324 } |
| 316 | 325 |
| 317 } // namespace extensions | 326 } // namespace extensions |
| OLD | NEW |