Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(927)

Side by Side Diff: chrome/browser/history/top_sites_extension_api.cc

Issue 11522007: Move TopSites api from c/b/history to c/b/e/api (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_ungoop_history
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/history/top_sites_extension_api.h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "chrome/browser/history/top_sites.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
12
13 GetTopSitesFunction::GetTopSitesFunction()
14 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
15
16 GetTopSitesFunction::~GetTopSitesFunction() {}
17
18 bool GetTopSitesFunction::RunImpl() {
19 history::TopSites* ts = profile()->GetTopSites();
20 if (!ts)
21 return false;
22
23 ts->GetMostVisitedURLs(
24 base::Bind(&GetTopSitesFunction::OnMostVisitedURLsAvailable,
25 weak_ptr_factory_.GetWeakPtr()));
26 return true;
27 }
28
29 void GetTopSitesFunction::OnMostVisitedURLsAvailable(
30 const history::MostVisitedURLList& data) {
31 scoped_ptr<base::ListValue> pages_value(new ListValue);
32 for (size_t i = 0; i < data.size(); i++) {
33 const history::MostVisitedURL& url = data[i];
34 if (!url.url.is_empty()) {
35 DictionaryValue* page_value = new DictionaryValue();
36 page_value->SetString("url", url.url.spec());
37 if (url.title.empty())
38 page_value->SetString("title", url.url.spec());
39 else
40 page_value->SetString("title", url.title);
41 pages_value->Append(page_value);
42 }
43 }
44
45 SetResult(pages_value.release());
46 SendResponse(true);
47 }
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites_extension_api.h ('k') | chrome/browser/history/top_sites_extension_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698