| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 151 } |
| 152 if (!page_url.empty()) { | 152 if (!page_url.empty()) { |
| 153 where_str += where_next + "page_url LIKE ?"; | 153 where_str += where_next + "page_url LIKE ?"; |
| 154 where_next = " AND "; | 154 where_next = " AND "; |
| 155 } | 155 } |
| 156 if (!arg_url.empty()) { | 156 if (!arg_url.empty()) { |
| 157 where_str += where_next + "arg_url LIKE ?"; | 157 where_str += where_next + "arg_url LIKE ?"; |
| 158 } | 158 } |
| 159 std::string query_str = base::StringPrintf( | 159 std::string query_str = base::StringPrintf( |
| 160 "SELECT extension_id,time,action_type,api_name,args,page_url,page_title," | 160 "SELECT extension_id,time,action_type,api_name,args,page_url,page_title," |
| 161 "arg_url,other FROM %s WHERE %s ORDER BY time DESC", | 161 "arg_url,other FROM %s %s %s ORDER BY time DESC", |
| 162 kTableName, | 162 kTableName, |
| 163 where_str.empty() ? "" : "WHERE", |
| 163 where_str.c_str()); | 164 where_str.c_str()); |
| 164 sql::Statement query(db->GetUniqueStatement(query_str.c_str())); | 165 sql::Statement query(db->GetUniqueStatement(query_str.c_str())); |
| 165 int i = -1; | 166 int i = -1; |
| 166 if (!extension_id.empty()) | 167 if (!extension_id.empty()) |
| 167 query.BindString(++i, extension_id); | 168 query.BindString(++i, extension_id); |
| 168 if (!api_name.empty()) | 169 if (!api_name.empty()) |
| 169 query.BindString(++i, api_name); | 170 query.BindString(++i, api_name); |
| 170 if (type != Action::ACTION_ANY) | 171 if (type != Action::ACTION_ANY) |
| 171 query.BindInt(++i, static_cast<int>(type)); | 172 query.BindInt(++i, static_cast<int>(type)); |
| 172 if (!page_url.empty()) | 173 if (!page_url.empty()) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 statement.BindString(0, restrict_urls[i].spec()); | 334 statement.BindString(0, restrict_urls[i].spec()); |
| 334 | 335 |
| 335 if (!statement.Run()) { | 336 if (!statement.Run()) { |
| 336 LOG(ERROR) << "Removing arg URL from database failed: " | 337 LOG(ERROR) << "Removing arg URL from database failed: " |
| 337 << statement.GetSQLStatement(); | 338 << statement.GetSQLStatement(); |
| 338 return; | 339 return; |
| 339 } | 340 } |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 | 343 |
| 344 void FullStreamUIPolicy::DoDeleteDatabase() { |
| 345 sql::Connection* db = GetDatabaseConnection(); |
| 346 if (!db) { |
| 347 LOG(ERROR) << "Unable to connect to database"; |
| 348 return; |
| 349 } |
| 350 |
| 351 queued_actions_.clear(); |
| 352 |
| 353 // Not wrapped in a transaction because the deletion should happen even if |
| 354 // the vacuuming fails. |
| 355 std::string sql_str = base::StringPrintf("DELETE FROM %s;", kTableName); |
| 356 sql::Statement statement(db->GetCachedStatement( |
| 357 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
| 358 if (!statement.Run()) { |
| 359 LOG(ERROR) << "Deleting the database failed: " |
| 360 << statement.GetSQLStatement(); |
| 361 return; |
| 362 } |
| 363 statement.Clear(); |
| 364 statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE), |
| 365 "VACUUM")); |
| 366 if (!statement.Run()) { |
| 367 LOG(ERROR) << "Vacuuming the database failed: " |
| 368 << statement.GetSQLStatement(); |
| 369 } |
| 370 } |
| 371 |
| 343 void FullStreamUIPolicy::OnDatabaseFailure() { | 372 void FullStreamUIPolicy::OnDatabaseFailure() { |
| 344 queued_actions_.clear(); | 373 queued_actions_.clear(); |
| 345 } | 374 } |
| 346 | 375 |
| 347 void FullStreamUIPolicy::OnDatabaseClose() { | 376 void FullStreamUIPolicy::OnDatabaseClose() { |
| 348 delete this; | 377 delete this; |
| 349 } | 378 } |
| 350 | 379 |
| 351 void FullStreamUIPolicy::Close() { | 380 void FullStreamUIPolicy::Close() { |
| 352 // The policy object should have never been created if there's no DB thread. | 381 // The policy object should have never been created if there's no DB thread. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 api_name, | 416 api_name, |
| 388 page_url, | 417 page_url, |
| 389 arg_url), | 418 arg_url), |
| 390 callback); | 419 callback); |
| 391 } | 420 } |
| 392 | 421 |
| 393 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 422 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
| 394 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); | 423 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); |
| 395 } | 424 } |
| 396 | 425 |
| 426 void FullStreamUIPolicy::DeleteDatabase() { |
| 427 ScheduleAndForget(this, &FullStreamUIPolicy::DoDeleteDatabase); |
| 428 } |
| 429 |
| 397 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( | 430 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( |
| 398 scoped_refptr<Action> action) const { | 431 scoped_refptr<Action> action) const { |
| 399 return action; | 432 return action; |
| 400 } | 433 } |
| 401 | 434 |
| 402 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { | 435 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { |
| 403 // TODO(mvrable): Right now this argument stripping updates the Action object | 436 // TODO(mvrable): Right now this argument stripping updates the Action object |
| 404 // in place, which isn't good if there are other users of the object. When | 437 // in place, which isn't good if there are other users of the object. When |
| 405 // database writing is moved to policy class, the modifications should be | 438 // database writing is moved to policy class, the modifications should be |
| 406 // made locally. | 439 // made locally. |
| 407 action = ProcessArguments(action); | 440 action = ProcessArguments(action); |
| 408 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); | 441 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); |
| 409 } | 442 } |
| 410 | 443 |
| 411 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 444 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
| 412 if (activity_database()->is_db_valid()) { | 445 if (activity_database()->is_db_valid()) { |
| 413 queued_actions_.push_back(action); | 446 queued_actions_.push_back(action); |
| 414 activity_database()->AdviseFlush(queued_actions_.size()); | 447 activity_database()->AdviseFlush(queued_actions_.size()); |
| 415 } | 448 } |
| 416 } | 449 } |
| 417 | 450 |
| 418 } // namespace extensions | 451 } // namespace extensions |
| OLD | NEW |