OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 "components/dom_distiller/core/fake_db.h" | |
6 | |
7 #include "base/bind.h" | |
8 | |
9 namespace dom_distiller { | |
10 namespace test { | |
11 | |
12 FakeDB::FakeDB(EntryMap* db) : db_(db) {} | |
13 | |
14 FakeDB::~FakeDB() {} | |
15 | |
16 void FakeDB::Init(const base::FilePath& database_dir, | |
17 DomDistillerDatabaseInterface::InitCallback callback) { | |
18 dir_ = database_dir; | |
19 init_callback_ = callback; | |
20 } | |
21 | |
22 void FakeDB::UpdateEntries( | |
23 scoped_ptr<EntryVector> entries_to_save, | |
24 scoped_ptr<EntryVector> entries_to_remove, | |
25 DomDistillerDatabaseInterface::UpdateCallback callback) { | |
26 for (EntryVector::iterator it = entries_to_save->begin(); | |
27 it != entries_to_save->end(); | |
28 ++it) { | |
29 (*db_)[it->entry_id()] = *it; | |
30 } | |
31 for (EntryVector::iterator it = entries_to_remove->begin(); | |
32 it != entries_to_remove->end(); | |
33 ++it) { | |
34 (*db_).erase(it->entry_id()); | |
35 } | |
36 update_callback_ = callback; | |
37 } | |
38 | |
39 void FakeDB::LoadEntries(DomDistillerDatabaseInterface::LoadCallback callback) { | |
40 scoped_ptr<EntryVector> entries(new EntryVector()); | |
41 for (EntryMap::iterator it = db_->begin(); it != db_->end(); ++it) { | |
42 entries->push_back(it->second); | |
43 } | |
44 load_callback_ = | |
45 base::Bind(RunLoadCallback, callback, base::Passed(&entries)); | |
46 } | |
47 | |
48 base::FilePath& FakeDB::GetDirectory() { return dir_; } | |
49 | |
50 void FakeDB::InitCallback(bool success) { | |
51 init_callback_.Run(success); | |
52 init_callback_.Reset(); | |
53 } | |
54 | |
55 void FakeDB::LoadCallback(bool success) { | |
56 load_callback_.Run(success); | |
57 load_callback_.Reset(); | |
58 } | |
59 | |
60 void FakeDB::UpdateCallback(bool success) { | |
61 update_callback_.Run(success); | |
62 update_callback_.Reset(); | |
63 } | |
64 | |
65 // static | |
66 void FakeDB::RunLoadCallback( | |
67 DomDistillerDatabaseInterface::LoadCallback callback, | |
68 scoped_ptr<EntryVector> entries, | |
69 bool success) { | |
70 callback.Run(success, entries.Pass()); | |
71 } | |
72 | |
73 // static | |
74 base::FilePath FakeDB::DirectoryForTestDB() { | |
75 return base::FilePath(FILE_PATH_LITERAL("/fake/path")); | |
76 } | |
77 | |
78 } // namespace test | |
79 } // namespace dom_distiller | |
OLD | NEW |