OLD | NEW |
---|---|
(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.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.
| |
9 #include "components/leveldb_proto/proto_database_impl.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 | |
12 namespace { | |
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"; | |
Peter Beverloo
2016/06/29 13:37:27
nit: blank lines after lines 12 and 16.
harkness
2016/06/30 10:41:57
Done.
| |
17 } // namespace | |
18 | |
19 BudgetDatabase::BudgetDatabase( | |
20 const base::FilePath& database_dir, | |
21 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | |
22 : db_(new leveldb_proto::ProtoDatabaseImpl<Budget>(task_runner)), | |
23 weak_ptr_factory_(this) { | |
24 db_->Init(kDatabaseUMAName, database_dir, | |
25 base::Bind(&BudgetDatabase::OnDatabaseInit, | |
26 weak_ptr_factory_.GetWeakPtr())); | |
27 } | |
28 | |
29 BudgetDatabase::~BudgetDatabase() {} | |
30 | |
31 void BudgetDatabase::OnDatabaseInit(bool success) { | |
32 // 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
| |
33 } | |
34 | |
35 void BudgetDatabase::GetValue(const GURL& origin, | |
36 const GetValueCallback& callback) { | |
37 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.
| |
38 } | |
39 | |
40 void BudgetDatabase::SetValue(const GURL& origin, | |
41 const Budget& budget, | |
42 const SetValueCallback& callback) { | |
43 std::unique_ptr<leveldb_proto::ProtoDatabase<Budget>::KeyEntryVector> entries( | |
44 new leveldb_proto::ProtoDatabase<Budget>::KeyEntryVector()); | |
45 entries->push_back(std::make_pair(origin.spec(), budget)); | |
46 std::unique_ptr<std::vector<std::string>> keys_to_remove( | |
47 new std::vector<std::string>()); | |
48 db_->UpdateEntries(std::move(entries), std::move(keys_to_remove), callback); | |
49 } | |
OLD | NEW |