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 "chrome/browser/extensions/api/top_sites/top_sites_api.h" | 5 #include "chrome/browser/extensions/api/top_sites/top_sites_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
10 #include "chrome/browser/history/top_sites_factory.h" | |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 12 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 TopSitesGetFunction::TopSitesGetFunction() | 16 TopSitesGetFunction::TopSitesGetFunction() |
16 : weak_ptr_factory_(this) {} | 17 : weak_ptr_factory_(this) {} |
17 | 18 |
18 TopSitesGetFunction::~TopSitesGetFunction() {} | 19 TopSitesGetFunction::~TopSitesGetFunction() {} |
19 | 20 |
20 bool TopSitesGetFunction::RunAsync() { | 21 bool TopSitesGetFunction::RunAsync() { |
21 history::TopSites* ts = GetProfile()->GetTopSites(); | 22 scoped_refptr<history::TopSites> ts = |
22 if (!ts) | 23 TopSitesFactory::GetForProfile(GetProfile()); |
24 if (ts.get() == NULL) | |
Bernhard Bauer
2015/01/08 10:22:04
Remove .get() and add the negation operator again.
Jitu( very slow this week)
2015/01/12 11:30:07
Done.
| |
23 return false; | 25 return false; |
24 | 26 |
25 ts->GetMostVisitedURLs( | 27 ts->GetMostVisitedURLs( |
26 base::Bind(&TopSitesGetFunction::OnMostVisitedURLsAvailable, | 28 base::Bind(&TopSitesGetFunction::OnMostVisitedURLsAvailable, |
27 weak_ptr_factory_.GetWeakPtr()), false); | 29 weak_ptr_factory_.GetWeakPtr()), false); |
28 return true; | 30 return true; |
29 } | 31 } |
30 | 32 |
31 void TopSitesGetFunction::OnMostVisitedURLsAvailable( | 33 void TopSitesGetFunction::OnMostVisitedURLsAvailable( |
32 const history::MostVisitedURLList& data) { | 34 const history::MostVisitedURLList& data) { |
33 scoped_ptr<base::ListValue> pages_value(new base::ListValue); | 35 scoped_ptr<base::ListValue> pages_value(new base::ListValue); |
34 for (size_t i = 0; i < data.size(); i++) { | 36 for (size_t i = 0; i < data.size(); i++) { |
35 const history::MostVisitedURL& url = data[i]; | 37 const history::MostVisitedURL& url = data[i]; |
36 if (!url.url.is_empty()) { | 38 if (!url.url.is_empty()) { |
37 base::DictionaryValue* page_value = new base::DictionaryValue(); | 39 base::DictionaryValue* page_value = new base::DictionaryValue(); |
38 page_value->SetString("url", url.url.spec()); | 40 page_value->SetString("url", url.url.spec()); |
39 if (url.title.empty()) | 41 if (url.title.empty()) |
40 page_value->SetString("title", url.url.spec()); | 42 page_value->SetString("title", url.url.spec()); |
41 else | 43 else |
42 page_value->SetString("title", url.title); | 44 page_value->SetString("title", url.title); |
43 pages_value->Append(page_value); | 45 pages_value->Append(page_value); |
44 } | 46 } |
45 } | 47 } |
46 | 48 |
47 SetResult(pages_value.release()); | 49 SetResult(pages_value.release()); |
48 SendResponse(true); | 50 SendResponse(true); |
49 } | 51 } |
50 | 52 |
51 } // namespace extensions | 53 } // namespace extensions |
OLD | NEW |