Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / components / dom_distiller / core / fake_db.cc
blob5ada8f0757128ddd1347d201f56e985adda8b380
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"
7 #include "base/bind.h"
9 namespace dom_distiller {
10 namespace test {
12 FakeDB::FakeDB(EntryMap* db) : db_(db) {}
14 FakeDB::~FakeDB() {}
16 void FakeDB::Init(const base::FilePath& database_dir,
17 DomDistillerDatabaseInterface::InitCallback callback) {
18 dir_ = database_dir;
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();
28 ++it) {
29 (*db_)[it->entry_id()] = *it;
31 for (EntryVector::iterator it = entries_to_remove->begin();
32 it != entries_to_remove->end();
33 ++it) {
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);
44 load_callback_ =
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();
65 // static
66 void FakeDB::RunLoadCallback(
67 DomDistillerDatabaseInterface::LoadCallback callback,
68 scoped_ptr<EntryVector> entries,
69 bool success) {
70 callback.Run(success, entries.Pass());
73 // static
74 base::FilePath FakeDB::DirectoryForTestDB() {
75 return base::FilePath(FILE_PATH_LITERAL("/fake/path"));
78 } // namespace test
79 } // namespace dom_distiller