Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/extensions/activity_log/counting_policy.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 34
35 #include <map> 35 #include <map>
36 #include <string> 36 #include <string>
37 #include <vector> 37 #include <vector>
38 38
39 #include "base/callback.h" 39 #include "base/callback.h"
40 #include "base/files/file_path.h" 40 #include "base/files/file_path.h"
41 #include "base/json/json_reader.h" 41 #include "base/json/json_reader.h"
42 #include "base/json/json_string_value_serializer.h" 42 #include "base/json/json_string_value_serializer.h"
43 #include "base/macros.h" 43 #include "base/macros.h"
44 #include "base/memory/ptr_util.h"
44 #include "base/strings/string_util.h" 45 #include "base/strings/string_util.h"
45 #include "base/strings/stringprintf.h" 46 #include "base/strings/stringprintf.h"
46 #include "chrome/common/chrome_constants.h" 47 #include "chrome/common/chrome_constants.h"
47 #include "sql/statement.h" 48 #include "sql/statement.h"
48 #include "sql/transaction.h" 49 #include "sql/transaction.h"
49 50
50 using content::BrowserThread; 51 using content::BrowserThread;
51 52
52 namespace { 53 namespace {
53 54
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return false; 415 return false;
415 last_database_cleaning_time_ = Now(); 416 last_database_cleaning_time_ = Now();
416 } 417 }
417 418
418 if (!transaction.Commit()) 419 if (!transaction.Commit())
419 return false; 420 return false;
420 421
421 return true; 422 return true;
422 } 423 }
423 424
424 scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData( 425 std::unique_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
425 const std::string& extension_id, 426 const std::string& extension_id,
426 const Action::ActionType type, 427 const Action::ActionType type,
427 const std::string& api_name, 428 const std::string& api_name,
428 const std::string& page_url, 429 const std::string& page_url,
429 const std::string& arg_url, 430 const std::string& arg_url,
430 const int days_ago) { 431 const int days_ago) {
431 // Ensure data is flushed to the database first so that we query over all 432 // Ensure data is flushed to the database first so that we query over all
432 // data. 433 // data.
433 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); 434 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
434 scoped_ptr<Action::ActionVector> actions(new Action::ActionVector()); 435 std::unique_ptr<Action::ActionVector> actions(new Action::ActionVector());
435 436
436 sql::Connection* db = GetDatabaseConnection(); 437 sql::Connection* db = GetDatabaseConnection();
437 if (!db) 438 if (!db)
438 return actions; 439 return actions;
439 440
440 // Build up the query based on which parameters were specified. 441 // Build up the query based on which parameters were specified.
441 std::string where_str = ""; 442 std::string where_str = "";
442 std::string where_next = ""; 443 std::string where_next = "";
443 if (!extension_id.empty()) { 444 if (!extension_id.empty()) {
444 where_str += "extension_id=?"; 445 where_str += "extension_id=?";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 493
493 // Execute the query and get results. 494 // Execute the query and get results.
494 while (query.is_valid() && query.Step()) { 495 while (query.is_valid() && query.Step()) {
495 scoped_refptr<Action> action = 496 scoped_refptr<Action> action =
496 new Action(query.ColumnString(0), 497 new Action(query.ColumnString(0),
497 base::Time::FromInternalValue(query.ColumnInt64(1)), 498 base::Time::FromInternalValue(query.ColumnInt64(1)),
498 static_cast<Action::ActionType>(query.ColumnInt(2)), 499 static_cast<Action::ActionType>(query.ColumnInt(2)),
499 query.ColumnString(3), query.ColumnInt64(10)); 500 query.ColumnString(3), query.ColumnInt64(10));
500 501
501 if (query.ColumnType(4) != sql::COLUMN_TYPE_NULL) { 502 if (query.ColumnType(4) != sql::COLUMN_TYPE_NULL) {
502 scoped_ptr<base::Value> parsed_value = 503 std::unique_ptr<base::Value> parsed_value =
503 base::JSONReader::Read(query.ColumnString(4)); 504 base::JSONReader::Read(query.ColumnString(4));
504 if (parsed_value && parsed_value->IsType(base::Value::TYPE_LIST)) { 505 if (parsed_value && parsed_value->IsType(base::Value::TYPE_LIST)) {
505 action->set_args(make_scoped_ptr( 506 action->set_args(base::WrapUnique(
506 static_cast<base::ListValue*>(parsed_value.release()))); 507 static_cast<base::ListValue*>(parsed_value.release())));
507 } 508 }
508 } 509 }
509 510
510 action->ParsePageUrl(query.ColumnString(5)); 511 action->ParsePageUrl(query.ColumnString(5));
511 action->set_page_title(query.ColumnString(6)); 512 action->set_page_title(query.ColumnString(6));
512 action->ParseArgUrl(query.ColumnString(7)); 513 action->ParseArgUrl(query.ColumnString(7));
513 514
514 if (query.ColumnType(8) != sql::COLUMN_TYPE_NULL) { 515 if (query.ColumnType(8) != sql::COLUMN_TYPE_NULL) {
515 scoped_ptr<base::Value> parsed_value = 516 std::unique_ptr<base::Value> parsed_value =
516 base::JSONReader::Read(query.ColumnString(8)); 517 base::JSONReader::Read(query.ColumnString(8));
517 if (parsed_value && parsed_value->IsType(base::Value::TYPE_DICTIONARY)) { 518 if (parsed_value && parsed_value->IsType(base::Value::TYPE_DICTIONARY)) {
518 action->set_other(make_scoped_ptr( 519 action->set_other(base::WrapUnique(
519 static_cast<base::DictionaryValue*>(parsed_value.release()))); 520 static_cast<base::DictionaryValue*>(parsed_value.release())));
520 } 521 }
521 } 522 }
522 action->set_count(query.ColumnInt(9)); 523 action->set_count(query.ColumnInt(9));
523 actions->push_back(action); 524 actions->push_back(action);
524 } 525 }
525 526
526 return actions; 527 return actions;
527 } 528 }
528 529
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 718 }
718 } 719 }
719 720
720 void CountingPolicy::ReadFilteredData( 721 void CountingPolicy::ReadFilteredData(
721 const std::string& extension_id, 722 const std::string& extension_id,
722 const Action::ActionType type, 723 const Action::ActionType type,
723 const std::string& api_name, 724 const std::string& api_name,
724 const std::string& page_url, 725 const std::string& page_url,
725 const std::string& arg_url, 726 const std::string& arg_url,
726 const int days_ago, 727 const int days_ago,
727 const base::Callback 728 const base::Callback<void(std::unique_ptr<Action::ActionVector>)>&
728 <void(scoped_ptr<Action::ActionVector>)>& callback) { 729 callback) {
729 BrowserThread::PostTaskAndReplyWithResult( 730 BrowserThread::PostTaskAndReplyWithResult(
730 BrowserThread::DB, 731 BrowserThread::DB,
731 FROM_HERE, 732 FROM_HERE,
732 base::Bind(&CountingPolicy::DoReadFilteredData, 733 base::Bind(&CountingPolicy::DoReadFilteredData,
733 base::Unretained(this), 734 base::Unretained(this),
734 extension_id, 735 extension_id,
735 type, 736 type,
736 api_name, 737 api_name,
737 page_url, 738 page_url,
738 arg_url, 739 arg_url,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 return true; 798 return true;
798 } 799 }
799 800
800 void CountingPolicy::Close() { 801 void CountingPolicy::Close() {
801 // The policy object should have never been created if there's no DB thread. 802 // The policy object should have never been created if there's no DB thread.
802 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 803 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
803 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); 804 ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
804 } 805 }
805 806
806 } // namespace extensions 807 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698