icon_loader.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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
  3. // found in the LICENSE file.
  4. #include <utility>
  5. #include "base/bind.h"
  6. #include "base/task_scheduler/post_task.h"
  7. #include "base/task_scheduler/task_traits.h"
  8. #include "base/threading/thread_task_runner_handle.h"
  9. #include "chrome/browser/icon_loader.h"
  10. #include "content/public/browser/browser_thread.h"
  11. using content::BrowserThread;
  12. // static
  13. IconLoader* IconLoader::Create(const base::FilePath& file_path,
  14. IconSize size,
  15. IconLoadedCallback callback) {
  16. return new IconLoader(file_path, size, callback);
  17. }
  18. void IconLoader::Start() {
  19. target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
  20. base::PostTaskWithTraits(
  21. FROM_HERE, traits(),
  22. base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)));
  23. }
  24. IconLoader::IconLoader(const base::FilePath& file_path,
  25. IconSize size,
  26. IconLoadedCallback callback)
  27. : file_path_(file_path), icon_size_(size), callback_(callback) {}
  28. IconLoader::~IconLoader() {}
  29. void IconLoader::ReadGroup() {
  30. group_ = GroupForFilepath(file_path_);
  31. GetReadIconTaskRunner()->PostTask(
  32. FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this)));
  33. }