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

Side by Side Diff: chrome/browser/android/popular_sites.cc

Issue 1272883004: Popular sites on the NTP: Favicons! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enable_popular_sites
Patch Set: review2 Created 5 years, 4 months 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
« no previous file with comments | « chrome/browser/android/popular_sites.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/android/popular_sites.h" 5 #include "chrome/browser/android/popular_sites.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/task_runner_util.h" 12 #include "base/task_runner_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/net/file_downloader.h" 14 #include "chrome/browser/net/file_downloader.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 19
20 namespace { 20 namespace {
21 21
22 const char kPopularSitesFilename[] = "ntp-popular-sites.json"; 22 const char kPopularSitesFilename[] = "ntp-popular-sites.json";
23 const char kPopularSitesURL[] = 23 const char kPopularSitesURL[] =
24 "https://www.gstatic.com/chrome/ntp/suggested_sites_IN_0.json"; 24 "https://www.gstatic.com/chrome/ntp/suggested_sites_IN_1.json";
25 25
26 base::FilePath GetPopularSitesPath() { 26 base::FilePath GetPopularSitesPath() {
27 base::FilePath dir; 27 base::FilePath dir;
28 PathService::Get(chrome::DIR_USER_DATA, &dir); 28 PathService::Get(chrome::DIR_USER_DATA, &dir);
29 return dir.AppendASCII(kPopularSitesFilename); 29 return dir.AppendASCII(kPopularSitesFilename);
30 } 30 }
31 31
32 scoped_ptr<std::vector<PopularSites::Site>> ReadAndParseJsonFile( 32 scoped_ptr<std::vector<PopularSites::Site>> ReadAndParseJsonFile(
33 const base::FilePath& path) { 33 const base::FilePath& path) {
34 std::string json; 34 std::string json;
(...skipping 13 matching lines...) Expand all
48 scoped_ptr<std::vector<PopularSites::Site>> sites( 48 scoped_ptr<std::vector<PopularSites::Site>> sites(
49 new std::vector<PopularSites::Site>); 49 new std::vector<PopularSites::Site>);
50 for (size_t i = 0; i < list->GetSize(); i++) { 50 for (size_t i = 0; i < list->GetSize(); i++) {
51 base::DictionaryValue* item; 51 base::DictionaryValue* item;
52 if (!list->GetDictionary(i, &item)) 52 if (!list->GetDictionary(i, &item))
53 continue; 53 continue;
54 base::string16 title; 54 base::string16 title;
55 std::string url; 55 std::string url;
56 if (!item->GetString("title", &title) || !item->GetString("url", &url)) 56 if (!item->GetString("title", &title) || !item->GetString("url", &url))
57 continue; 57 continue;
58 sites->push_back(PopularSites::Site(title, GURL(url))); 58 std::string favicon_url;
59 item->GetString("favicon_url", &favicon_url);
60 sites->push_back(PopularSites::Site(title, GURL(url), GURL(favicon_url)));
59 } 61 }
60 62
61 return sites.Pass(); 63 return sites.Pass();
62 } 64 }
63 65
64 } // namespace 66 } // namespace
65 67
66 PopularSites::Site::Site(const base::string16& title, const GURL& url) 68 PopularSites::Site::Site(const base::string16& title,
67 : title(title), url(url) {} 69 const GURL& url,
70 const GURL& favicon_url)
71 : title(title), url(url), favicon_url(favicon_url) {}
68 72
69 PopularSites::PopularSites(net::URLRequestContextGetter* request_context, 73 PopularSites::PopularSites(net::URLRequestContextGetter* request_context,
70 const FinishedCallback& callback) 74 const FinishedCallback& callback)
71 : callback_(callback), weak_ptr_factory_(this) { 75 : callback_(callback), weak_ptr_factory_(this) {
72 base::FilePath path = GetPopularSitesPath(); 76 base::FilePath path = GetPopularSitesPath();
73 downloader_.reset(new FileDownloader( 77 downloader_.reset(new FileDownloader(
74 GURL(kPopularSitesURL), path, request_context, 78 GURL(kPopularSitesURL), path, request_context,
75 base::Bind(&PopularSites::OnDownloadDone, base::Unretained(this), path))); 79 base::Bind(&PopularSites::OnDownloadDone, base::Unretained(this), path)));
76 } 80 }
77 81
(...skipping 16 matching lines...) Expand all
94 downloader_.reset(); 98 downloader_.reset();
95 } 99 }
96 100
97 void PopularSites::OnJsonParsed(scoped_ptr<std::vector<Site>> sites) { 101 void PopularSites::OnJsonParsed(scoped_ptr<std::vector<Site>> sites) {
98 if (sites) 102 if (sites)
99 sites_.swap(*sites); 103 sites_.swap(*sites);
100 else 104 else
101 sites_.clear(); 105 sites_.clear();
102 callback_.Run(!!sites); 106 callback_.Run(!!sites);
103 } 107 }
OLDNEW
« no previous file with comments | « chrome/browser/android/popular_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698