OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/metro_pin_tab_helper_win.h" | 5 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 ~FaviconChooser() {} | 241 ~FaviconChooser() {} |
242 | 242 |
243 // Pin the page on the FILE thread using the current |best_candidate_| and | 243 // Pin the page on the FILE thread using the current |best_candidate_| and |
244 // delete the FaviconChooser. | 244 // delete the FaviconChooser. |
245 void UseChosenCandidate(); | 245 void UseChosenCandidate(); |
246 | 246 |
247 // Update the |best_candidate_| with the newly downloaded favicons provided. | 247 // Update the |best_candidate_| with the newly downloaded favicons provided. |
248 void UpdateCandidate(int id, | 248 void UpdateCandidate(int id, |
249 const GURL& image_url, | 249 const GURL& image_url, |
250 bool errored, | |
251 int requested_size, | 250 int requested_size, |
252 const std::vector<SkBitmap>& bitmaps); | 251 const std::vector<SkBitmap>& bitmaps); |
253 | 252 |
254 void AddPendingRequest(int request_id); | 253 void AddPendingRequest(int request_id); |
255 | 254 |
256 private: | 255 private: |
257 // The tab helper that this chooser is operating for. | 256 // The tab helper that this chooser is operating for. |
258 MetroPinTabHelper* helper_; | 257 MetroPinTabHelper* helper_; |
259 | 258 |
260 // Title and URL of the page being pinned. | 259 // Title and URL of the page being pinned. |
(...skipping 23 matching lines...) Expand all Loading... |
284 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 283 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
285 scoped_refptr<PinPageTaskRunner> runner( | 284 scoped_refptr<PinPageTaskRunner> runner( |
286 new PinPageTaskRunner(title_, url_, best_candidate_)); | 285 new PinPageTaskRunner(title_, url_, best_candidate_)); |
287 runner->Run(); | 286 runner->Run(); |
288 helper_->FaviconDownloaderFinished(); | 287 helper_->FaviconDownloaderFinished(); |
289 } | 288 } |
290 | 289 |
291 void MetroPinTabHelper::FaviconChooser::UpdateCandidate( | 290 void MetroPinTabHelper::FaviconChooser::UpdateCandidate( |
292 int id, | 291 int id, |
293 const GURL& image_url, | 292 const GURL& image_url, |
294 bool errored, | |
295 int requested_size, | 293 int requested_size, |
296 const std::vector<SkBitmap>& bitmaps) { | 294 const std::vector<SkBitmap>& bitmaps) { |
297 const int kMaxIconSize = 32; | 295 const int kMaxIconSize = 32; |
298 | 296 |
299 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 297 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
300 | 298 |
301 std::set<int>::iterator iter = in_progress_requests_.find(id); | 299 std::set<int>::iterator iter = in_progress_requests_.find(id); |
302 // Check that this request is one of ours. | 300 // Check that this request is one of ours. |
303 if (iter == in_progress_requests_.end()) | 301 if (iter == in_progress_requests_.end()) |
304 return; | 302 return; |
305 | 303 |
306 in_progress_requests_.erase(iter); | 304 in_progress_requests_.erase(iter); |
307 | 305 |
308 // Process the bitmaps, keeping the one that is best so far. | 306 // Process the bitmaps, keeping the one that is best so far. |
309 if (!errored) { | 307 for (std::vector<SkBitmap>::const_iterator iter = bitmaps.begin(); |
310 for (std::vector<SkBitmap>::const_iterator iter = bitmaps.begin(); | 308 iter != bitmaps.end(); |
311 iter != bitmaps.end(); | 309 ++iter) { |
312 ++iter) { | |
313 | 310 |
314 // If the new bitmap is too big, ignore it. | 311 // If the new bitmap is too big, ignore it. |
315 if (iter->height() > kMaxIconSize || iter->width() > kMaxIconSize) | 312 if (iter->height() > kMaxIconSize || iter->width() > kMaxIconSize) |
316 continue; | 313 continue; |
317 | 314 |
318 // If we don't have a best candidate yet, this is better so just grab it. | 315 // If we don't have a best candidate yet, this is better so just grab it. |
319 if (best_candidate_.isNull()) { | 316 if (best_candidate_.isNull()) { |
320 best_candidate_ = *gfx::ImageSkia(*iter).DeepCopy().get(); | 317 best_candidate_ = *gfx::ImageSkia(*iter).DeepCopy().get(); |
321 continue; | 318 continue; |
322 } | 319 } |
323 | 320 |
324 // If it is smaller than our best one so far, ignore it. | 321 // If it is smaller than our best one so far, ignore it. |
325 if (iter->height() <= best_candidate_.height() || | 322 if (iter->height() <= best_candidate_.height() || |
326 iter->width() <= best_candidate_.width()) { | 323 iter->width() <= best_candidate_.width()) { |
327 continue; | 324 continue; |
328 } | 325 } |
329 | 326 |
330 // Othewise it is our new best candidate. | 327 // Othewise it is our new best candidate. |
331 best_candidate_ = *gfx::ImageSkia(*iter).DeepCopy().get(); | 328 best_candidate_ = *gfx::ImageSkia(*iter).DeepCopy().get(); |
332 } | |
333 } | 329 } |
334 | 330 |
335 // If there are no more outstanding requests, pin the page on the FILE thread. | 331 // If there are no more outstanding requests, pin the page on the FILE thread. |
336 // Once this happens this downloader has done its job, so delete it. | 332 // Once this happens this downloader has done its job, so delete it. |
337 if (in_progress_requests_.empty()) | 333 if (in_progress_requests_.empty()) |
338 UseChosenCandidate(); | 334 UseChosenCandidate(); |
339 } | 335 } |
340 | 336 |
341 void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) { | 337 void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) { |
342 in_progress_requests_.insert(request_id); | 338 in_progress_requests_.insert(request_id); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 419 |
424 void MetroPinTabHelper::DidUpdateFaviconURL( | 420 void MetroPinTabHelper::DidUpdateFaviconURL( |
425 int32 page_id, | 421 int32 page_id, |
426 const std::vector<content::FaviconURL>& candidates) { | 422 const std::vector<content::FaviconURL>& candidates) { |
427 favicon_url_candidates_ = candidates; | 423 favicon_url_candidates_ = candidates; |
428 } | 424 } |
429 | 425 |
430 void MetroPinTabHelper::DidDownloadFavicon( | 426 void MetroPinTabHelper::DidDownloadFavicon( |
431 int id, | 427 int id, |
432 const GURL& image_url, | 428 const GURL& image_url, |
433 bool errored, | |
434 int requested_size, | 429 int requested_size, |
435 const std::vector<SkBitmap>& bitmaps) { | 430 const std::vector<SkBitmap>& bitmaps) { |
436 if (favicon_chooser_.get()) { | 431 if (favicon_chooser_.get()) { |
437 favicon_chooser_->UpdateCandidate(id, image_url, errored, | 432 favicon_chooser_->UpdateCandidate(id, image_url, requested_size, bitmaps); |
438 requested_size, bitmaps); | |
439 } | 433 } |
440 } | 434 } |
441 | 435 |
442 void MetroPinTabHelper::UnPinPageFromStartScreen() { | 436 void MetroPinTabHelper::UnPinPageFromStartScreen() { |
443 HMODULE metro_module = base::win::GetMetroModule(); | 437 HMODULE metro_module = base::win::GetMetroModule(); |
444 if (!metro_module) | 438 if (!metro_module) |
445 return; | 439 return; |
446 | 440 |
447 base::win::MetroUnPinFromStartScreen metro_un_pin_from_start_screen = | 441 base::win::MetroUnPinFromStartScreen metro_un_pin_from_start_screen = |
448 reinterpret_cast<base::win::MetroUnPinFromStartScreen>( | 442 reinterpret_cast<base::win::MetroUnPinFromStartScreen>( |
449 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen")); | 443 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen")); |
450 if (!metro_un_pin_from_start_screen) { | 444 if (!metro_un_pin_from_start_screen) { |
451 NOTREACHED(); | 445 NOTREACHED(); |
452 return; | 446 return; |
453 } | 447 } |
454 | 448 |
455 GURL url = web_contents()->GetURL(); | 449 GURL url = web_contents()->GetURL(); |
456 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 450 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
457 metro_un_pin_from_start_screen(tile_id, | 451 metro_un_pin_from_start_screen(tile_id, |
458 base::Bind(&PinPageReportUmaCallback)); | 452 base::Bind(&PinPageReportUmaCallback)); |
459 } | 453 } |
460 | 454 |
461 void MetroPinTabHelper::FaviconDownloaderFinished() { | 455 void MetroPinTabHelper::FaviconDownloaderFinished() { |
462 favicon_chooser_.reset(); | 456 favicon_chooser_.reset(); |
463 } | 457 } |
OLD | NEW |