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.
5 #include "components/dom_distiller/core/fake_db.h"
9 namespace dom_distiller
{
12 FakeDB::FakeDB(EntryMap
* db
) : db_(db
) {}
16 void FakeDB::Init(const base::FilePath
& database_dir
,
17 DomDistillerDatabaseInterface::InitCallback callback
) {
19 init_callback_
= callback
;
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();
29 (*db_
)[it
->entry_id()] = *it
;
31 for (EntryVector::iterator it
= entries_to_remove
->begin();
32 it
!= entries_to_remove
->end();
34 (*db_
).erase(it
->entry_id());
36 update_callback_
= callback
;
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
);
45 base::Bind(RunLoadCallback
, callback
, base::Passed(&entries
));
48 base::FilePath
& FakeDB::GetDirectory() { return dir_
; }
50 void FakeDB::InitCallback(bool success
) {
51 init_callback_
.Run(success
);
52 init_callback_
.Reset();
55 void FakeDB::LoadCallback(bool success
) {
56 load_callback_
.Run(success
);
57 load_callback_
.Reset();
60 void FakeDB::UpdateCallback(bool success
) {
61 update_callback_
.Run(success
);
62 update_callback_
.Reset();
66 void FakeDB::RunLoadCallback(
67 DomDistillerDatabaseInterface::LoadCallback callback
,
68 scoped_ptr
<EntryVector
> entries
,
70 callback
.Run(success
, entries
.Pass());
74 base::FilePath
FakeDB::DirectoryForTestDB() {
75 return base::FilePath(FILE_PATH_LITERAL("/fake/path"));
79 } // namespace dom_distiller