OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/budget_service/budget_database.h" | 5 #include "chrome/browser/budget_service/budget_database.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/task_scheduler/post_task.h" | 9 #include "base/task_scheduler/post_task.h" |
10 #include "base/time/clock.h" | 10 #include "base/time/clock.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 chunks = std::move(other.chunks); | 45 chunks = std::move(other.chunks); |
46 } | 46 } |
47 | 47 |
48 BudgetDatabase::BudgetInfo::~BudgetInfo() {} | 48 BudgetDatabase::BudgetInfo::~BudgetInfo() {} |
49 | 49 |
50 BudgetDatabase::BudgetDatabase(Profile* profile, | 50 BudgetDatabase::BudgetDatabase(Profile* profile, |
51 const base::FilePath& database_dir) | 51 const base::FilePath& database_dir) |
52 : profile_(profile), | 52 : profile_(profile), |
53 db_(new leveldb_proto::ProtoDatabaseImpl<budget_service::Budget>( | 53 db_(new leveldb_proto::ProtoDatabaseImpl<budget_service::Budget>( |
54 base::CreateSequencedTaskRunnerWithTraits( | 54 base::CreateSequencedTaskRunnerWithTraits( |
55 base::TaskTraits() | 55 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
56 .MayBlock() | 56 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}))), |
57 .WithPriority(base::TaskPriority::BACKGROUND) | |
58 .WithShutdownBehavior( | |
59 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)))), | |
60 clock_(base::WrapUnique(new base::DefaultClock)), | 57 clock_(base::WrapUnique(new base::DefaultClock)), |
61 weak_ptr_factory_(this) { | 58 weak_ptr_factory_(this) { |
62 db_->Init(kDatabaseUMAName, database_dir, | 59 db_->Init(kDatabaseUMAName, database_dir, |
63 base::Bind(&BudgetDatabase::OnDatabaseInit, | 60 base::Bind(&BudgetDatabase::OnDatabaseInit, |
64 weak_ptr_factory_.GetWeakPtr())); | 61 weak_ptr_factory_.GetWeakPtr())); |
65 } | 62 } |
66 | 63 |
67 BudgetDatabase::~BudgetDatabase() {} | 64 BudgetDatabase::~BudgetDatabase() {} |
68 | 65 |
69 void BudgetDatabase::GetBudgetDetails(const url::Origin& origin, | 66 void BudgetDatabase::GetBudgetDetails(const url::Origin& origin, |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 clock_->Now() - base::TimeDelta::FromDays(kBudgetDurationInDays)) { | 366 clock_->Now() - base::TimeDelta::FromDays(kBudgetDurationInDays)) { |
370 budget_map_.erase(origin); | 367 budget_map_.erase(origin); |
371 return true; | 368 return true; |
372 } | 369 } |
373 | 370 |
374 // Although some things may have expired, there are some chunks still valid. | 371 // Although some things may have expired, there are some chunks still valid. |
375 // Don't write to the DB now, write either when all chunks expire or when the | 372 // Don't write to the DB now, write either when all chunks expire or when the |
376 // origin spends some budget. | 373 // origin spends some budget. |
377 return false; | 374 return false; |
378 } | 375 } |
OLD | NEW |