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..ad051f1821fdb350004a16d8d862847041438033 |
--- /dev/null |
+++ b/chrome/browser/budget_service/budget_database.cc |
@@ -0,0 +1,49 @@ |
+// 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.h" |
Peter Beverloo
2016/06/29 13:37:27
nit: you already include this in the header file,
harkness
2016/06/30 10:41:57
Acknowledged.
|
+#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"; |
Peter Beverloo
2016/06/29 13:37:27
nit: blank lines after lines 12 and 16.
harkness
2016/06/30 10:41:57
Done.
|
+} // namespace |
+ |
+BudgetDatabase::BudgetDatabase( |
+ const base::FilePath& database_dir, |
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
+ : db_(new leveldb_proto::ProtoDatabaseImpl<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? |
Peter Beverloo
2016/06/29 13:37:27
Caching is an interesting question. A developer co
harkness
2016/06/30 10:41:57
I need to dig into the implementation of ProtoData
|
+} |
+ |
+void BudgetDatabase::GetValue(const GURL& origin, |
+ const GetValueCallback& callback) { |
+ db_->GetEntry(origin.spec(), callback); |
Peter Beverloo
2016/06/29 13:37:27
DCHECK_EQ(origin.GetOrigin(), origin);
(Also on l
harkness
2016/06/30 10:41:57
Done.
|
+} |
+ |
+void BudgetDatabase::SetValue(const GURL& origin, |
+ const Budget& budget, |
+ const SetValueCallback& callback) { |
+ std::unique_ptr<leveldb_proto::ProtoDatabase<Budget>::KeyEntryVector> entries( |
+ new leveldb_proto::ProtoDatabase<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); |
+} |