Chromium Code Reviews| Index: chrome/browser/budget_service/budget_database.cc |
| diff --git a/chrome/browser/budget_service/budget_database.cc b/chrome/browser/budget_service/budget_database.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7d15397b69e8ae8e7056f6e8588b48241f3e0e9 |
| --- /dev/null |
| +++ b/chrome/browser/budget_service/budget_database.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/budget_service/budget_database.h" |
| + |
| +#include "chrome/browser/budget_service/budget.pb.h" |
| +#include "components/leveldb_proto/proto_database_impl.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace { |
| + |
| +// UMA are logged for the database with this string as part of the name. |
| +// They will be LevelDB.*.BackgroundBudgetService. Changes here should be |
| +// synchronized with histograms.xml. |
| +const char kDatabaseUMAName[] = "BackgroundBudgetService"; |
| + |
| +} // namespace |
| + |
| +BudgetDatabase::BudgetDatabase( |
| + const base::FilePath& database_dir, |
| + const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| + : db_(new leveldb_proto::ProtoDatabaseImpl<budget_service::Budget>( |
| + task_runner)), |
| + weak_ptr_factory_(this) { |
| + db_->Init(kDatabaseUMAName, database_dir, |
| + base::Bind(&BudgetDatabase::OnDatabaseInit, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +BudgetDatabase::~BudgetDatabase() {} |
| + |
| +void BudgetDatabase::OnDatabaseInit(bool success) { |
| + // TODO(harkness): Consider caching the budget database now? |
| +} |
| + |
| +void BudgetDatabase::GetValue(const GURL& origin, |
| + const GetValueCallback& callback) { |
| + DCHECK_EQ(origin.GetOrigin(), origin); |
| + db_->GetEntry(origin.spec(), callback); |
| +} |
| + |
| +void BudgetDatabase::SetValue(const GURL& origin, |
| + const budget_service::Budget& budget, |
| + const SetValueCallback& callback) { |
| + DCHECK_EQ(origin.GetOrigin(), origin); |
| + std::unique_ptr< |
| + leveldb_proto::ProtoDatabase<budget_service::Budget>::KeyEntryVector> |
| + entries(new leveldb_proto::ProtoDatabase< |
| + budget_service::Budget>::KeyEntryVector()); |
| + entries->push_back(std::make_pair(origin.spec(), budget)); |
| + std::unique_ptr<std::vector<std::string>> keys_to_remove( |
| + new std::vector<std::string>()); |
| + db_->UpdateEntries(std::move(entries), std::move(keys_to_remove), callback); |
|
Peter Beverloo
2016/06/30 13:12:46
micro nit: blank lines to separate the logical sec
harkness
2016/07/01 12:29:54
Good point.
|
| +} |