OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/dom_distiller/core/fake_distiller.h" | 5 #include "components/dom_distiller/core/fake_distiller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 EXPECT_CALL(*this, Die()).Times(testing::AnyNumber()); | 35 EXPECT_CALL(*this, Die()).Times(testing::AnyNumber()); |
36 } | 36 } |
37 | 37 |
38 FakeDistiller::~FakeDistiller() { | 38 FakeDistiller::~FakeDistiller() { |
39 EXPECT_TRUE(destruction_allowed_); | 39 EXPECT_TRUE(destruction_allowed_); |
40 Die(); | 40 Die(); |
41 } | 41 } |
42 | 42 |
43 void FakeDistiller::DistillPage( | 43 void FakeDistiller::DistillPage( |
44 const GURL& url, | 44 const GURL& url, |
45 scoped_ptr<DistillerPage> distiller_page, | 45 std::unique_ptr<DistillerPage> distiller_page, |
46 const DistillationFinishedCallback& article_callback, | 46 const DistillationFinishedCallback& article_callback, |
47 const DistillationUpdateCallback& page_callback) { | 47 const DistillationUpdateCallback& page_callback) { |
48 url_ = url; | 48 url_ = url; |
49 article_callback_ = article_callback; | 49 article_callback_ = article_callback; |
50 page_callback_ = page_callback; | 50 page_callback_ = page_callback; |
51 if (!distillation_initiated_callback_.is_null()) { | 51 if (!distillation_initiated_callback_.is_null()) { |
52 base::ResetAndReturn(&distillation_initiated_callback_).Run(); | 52 base::ResetAndReturn(&distillation_initiated_callback_).Run(); |
53 } | 53 } |
54 if (execute_callback_) { | 54 if (execute_callback_) { |
55 scoped_ptr<DistilledArticleProto> proto(new DistilledArticleProto); | 55 std::unique_ptr<DistilledArticleProto> proto(new DistilledArticleProto); |
56 proto->add_pages()->set_url(url_.spec()); | 56 proto->add_pages()->set_url(url_.spec()); |
57 PostDistillerCallback(std::move(proto)); | 57 PostDistillerCallback(std::move(proto)); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 void FakeDistiller::RunDistillerCallback( | 61 void FakeDistiller::RunDistillerCallback( |
62 scoped_ptr<DistilledArticleProto> proto) { | 62 std::unique_ptr<DistilledArticleProto> proto) { |
63 ASSERT_FALSE(execute_callback_) << "Cannot explicitly run the distiller " | 63 ASSERT_FALSE(execute_callback_) << "Cannot explicitly run the distiller " |
64 "callback for a fake distiller created " | 64 "callback for a fake distiller created " |
65 "with automatic callback execution."; | 65 "with automatic callback execution."; |
66 PostDistillerCallback(std::move(proto)); | 66 PostDistillerCallback(std::move(proto)); |
67 } | 67 } |
68 | 68 |
69 void FakeDistiller::RunDistillerUpdateCallback( | 69 void FakeDistiller::RunDistillerUpdateCallback( |
70 const ArticleDistillationUpdate& update) { | 70 const ArticleDistillationUpdate& update) { |
71 page_callback_.Run(update); | 71 page_callback_.Run(update); |
72 } | 72 } |
73 | 73 |
74 | |
75 void FakeDistiller::PostDistillerCallback( | 74 void FakeDistiller::PostDistillerCallback( |
76 scoped_ptr<DistilledArticleProto> proto) { | 75 std::unique_ptr<DistilledArticleProto> proto) { |
77 base::ThreadTaskRunnerHandle::Get()->PostTask( | 76 base::ThreadTaskRunnerHandle::Get()->PostTask( |
78 FROM_HERE, base::Bind(&FakeDistiller::RunDistillerCallbackInternal, | 77 FROM_HERE, base::Bind(&FakeDistiller::RunDistillerCallbackInternal, |
79 base::Unretained(this), base::Passed(&proto))); | 78 base::Unretained(this), base::Passed(&proto))); |
80 } | 79 } |
81 | 80 |
82 void FakeDistiller::RunDistillerCallbackInternal( | 81 void FakeDistiller::RunDistillerCallbackInternal( |
83 scoped_ptr<DistilledArticleProto> proto) { | 82 std::unique_ptr<DistilledArticleProto> proto) { |
84 EXPECT_FALSE(article_callback_.is_null()); | 83 EXPECT_FALSE(article_callback_.is_null()); |
85 | 84 |
86 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, | 85 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, |
87 false); | 86 false); |
88 article_callback_.Run(std::move(proto)); | 87 article_callback_.Run(std::move(proto)); |
89 article_callback_.Reset(); | 88 article_callback_.Reset(); |
90 } | 89 } |
91 | 90 |
92 } // namespace test | 91 } // namespace test |
93 } // namespace dom_distiller | 92 } // namespace dom_distiller |
OLD | NEW |