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 "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 threshold_to_get_any_largest_icon, | 204 threshold_to_get_any_largest_icon, |
| 205 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), | 205 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), |
| 206 &favicon_task_tracker_); | 206 &favicon_task_tracker_); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void AddToHomescreenDataFetcher::OnFaviconFetched( | 209 void AddToHomescreenDataFetcher::OnFaviconFetched( |
| 210 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 210 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 211 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 211 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 212 return; | 212 return; |
| 213 | 213 |
| 214 content::BrowserThread::PostTask( | 214 content::BrowserThread::PostBlockingPoolTask( |
| 215 content::BrowserThread::IO, | |
| 216 FROM_HERE, | 215 FROM_HERE, |
| 217 base::Bind(&AddToHomescreenDataFetcher::CreateLauncherIcon, | 216 base::Bind(&AddToHomescreenDataFetcher::CreateLauncherIconInBackground, |
| 218 this, | 217 this, bitmap_result)); |
| 219 bitmap_result)); | |
| 220 } | 218 } |
| 221 | 219 |
| 222 void AddToHomescreenDataFetcher::CreateLauncherIcon( | 220 void AddToHomescreenDataFetcher::CreateLauncherIconInBackground( |
| 223 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 221 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 224 if (!web_contents() || !weak_observer_) return; | 222 if (!web_contents() || !weak_observer_) return; |
|
Yaron
2016/08/09 20:52:19
Hmm. I don't think we should check the web_content
| |
| 225 | 223 |
| 226 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 224 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 227 SkBitmap icon_bitmap; | 225 SkBitmap icon_bitmap; |
| 228 if (bitmap_result.is_valid()) { | 226 if (bitmap_result.is_valid()) { |
| 229 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), | 227 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), |
| 230 bitmap_result.bitmap_data->size(), | 228 bitmap_result.bitmap_data->size(), |
| 231 &icon_bitmap); | 229 &icon_bitmap); |
| 232 } | 230 } |
| 233 | 231 |
| 234 bool is_generated = false; | 232 bool is_generated = false; |
| 235 if (weak_observer_) { | 233 if (weak_observer_) { |
| 236 icon_bitmap = weak_observer_->FinalizeLauncherIcon(icon_bitmap, | 234 icon_bitmap = weak_observer_->FinalizeLauncherIconInBackground( |
| 237 shortcut_info_.url, | 235 icon_bitmap, shortcut_info_.url, &is_generated); |
|
Yaron
2016/08/09 20:52:18
similarly, the url should be passed in, mutated (c
| |
| 238 &is_generated); | |
| 239 } | 236 } |
| 240 | 237 |
| 241 shortcut_info_.icon_url = is_generated ? GURL() : bitmap_result.icon_url; | 238 shortcut_info_.icon_url = is_generated ? GURL() : bitmap_result.icon_url; |
| 242 content::BrowserThread::PostTask( | 239 content::BrowserThread::PostTask( |
| 243 content::BrowserThread::UI, FROM_HERE, | 240 content::BrowserThread::UI, FROM_HERE, |
| 244 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this, | 241 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this, |
| 245 icon_bitmap)); | 242 icon_bitmap)); |
| 246 } | 243 } |
| 247 | 244 |
| 248 void AddToHomescreenDataFetcher::OnManifestIconFetched(const GURL& icon_url, | 245 void AddToHomescreenDataFetcher::OnManifestIconFetched(const GURL& icon_url, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 272 | 269 |
| 273 // If URL points to an offline content, get original URL. | 270 // If URL points to an offline content, get original URL. |
| 274 GURL online_url = | 271 GURL online_url = |
| 275 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( | 272 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( |
| 276 web_contents()->GetBrowserContext(), original_url); | 273 web_contents()->GetBrowserContext(), original_url); |
| 277 if (online_url.is_valid()) | 274 if (online_url.is_valid()) |
| 278 return online_url; | 275 return online_url; |
| 279 | 276 |
| 280 return original_url; | 277 return original_url; |
| 281 } | 278 } |
| OLD | NEW |