OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history/core/browser/top_sites_impl.h" | 5 #include "components/history/core/browser/top_sites_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Used by WaitForHistory, see it for details. | 47 // Used by WaitForHistory, see it for details. |
48 class WaitForHistoryTask : public HistoryDBTask { | 48 class WaitForHistoryTask : public HistoryDBTask { |
49 public: | 49 public: |
50 WaitForHistoryTask() {} | 50 WaitForHistoryTask() {} |
51 | 51 |
52 bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) override { | 52 bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) override { |
53 return true; | 53 return true; |
54 } | 54 } |
55 | 55 |
56 void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); } | 56 void DoneRunOnMainThread() override { |
| 57 base::MessageLoop::current()->QuitWhenIdle(); |
| 58 } |
57 | 59 |
58 private: | 60 private: |
59 ~WaitForHistoryTask() override {} | 61 ~WaitForHistoryTask() override {} |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); | 63 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); |
62 }; | 64 }; |
63 | 65 |
64 // Used for querying top sites. Either runs sequentially, or runs a nested | 66 // Used for querying top sites. Either runs sequentially, or runs a nested |
65 // nested message loop until the response is complete. The later is used when | 67 // nested message loop until the response is complete. The later is used when |
66 // TopSites is queried before it finishes loading. | 68 // TopSites is queried before it finishes loading. |
(...skipping 30 matching lines...) Expand all Loading... |
97 const MostVisitedURLList& urls() const { return urls_; } | 99 const MostVisitedURLList& urls() const { return urls_; } |
98 | 100 |
99 int number_of_callbacks() const { return number_of_callbacks_; } | 101 int number_of_callbacks() const { return number_of_callbacks_; } |
100 | 102 |
101 private: | 103 private: |
102 // Callback for TopSitesImpl::GetMostVisitedURLs. | 104 // Callback for TopSitesImpl::GetMostVisitedURLs. |
103 void OnTopSitesAvailable(const history::MostVisitedURLList& data) { | 105 void OnTopSitesAvailable(const history::MostVisitedURLList& data) { |
104 urls_ = data; | 106 urls_ = data; |
105 number_of_callbacks_++; | 107 number_of_callbacks_++; |
106 if (waiting_) { | 108 if (waiting_) { |
107 base::MessageLoop::current()->Quit(); | 109 base::MessageLoop::current()->QuitWhenIdle(); |
108 waiting_ = false; | 110 waiting_ = false; |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 MostVisitedURLList urls_; | 114 MostVisitedURLList urls_; |
113 int number_of_callbacks_; | 115 int number_of_callbacks_; |
114 bool waiting_; | 116 bool waiting_; |
115 base::WeakPtrFactory<TopSitesQuerier> weak_ptr_factory_; | 117 base::WeakPtrFactory<TopSitesQuerier> weak_ptr_factory_; |
116 | 118 |
117 DISALLOW_COPY_AND_ASSIGN(TopSitesQuerier); | 119 DISALLOW_COPY_AND_ASSIGN(TopSitesQuerier); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 ASSERT_LE(start_index + prepopulate_pages.size(), querier.urls().size()); | 206 ASSERT_LE(start_index + prepopulate_pages.size(), querier.urls().size()); |
205 for (size_t i = 0; i < prepopulate_pages.size(); ++i) { | 207 for (size_t i = 0; i < prepopulate_pages.size(); ++i) { |
206 EXPECT_EQ(prepopulate_pages[i].most_visited.url.spec(), | 208 EXPECT_EQ(prepopulate_pages[i].most_visited.url.spec(), |
207 querier.urls()[start_index + i].url.spec()) | 209 querier.urls()[start_index + i].url.spec()) |
208 << " @ index " << i; | 210 << " @ index " << i; |
209 } | 211 } |
210 } | 212 } |
211 | 213 |
212 // Quit the current message loop when invoked. Useful when running a nested | 214 // Quit the current message loop when invoked. Useful when running a nested |
213 // message loop. | 215 // message loop. |
214 void QuitCallback() { base::MessageLoop::current()->Quit(); } | 216 void QuitCallback() { base::MessageLoop::current()->QuitWhenIdle(); } |
215 | 217 |
216 // Adds a page to history. | 218 // Adds a page to history. |
217 void AddPageToHistory(const GURL& url) { | 219 void AddPageToHistory(const GURL& url) { |
218 RedirectList redirects; | 220 RedirectList redirects; |
219 redirects.push_back(url); | 221 redirects.push_back(url); |
220 history_service()->AddPage( | 222 history_service()->AddPage( |
221 url, base::Time::Now(), reinterpret_cast<ContextID>(1), 0, GURL(), | 223 url, base::Time::Now(), reinterpret_cast<ContextID>(1), 0, GURL(), |
222 redirects, ui::PAGE_TRANSITION_TYPED, history::SOURCE_BROWSED, false); | 224 redirects, ui::PAGE_TRANSITION_TYPED, history::SOURCE_BROWSED, false); |
223 } | 225 } |
224 | 226 |
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 EXPECT_EQ("http://forced/5", querier.urls()[5].url.spec()); | 1653 EXPECT_EQ("http://forced/5", querier.urls()[5].url.spec()); |
1652 EXPECT_EQ(6000u, querier.urls()[5].last_forced_time.ToJsTime()); | 1654 EXPECT_EQ(6000u, querier.urls()[5].last_forced_time.ToJsTime()); |
1653 scoped_refptr<base::RefCountedMemory> thumbnail_data; | 1655 scoped_refptr<base::RefCountedMemory> thumbnail_data; |
1654 ASSERT_TRUE(top_sites()->GetPageThumbnail(GURL("http://forced/5"), false, | 1656 ASSERT_TRUE(top_sites()->GetPageThumbnail(GURL("http://forced/5"), false, |
1655 &thumbnail_data)); | 1657 &thumbnail_data)); |
1656 ASSERT_TRUE( | 1658 ASSERT_TRUE( |
1657 ThumbnailsAreEqual(orig_thumbnail_data.get(), thumbnail_data.get())); | 1659 ThumbnailsAreEqual(orig_thumbnail_data.get(), thumbnail_data.get())); |
1658 } | 1660 } |
1659 | 1661 |
1660 } // namespace history | 1662 } // namespace history |
OLD | NEW |