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

Side by Side Diff: chrome/browser/budget_service/budget_database.cc

Issue 2107173002: Add the future storage framework for the BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/budget_service/budget_database.h"
6
7 #include "chrome/browser/budget_service/budget.pb.h"
8 #include "components/leveldb_proto/proto_database_impl.h"
9 #include "content/public/browser/browser_thread.h"
10
11 namespace {
12
13 // UMA are logged for the database with this string as part of the name.
14 // They will be LevelDB.*.BackgroundBudgetService. Changes here should be
15 // synchronized with histograms.xml.
16 const char kDatabaseUMAName[] = "BackgroundBudgetService";
17
18 } // namespace
19
20 BudgetDatabase::BudgetDatabase(
21 const base::FilePath& database_dir,
22 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
23 : db_(new leveldb_proto::ProtoDatabaseImpl<budget_service::Budget>(
24 task_runner)),
25 weak_ptr_factory_(this) {
26 db_->Init(kDatabaseUMAName, database_dir,
27 base::Bind(&BudgetDatabase::OnDatabaseInit,
28 weak_ptr_factory_.GetWeakPtr()));
29 }
30
31 BudgetDatabase::~BudgetDatabase() {}
32
33 void BudgetDatabase::OnDatabaseInit(bool success) {
34 // TODO(harkness): Consider caching the budget database now?
35 }
36
37 void BudgetDatabase::GetValue(const GURL& origin,
38 const GetValueCallback& callback) {
39 DCHECK_EQ(origin.GetOrigin(), origin);
40 db_->GetEntry(origin.spec(), callback);
41 }
42
43 void BudgetDatabase::SetValue(const GURL& origin,
44 const budget_service::Budget& budget,
45 const SetValueCallback& callback) {
46 DCHECK_EQ(origin.GetOrigin(), origin);
47
48 // Build structures to hold the updated values.
49 std::unique_ptr<
50 leveldb_proto::ProtoDatabase<budget_service::Budget>::KeyEntryVector>
51 entries(new leveldb_proto::ProtoDatabase<
52 budget_service::Budget>::KeyEntryVector());
53 entries->push_back(std::make_pair(origin.spec(), budget));
54 std::unique_ptr<std::vector<std::string>> keys_to_remove(
55 new std::vector<std::string>());
56
57 // Send the updates to the database.
58 db_->UpdateEntries(std::move(entries), std::move(keys_to_remove), callback);
59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698