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

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

Issue 1314493013: Popular sites on the NTP: add thumbnails! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 5 years, 3 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
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/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/net/file_downloader.h" 15 #include "chrome/browser/net/file_downloader.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 18
19 using content::BrowserThread; 19 using content::BrowserThread;
20 20
21 namespace { 21 namespace {
22 22
23 const char kPopularSitesURLFormat[] = "https://www.gstatic.com/chrome/ntp/%s"; 23 const char kPopularSitesURLFormat[] = "https://www.gstatic.com/chrome/ntp/%s";
24 const char kPopularSitesDefaultFilename[] = "suggested_sites_IN_1.json"; 24 const char kPopularSitesDefaultFilename[] = "suggested_sites_IN_2.json";
25 25
26 std::string GetPopularSitesFilename(const std::string& filename) { 26 std::string GetPopularSitesFilename(const std::string& filename) {
27 return filename.empty() ? kPopularSitesDefaultFilename : filename.c_str(); 27 return filename.empty() ? kPopularSitesDefaultFilename : filename.c_str();
28 } 28 }
29 29
30 base::FilePath GetPopularSitesPath(const std::string& filename) { 30 base::FilePath GetPopularSitesPath(const std::string& filename) {
31 base::FilePath dir; 31 base::FilePath dir;
32 PathService::Get(chrome::DIR_USER_DATA, &dir); 32 PathService::Get(chrome::DIR_USER_DATA, &dir);
33 return dir.AppendASCII(GetPopularSitesFilename(filename)); 33 return dir.AppendASCII(GetPopularSitesFilename(filename));
34 } 34 }
(...skipping 24 matching lines...) Expand all
59 for (size_t i = 0; i < list->GetSize(); i++) { 59 for (size_t i = 0; i < list->GetSize(); i++) {
60 base::DictionaryValue* item; 60 base::DictionaryValue* item;
61 if (!list->GetDictionary(i, &item)) 61 if (!list->GetDictionary(i, &item))
62 continue; 62 continue;
63 base::string16 title; 63 base::string16 title;
64 std::string url; 64 std::string url;
65 if (!item->GetString("title", &title) || !item->GetString("url", &url)) 65 if (!item->GetString("title", &title) || !item->GetString("url", &url))
66 continue; 66 continue;
67 std::string favicon_url; 67 std::string favicon_url;
68 item->GetString("favicon_url", &favicon_url); 68 item->GetString("favicon_url", &favicon_url);
69 sites->push_back(PopularSites::Site(title, GURL(url), GURL(favicon_url))); 69 std::string thumbnail_url;
70 item->GetString("thumbnail_url", &thumbnail_url);
71
72 sites->push_back(PopularSites::Site(title, GURL(url), GURL(favicon_url),
73 GURL(thumbnail_url)));
70 } 74 }
71 75
72 return sites.Pass(); 76 return sites.Pass();
73 } 77 }
74 78
75 } // namespace 79 } // namespace
76 80
77 PopularSites::Site::Site(const base::string16& title, 81 PopularSites::Site::Site(const base::string16& title,
78 const GURL& url, 82 const GURL& url,
79 const GURL& favicon_url) 83 const GURL& favicon_url,
80 : title(title), url(url), favicon_url(favicon_url) {} 84 const GURL& thumbnail_url)
85 : title(title),
86 url(url),
87 favicon_url(favicon_url),
88 thumbnail_url(thumbnail_url) {}
81 89
82 PopularSites::PopularSites(const std::string& filename, 90 PopularSites::PopularSites(const std::string& filename,
83 net::URLRequestContextGetter* request_context, 91 net::URLRequestContextGetter* request_context,
84 const FinishedCallback& callback) 92 const FinishedCallback& callback)
85 : callback_(callback), weak_ptr_factory_(this) { 93 : callback_(callback), weak_ptr_factory_(this) {
86 base::FilePath path = GetPopularSitesPath(filename); 94 base::FilePath path = GetPopularSitesPath(filename);
87 downloader_.reset(new FileDownloader( 95 downloader_.reset(new FileDownloader(
88 GetPopularSitesURL(filename), path, request_context, 96 GetPopularSitesURL(filename), path, request_context,
89 base::Bind(&PopularSites::OnDownloadDone, base::Unretained(this), path))); 97 base::Bind(&PopularSites::OnDownloadDone, base::Unretained(this), path)));
90 } 98 }
(...skipping 17 matching lines...) Expand all
108 downloader_.reset(); 116 downloader_.reset();
109 } 117 }
110 118
111 void PopularSites::OnJsonParsed(scoped_ptr<std::vector<Site>> sites) { 119 void PopularSites::OnJsonParsed(scoped_ptr<std::vector<Site>> sites) {
112 if (sites) 120 if (sites)
113 sites_.swap(*sites); 121 sites_.swap(*sites);
114 else 122 else
115 sites_.clear(); 123 sites_.clear();
116 callback_.Run(!!sites); 124 callback_.Run(!!sites);
117 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698