| 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/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 const gfx::ImageSkia overlay_; | 530 const gfx::ImageSkia overlay_; |
| 531 const color_utils::HSL hsl_shift_; | 531 const color_utils::HSL hsl_shift_; |
| 532 const int vertical_offset_; | 532 const int vertical_offset_; |
| 533 | 533 |
| 534 DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource); | 534 DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource); |
| 535 }; | 535 }; |
| 536 | 536 |
| 537 } // namespace | 537 } // namespace |
| 538 | 538 |
| 539 BrowserThemePack::~BrowserThemePack() { | 539 BrowserThemePack::~BrowserThemePack() { |
| 540 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 541 |
| 540 if (!data_pack_.get()) { | 542 if (!data_pack_.get()) { |
| 541 delete header_; | 543 delete header_; |
| 542 delete [] tints_; | 544 delete [] tints_; |
| 543 delete [] colors_; | 545 delete [] colors_; |
| 544 delete [] display_properties_; | 546 delete [] display_properties_; |
| 545 delete [] source_images_; | 547 delete [] source_images_; |
| 546 } | 548 } |
| 549 |
| 550 // |images_| will trigger the thread-checker as the images were built on the |
| 551 // UI thread and we are on the FILE thread. As a special case, it is safe to |
| 552 // delete them on the FILE thread because there are no remaining references to |
| 553 // this BrowserThemePack from the UI thread. Explicitly detach all the images |
| 554 // from the UI thread to suppress the error. |
| 555 for (auto image : images_) |
| 556 image.second.DetachFromThread(); |
| 557 |
| 558 // For the same reason, detach all of the |images_on_file_thread_| from |
| 559 // whatever thread they are attached to. (Note that |images_on_file_thread_| |
| 560 // is usually accessed on the FILE thread, but not always.) |
| 561 for (auto image : images_on_file_thread_) |
| 562 image.second.DetachFromThread(); |
| 547 } | 563 } |
| 548 | 564 |
| 549 // static | 565 // static |
| 550 void BrowserThemePack::BuildFromExtension( | 566 void BrowserThemePack::BuildFromExtension( |
| 551 const extensions::Extension* extension, | 567 const extensions::Extension* extension, |
| 552 scoped_refptr<BrowserThemePack> pack) { | 568 scoped_refptr<BrowserThemePack> pack) { |
| 553 DCHECK(extension); | 569 DCHECK(extension); |
| 554 DCHECK(extension->is_theme()); | 570 DCHECK(extension->is_theme()); |
| 555 DCHECK(!pack->is_valid()); | 571 DCHECK(!pack->is_valid()); |
| 556 | 572 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 587 // image if a caller of BrowserThemePack::GetImageNamed() requests an | 603 // image if a caller of BrowserThemePack::GetImageNamed() requests an |
| 588 // ImageSkiaRep for a scale factor not specified by the theme author. | 604 // ImageSkiaRep for a scale factor not specified by the theme author. |
| 589 // Callers of BrowserThemePack::GetImageNamed() to be able to retrieve | 605 // Callers of BrowserThemePack::GetImageNamed() to be able to retrieve |
| 590 // ImageSkiaReps for all supported scale factors. | 606 // ImageSkiaReps for all supported scale factors. |
| 591 for (ImageCache::iterator it = pack->images_.begin(); | 607 for (ImageCache::iterator it = pack->images_.begin(); |
| 592 it != pack->images_.end(); ++it) { | 608 it != pack->images_.end(); ++it) { |
| 593 const gfx::ImageSkia source_image_skia = it->second.AsImageSkia(); | 609 const gfx::ImageSkia source_image_skia = it->second.AsImageSkia(); |
| 594 ThemeImageSource* source = new ThemeImageSource(source_image_skia); | 610 ThemeImageSource* source = new ThemeImageSource(source_image_skia); |
| 595 // image_skia takes ownership of source. | 611 // image_skia takes ownership of source. |
| 596 gfx::ImageSkia image_skia(source, source_image_skia.size()); | 612 gfx::ImageSkia image_skia(source, source_image_skia.size()); |
| 613 // From now on, it->second will only be stored in |images_on_file_thread_|, |
| 614 // so detach it from the UI thread. |
| 615 it->second.DetachFromThread(); |
| 597 it->second = gfx::Image(image_skia); | 616 it->second = gfx::Image(image_skia); |
| 598 } | 617 } |
| 599 | 618 |
| 600 // Generate raw images (for new-tab-page attribution and background) for | 619 // Generate raw images (for new-tab-page attribution and background) for |
| 601 // any missing scale from an available scale image. | 620 // any missing scale from an available scale image. |
| 602 for (size_t i = 0; i < arraysize(kPreloadIDs); ++i) { | 621 for (size_t i = 0; i < arraysize(kPreloadIDs); ++i) { |
| 603 pack->GenerateRawImageForAllSupportedScales(kPreloadIDs[i]); | 622 pack->GenerateRawImageForAllSupportedScales(kPreloadIDs[i]); |
| 604 } | 623 } |
| 605 | 624 |
| 606 // The BrowserThemePack is now in a consistent state. | 625 // The BrowserThemePack is now in a consistent state. |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 false, | 1445 false, |
| 1427 &bitmap_data)) { | 1446 &bitmap_data)) { |
| 1428 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1447 NOTREACHED() << "Unable to encode theme image for prs_id=" |
| 1429 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1448 << prs_id << " for scale_factor=" << scale_factors_[i]; |
| 1430 break; | 1449 break; |
| 1431 } | 1450 } |
| 1432 image_memory_[scaled_raw_id] = | 1451 image_memory_[scaled_raw_id] = |
| 1433 base::RefCountedBytes::TakeVector(&bitmap_data); | 1452 base::RefCountedBytes::TakeVector(&bitmap_data); |
| 1434 } | 1453 } |
| 1435 } | 1454 } |
| OLD | NEW |