icon_loader_auralinux.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chrome/browser/icon_loader.h"
  5. #include "base/bind.h"
  6. #include "base/message_loop/message_loop.h"
  7. #include "base/nix/mime_util_xdg.h"
  8. #include "ui/views/linux_ui/linux_ui.h"
  9. // static
  10. IconLoader::IconGroup IconLoader::GroupForFilepath(
  11. const base::FilePath& file_path) {
  12. return base::nix::GetFileMimeType(file_path);
  13. }
  14. // static
  15. scoped_refptr<base::TaskRunner> IconLoader::GetReadIconTaskRunner() {
  16. // ReadIcon() calls into views::LinuxUI and GTK2 code, so it must be on the UI
  17. // thread.
  18. return content::BrowserThread::GetTaskRunnerForThread(
  19. content::BrowserThread::UI);
  20. }
  21. void IconLoader::ReadIcon() {
  22. int size_pixels = 0;
  23. switch (icon_size_) {
  24. case IconLoader::SMALL:
  25. size_pixels = 16;
  26. break;
  27. case IconLoader::NORMAL:
  28. size_pixels = 32;
  29. break;
  30. case IconLoader::LARGE:
  31. size_pixels = 48;
  32. break;
  33. default:
  34. NOTREACHED();
  35. }
  36. std::unique_ptr<gfx::Image> image;
  37. views::LinuxUI* ui = views::LinuxUI::instance();
  38. if (ui) {
  39. image = std::make_unique<gfx::Image>(
  40. ui->GetIconForContentType(group_, size_pixels));
  41. if (image->IsEmpty())
  42. image = nullptr;
  43. }
  44. target_task_runner_->PostTask(
  45. FROM_HERE, base::BindOnce(callback_, base::Passed(&image), group_));
  46. delete this;
  47. }