OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/ntp_tiles/popular_sites_impl.h" | 5 #include "components/ntp_tiles/popular_sites_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 continue; | 123 continue; |
124 std::string favicon_url; | 124 std::string favicon_url; |
125 item->GetString("favicon_url", &favicon_url); | 125 item->GetString("favicon_url", &favicon_url); |
126 std::string thumbnail_url; | 126 std::string thumbnail_url; |
127 item->GetString("thumbnail_url", &thumbnail_url); | 127 item->GetString("thumbnail_url", &thumbnail_url); |
128 std::string large_icon_url; | 128 std::string large_icon_url; |
129 item->GetString("large_icon_url", &large_icon_url); | 129 item->GetString("large_icon_url", &large_icon_url); |
130 | 130 |
131 sites.emplace_back(title, GURL(url), GURL(favicon_url), | 131 sites.emplace_back(title, GURL(url), GURL(favicon_url), |
132 GURL(large_icon_url), GURL(thumbnail_url)); | 132 GURL(large_icon_url), GURL(thumbnail_url)); |
| 133 item->GetInteger("default_icon_resource", |
| 134 &sites.back().default_icon_resource); |
133 } | 135 } |
134 return sites; | 136 return sites; |
135 } | 137 } |
136 | 138 |
| 139 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_ANDROID) || defined(OS_IOS)) |
| 140 void SetDefaultResourceForSite(int index, |
| 141 int resource_id, |
| 142 base::ListValue* sites) { |
| 143 base::DictionaryValue* site; |
| 144 if (!sites->GetDictionary(index, &site)) { |
| 145 return; |
| 146 } |
| 147 site->SetInteger("default_icon_resource", resource_id); |
| 148 } |
| 149 #endif |
| 150 |
137 // Creates the list of popular sites based on a snapshot available for mobile. | 151 // Creates the list of popular sites based on a snapshot available for mobile. |
138 std::unique_ptr<base::ListValue> DefaultPopularSites() { | 152 std::unique_ptr<base::ListValue> DefaultPopularSites() { |
139 #if defined(OS_ANDROID) || defined(OS_IOS) | 153 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 154 return base::MakeUnique<base::ListValue>(); |
| 155 #else |
140 std::unique_ptr<base::ListValue> sites = | 156 std::unique_ptr<base::ListValue> sites = |
141 base::ListValue::From(base::JSONReader().ReadToValue( | 157 base::ListValue::From(base::JSONReader::Read( |
142 ResourceBundle::GetSharedInstance().GetRawDataResource( | 158 ResourceBundle::GetSharedInstance().GetRawDataResource( |
143 IDR_DEFAULT_POPULAR_SITES_JSON))); | 159 IDR_DEFAULT_POPULAR_SITES_JSON))); |
144 DCHECK(sites); | 160 DCHECK(sites); |
| 161 #if defined(GOOGLE_CHROME_BUILD) |
| 162 int index = 0; |
| 163 for (int icon_resource : |
| 164 {IDR_DEFAULT_POPULAR_SITES_ICON0, IDR_DEFAULT_POPULAR_SITES_ICON1, |
| 165 IDR_DEFAULT_POPULAR_SITES_ICON2, IDR_DEFAULT_POPULAR_SITES_ICON3, |
| 166 IDR_DEFAULT_POPULAR_SITES_ICON4, IDR_DEFAULT_POPULAR_SITES_ICON5, |
| 167 IDR_DEFAULT_POPULAR_SITES_ICON6, IDR_DEFAULT_POPULAR_SITES_ICON7}) { |
| 168 SetDefaultResourceForSite(index++, icon_resource, sites.get()); |
| 169 } |
| 170 #endif // GOOGLE_CHROME_BUILD |
145 return sites; | 171 return sites; |
146 #endif | 172 #endif // OS_ANDROID || OS_IOS |
147 return base::MakeUnique<base::ListValue>(); | |
148 } | 173 } |
149 | 174 |
150 } // namespace | 175 } // namespace |
151 | 176 |
152 PopularSites::Site::Site(const base::string16& title, | 177 PopularSites::Site::Site(const base::string16& title, |
153 const GURL& url, | 178 const GURL& url, |
154 const GURL& favicon_url, | 179 const GURL& favicon_url, |
155 const GURL& large_icon_url, | 180 const GURL& large_icon_url, |
156 const GURL& thumbnail_url) | 181 const GURL& thumbnail_url) |
157 : title(title), | 182 : title(title), |
158 url(url), | 183 url(url), |
159 favicon_url(favicon_url), | 184 favicon_url(favicon_url), |
160 large_icon_url(large_icon_url), | 185 large_icon_url(large_icon_url), |
161 thumbnail_url(thumbnail_url) {} | 186 thumbnail_url(thumbnail_url), |
| 187 default_icon_resource(-1) {} |
162 | 188 |
163 PopularSites::Site::Site(const Site& other) = default; | 189 PopularSites::Site::Site(const Site& other) = default; |
164 | 190 |
165 PopularSites::Site::~Site() {} | 191 PopularSites::Site::~Site() {} |
166 | 192 |
167 PopularSitesImpl::PopularSitesImpl( | 193 PopularSitesImpl::PopularSitesImpl( |
168 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 194 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
169 PrefService* prefs, | 195 PrefService* prefs, |
170 const TemplateURLService* template_url_service, | 196 const TemplateURLService* template_url_service, |
171 VariationsService* variations_service, | 197 VariationsService* variations_service, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 412 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
387 kPopularSitesDefaultVersion); | 413 kPopularSitesDefaultVersion); |
388 FetchPopularSites(); | 414 FetchPopularSites(); |
389 } else { | 415 } else { |
390 DLOG(WARNING) << "Download fallback site list failed"; | 416 DLOG(WARNING) << "Download fallback site list failed"; |
391 callback_.Run(false); | 417 callback_.Run(false); |
392 } | 418 } |
393 } | 419 } |
394 | 420 |
395 } // namespace ntp_tiles | 421 } // namespace ntp_tiles |
OLD | NEW |