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 // TODO(fhorschig): Add ids here. |
| 164 for (int icon_resource : std::vector<int>{}) { |
| 165 SetDefaultResourceForSite(index++, icon_resource, sites.get()); |
| 166 } |
| 167 #endif // GOOGLE_CHROME_BUILD |
145 return sites; | 168 return sites; |
146 #endif | 169 #endif // OS_ANDROID || OS_IOS |
147 return base::MakeUnique<base::ListValue>(); | |
148 } | 170 } |
149 | 171 |
150 } // namespace | 172 } // namespace |
151 | 173 |
152 PopularSites::Site::Site(const base::string16& title, | 174 PopularSites::Site::Site(const base::string16& title, |
153 const GURL& url, | 175 const GURL& url, |
154 const GURL& favicon_url, | 176 const GURL& favicon_url, |
155 const GURL& large_icon_url, | 177 const GURL& large_icon_url, |
156 const GURL& thumbnail_url) | 178 const GURL& thumbnail_url) |
157 : title(title), | 179 : title(title), |
158 url(url), | 180 url(url), |
159 favicon_url(favicon_url), | 181 favicon_url(favicon_url), |
160 large_icon_url(large_icon_url), | 182 large_icon_url(large_icon_url), |
161 thumbnail_url(thumbnail_url) {} | 183 thumbnail_url(thumbnail_url), |
| 184 default_icon_resource(-1) {} |
162 | 185 |
163 PopularSites::Site::Site(const Site& other) = default; | 186 PopularSites::Site::Site(const Site& other) = default; |
164 | 187 |
165 PopularSites::Site::~Site() {} | 188 PopularSites::Site::~Site() {} |
166 | 189 |
167 PopularSitesImpl::PopularSitesImpl( | 190 PopularSitesImpl::PopularSitesImpl( |
168 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 191 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
169 PrefService* prefs, | 192 PrefService* prefs, |
170 const TemplateURLService* template_url_service, | 193 const TemplateURLService* template_url_service, |
171 VariationsService* variations_service, | 194 VariationsService* variations_service, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 409 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
387 kPopularSitesDefaultVersion); | 410 kPopularSitesDefaultVersion); |
388 FetchPopularSites(); | 411 FetchPopularSites(); |
389 } else { | 412 } else { |
390 DLOG(WARNING) << "Download fallback site list failed"; | 413 DLOG(WARNING) << "Download fallback site list failed"; |
391 callback_.Run(false); | 414 callback_.Run(false); |
392 } | 415 } |
393 } | 416 } |
394 | 417 |
395 } // namespace ntp_tiles | 418 } // namespace ntp_tiles |
OLD | NEW |