Chromium Code Reviews| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 continue; | 122 continue; |
| 123 std::string favicon_url; | 123 std::string favicon_url; |
| 124 item->GetString("favicon_url", &favicon_url); | 124 item->GetString("favicon_url", &favicon_url); |
| 125 std::string thumbnail_url; | 125 std::string thumbnail_url; |
| 126 item->GetString("thumbnail_url", &thumbnail_url); | 126 item->GetString("thumbnail_url", &thumbnail_url); |
| 127 std::string large_icon_url; | 127 std::string large_icon_url; |
| 128 item->GetString("large_icon_url", &large_icon_url); | 128 item->GetString("large_icon_url", &large_icon_url); |
| 129 | 129 |
| 130 sites.emplace_back(title, GURL(url), GURL(favicon_url), | 130 sites.emplace_back(title, GURL(url), GURL(favicon_url), |
| 131 GURL(large_icon_url), GURL(thumbnail_url)); | 131 GURL(large_icon_url), GURL(thumbnail_url)); |
| 132 item->GetInteger("default_resource_id", &sites.back().default_resource_id); | |
| 132 } | 133 } |
| 133 return sites; | 134 return sites; |
| 134 } | 135 } |
| 135 | 136 |
| 137 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 138 void SetDefaultResourceForSite(base::ListValue* sites, | |
| 139 int index, | |
| 140 int resource_id) { | |
| 141 base::DictionaryValue* site; | |
| 142 if (!sites->GetDictionary(index, &site)) { | |
| 143 return; | |
| 144 } | |
| 145 site->SetInteger("default_resource_id", resource_id); | |
|
sfiera
2017/02/16 18:54:16
Feels a little weird to be storing a resource ID i
fhorschig
2017/02/17 16:24:04
Yes. With the first real fetch, this value is gone
| |
| 146 } | |
| 147 #endif | |
| 148 | |
| 136 // Creates the list of popular sites based on a snapshot available for mobile. | 149 // Creates the list of popular sites based on a snapshot available for mobile. |
| 137 std::unique_ptr<base::ListValue> DefaultPopularSites() { | 150 std::unique_ptr<base::ListValue> DefaultPopularSites() { |
| 138 #if defined(OS_ANDROID) || defined(OS_IOS) | 151 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 139 std::unique_ptr<base::ListValue> sites = | 152 std::unique_ptr<base::ListValue> sites = |
| 140 base::ListValue::From(base::JSONReader().ReadToValue( | 153 base::ListValue::From(base::JSONReader().ReadToValue( |
| 141 ResourceBundle::GetSharedInstance().GetRawDataResource( | 154 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 142 IDR_DEFAULT_POPULAR_SITES_JSON))); | 155 IDR_DEFAULT_POPULAR_SITES_JSON))); |
| 143 DCHECK(sites); | 156 DCHECK(sites); |
| 157 SetDefaultResourceForSite(sites.get(), 0, IDR_DEFAULT_POPULAR_SITES_ICON0); | |
|
sfiera
2017/02/16 18:54:16
Couldn't you write this as a foreach loop? Like:
fhorschig
2017/02/17 16:24:04
YES! This is exactly what I have been looking for.
| |
| 158 SetDefaultResourceForSite(sites.get(), 1, IDR_DEFAULT_POPULAR_SITES_ICON1); | |
| 159 SetDefaultResourceForSite(sites.get(), 2, IDR_DEFAULT_POPULAR_SITES_ICON2); | |
| 160 SetDefaultResourceForSite(sites.get(), 3, IDR_DEFAULT_POPULAR_SITES_ICON3); | |
| 161 SetDefaultResourceForSite(sites.get(), 4, IDR_DEFAULT_POPULAR_SITES_ICON4); | |
| 162 SetDefaultResourceForSite(sites.get(), 5, IDR_DEFAULT_POPULAR_SITES_ICON5); | |
| 163 SetDefaultResourceForSite(sites.get(), 6, IDR_DEFAULT_POPULAR_SITES_ICON6); | |
| 164 SetDefaultResourceForSite(sites.get(), 7, IDR_DEFAULT_POPULAR_SITES_ICON7); | |
| 144 return sites; | 165 return sites; |
| 145 #endif | 166 #endif |
| 146 return base::MakeUnique<base::ListValue>(); | 167 return base::MakeUnique<base::ListValue>(); |
| 147 } | 168 } |
| 148 | 169 |
| 149 } // namespace | 170 } // namespace |
| 150 | 171 |
| 151 PopularSites::Site::Site(const base::string16& title, | 172 PopularSites::Site::Site(const base::string16& title, |
| 152 const GURL& url, | 173 const GURL& url, |
| 153 const GURL& favicon_url, | 174 const GURL& favicon_url, |
| 154 const GURL& large_icon_url, | 175 const GURL& large_icon_url, |
| 155 const GURL& thumbnail_url) | 176 const GURL& thumbnail_url) |
| 156 : title(title), | 177 : title(title), |
| 157 url(url), | 178 url(url), |
| 158 favicon_url(favicon_url), | 179 favicon_url(favicon_url), |
| 159 large_icon_url(large_icon_url), | 180 large_icon_url(large_icon_url), |
| 160 thumbnail_url(thumbnail_url) {} | 181 thumbnail_url(thumbnail_url), |
| 182 default_resource_id(-1) {} // Valid resources would be >=0 | |
|
sfiera
2017/02/16 18:54:16
I don't think any comment is needed in addition to
fhorschig
2017/02/17 16:24:04
Done.
| |
| 161 | 183 |
| 162 PopularSites::Site::Site(const Site& other) = default; | 184 PopularSites::Site::Site(const Site& other) = default; |
| 163 | 185 |
| 164 PopularSites::Site::~Site() {} | 186 PopularSites::Site::~Site() {} |
| 165 | 187 |
| 166 PopularSitesImpl::PopularSitesImpl( | 188 PopularSitesImpl::PopularSitesImpl( |
| 167 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 189 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
| 168 PrefService* prefs, | 190 PrefService* prefs, |
| 169 const TemplateURLService* template_url_service, | 191 const TemplateURLService* template_url_service, |
| 170 VariationsService* variations_service, | 192 VariationsService* variations_service, |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 386 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
| 365 kPopularSitesDefaultVersion); | 387 kPopularSitesDefaultVersion); |
| 366 FetchPopularSites(); | 388 FetchPopularSites(); |
| 367 } else { | 389 } else { |
| 368 DLOG(WARNING) << "Download fallback site list failed"; | 390 DLOG(WARNING) << "Download fallback site list failed"; |
| 369 callback_.Run(false); | 391 callback_.Run(false); |
| 370 } | 392 } |
| 371 } | 393 } |
| 372 | 394 |
| 373 } // namespace ntp_tiles | 395 } // namespace ntp_tiles |
| OLD | NEW |