| 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 #ifndef CHROME_BROWSER_ICON_LOADER_H_ | 5 #ifndef CHROME_BROWSER_ICON_LOADER_H_ |
| 6 #define CHROME_BROWSER_ICON_LOADER_H_ | 6 #define CHROME_BROWSER_ICON_LOADER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/task_scheduler/task_traits.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 18 | 19 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
| 20 // | 21 // |
| 21 // A facility to read a file containing an icon asynchronously in the IO | 22 // A facility to read a file containing an icon asynchronously in the IO |
| 22 // thread. Returns the icon in the form of an ImageSkia. | 23 // thread. Returns the icon in the form of an ImageSkia. |
| 23 // | 24 // |
| 24 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 private: | 60 private: |
| 60 IconLoader(const base::FilePath& file_path, | 61 IconLoader(const base::FilePath& file_path, |
| 61 IconSize size, | 62 IconSize size, |
| 62 IconLoadedCallback callback); | 63 IconLoadedCallback callback); |
| 63 | 64 |
| 64 ~IconLoader(); | 65 ~IconLoader(); |
| 65 | 66 |
| 66 // Given a file path, get the group for the given file. | 67 // Given a file path, get the group for the given file. |
| 67 static IconGroup GroupForFilepath(const base::FilePath& file_path); | 68 static IconGroup GroupForFilepath(const base::FilePath& file_path); |
| 68 | 69 |
| 69 // The thread ReadIcon() should be called on. | 70 // The TaskRunner that ReadIcon() must be called on. |
| 70 static content::BrowserThread::ID ReadIconThreadID(); | 71 static scoped_refptr<base::TaskRunner> ReadIconTaskRunner(); |
| 71 | 72 |
| 72 void ReadGroup(); | 73 void ReadGroup(); |
| 73 void OnReadGroup(); | 74 void OnReadGroup(); |
| 74 void ReadIcon(); | 75 void ReadIcon(); |
| 75 | 76 |
| 77 // The traits of the tasks posted by this class. These operations may block, |
| 78 // because they are fetching icons from the disk, yet the result will be seen |
| 79 // by the user so they should be prioritized accordingly. |
| 80 static constexpr base::TaskTraits traits() { |
| 81 return {base::MayBlock(), base::TaskPriority::USER_VISIBLE}; |
| 82 } |
| 83 |
| 76 // The task runner object of the thread in which we notify the delegate. | 84 // The task runner object of the thread in which we notify the delegate. |
| 77 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; | 85 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; |
| 78 | 86 |
| 79 base::FilePath file_path_; | 87 base::FilePath file_path_; |
| 80 | 88 |
| 81 IconGroup group_; | 89 IconGroup group_; |
| 82 | 90 |
| 83 IconSize icon_size_; | 91 IconSize icon_size_; |
| 84 | 92 |
| 85 IconLoadedCallback callback_; | 93 IconLoadedCallback callback_; |
| 86 | 94 |
| 87 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 95 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
| 88 }; | 96 }; |
| 89 | 97 |
| 90 #endif // CHROME_BROWSER_ICON_LOADER_H_ | 98 #endif // CHROME_BROWSER_ICON_LOADER_H_ |
| OLD | NEW |