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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); | 49 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); |
50 }; | 50 }; |
51 | 51 |
52 // Used for querying top sites. Either runs sequentially, or runs a nested | 52 // Used for querying top sites. Either runs sequentially, or runs a nested |
53 // nested message loop until the response is complete. The later is used when | 53 // nested message loop until the response is complete. The later is used when |
54 // TopSites is queried before it finishes loading. | 54 // TopSites is queried before it finishes loading. |
55 class TopSitesQuerier { | 55 class TopSitesQuerier { |
56 public: | 56 public: |
57 TopSitesQuerier() | 57 TopSitesQuerier() |
58 : weak_ptr_factory_(this), | 58 : number_of_callbacks_(0), |
59 number_of_callbacks_(0), | 59 waiting_(false), |
60 waiting_(false) {} | 60 weak_ptr_factory_(this) {} |
61 | 61 |
62 // Queries top sites. If |wait| is true a nested message loop is run until the | 62 // Queries top sites. If |wait| is true a nested message loop is run until the |
63 // callback is notified. | 63 // callback is notified. |
64 void QueryTopSites(TopSitesImpl* top_sites, bool wait) { | 64 void QueryTopSites(TopSitesImpl* top_sites, bool wait) { |
65 QueryAllTopSites(top_sites, wait, false); | 65 QueryAllTopSites(top_sites, wait, false); |
66 } | 66 } |
67 | 67 |
68 // Queries top sites, including potentially forced URLs if | 68 // Queries top sites, including potentially forced URLs if |
69 // |include_forced_urls| is true. | 69 // |include_forced_urls| is true. |
70 void QueryAllTopSites(TopSitesImpl* top_sites, | 70 void QueryAllTopSites(TopSitesImpl* top_sites, |
(...skipping 23 matching lines...) Expand all Loading... |
94 // Callback for TopSitesImpl::GetMostVisitedURLs. | 94 // Callback for TopSitesImpl::GetMostVisitedURLs. |
95 void OnTopSitesAvailable(const history::MostVisitedURLList& data) { | 95 void OnTopSitesAvailable(const history::MostVisitedURLList& data) { |
96 urls_ = data; | 96 urls_ = data; |
97 number_of_callbacks_++; | 97 number_of_callbacks_++; |
98 if (waiting_) { | 98 if (waiting_) { |
99 base::MessageLoop::current()->Quit(); | 99 base::MessageLoop::current()->Quit(); |
100 waiting_ = false; | 100 waiting_ = false; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 base::WeakPtrFactory<TopSitesQuerier> weak_ptr_factory_; | |
105 MostVisitedURLList urls_; | 104 MostVisitedURLList urls_; |
106 int number_of_callbacks_; | 105 int number_of_callbacks_; |
107 bool waiting_; | 106 bool waiting_; |
| 107 base::WeakPtrFactory<TopSitesQuerier> weak_ptr_factory_; |
108 | 108 |
109 DISALLOW_COPY_AND_ASSIGN(TopSitesQuerier); | 109 DISALLOW_COPY_AND_ASSIGN(TopSitesQuerier); |
110 }; | 110 }; |
111 | 111 |
112 // Extracts the data from |t1| into a SkBitmap. This is intended for usage of | 112 // Extracts the data from |t1| into a SkBitmap. This is intended for usage of |
113 // thumbnail data, which is stored as jpgs. | 113 // thumbnail data, which is stored as jpgs. |
114 SkBitmap ExtractThumbnail(const base::RefCountedMemory& t1) { | 114 SkBitmap ExtractThumbnail(const base::RefCountedMemory& t1) { |
115 scoped_ptr<SkBitmap> image(gfx::JPEGCodec::Decode(t1.front(), | 115 scoped_ptr<SkBitmap> image(gfx::JPEGCodec::Decode(t1.front(), |
116 t1.size())); | 116 t1.size())); |
117 return image.get() ? *image : SkBitmap(); | 117 return image.get() ? *image : SkBitmap(); |
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); | 1567 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); |
1568 orig_thumbnail.lockPixels(); | 1568 orig_thumbnail.lockPixels(); |
1569 thumbnail.lockPixels(); | 1569 thumbnail.lockPixels(); |
1570 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), | 1570 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), |
1571 orig_thumbnail.getSize())); | 1571 orig_thumbnail.getSize())); |
1572 thumbnail.unlockPixels(); | 1572 thumbnail.unlockPixels(); |
1573 orig_thumbnail.unlockPixels(); | 1573 orig_thumbnail.unlockPixels(); |
1574 } | 1574 } |
1575 | 1575 |
1576 } // namespace history | 1576 } // namespace history |
OLD | NEW |