Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_loader.h

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small changes based on review from Antony Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_
7 7
8 #include <map> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chrome/browser/image_decoder.h" 14 #include "chrome/browser/image_decoder.h"
15 15
16 class SkBitmap; 16 class SkBitmap;
17 17
18 namespace base { 18 namespace base {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 ImageInfo(const std::string& file_path, 60 ImageInfo(const std::string& file_path,
61 int pixels_per_side, 61 int pixels_per_side,
62 const LoadedCallback& loaded_cb); 62 const LoadedCallback& loaded_cb);
63 ~ImageInfo(); 63 ~ImageInfo();
64 64
65 const std::string file_path; 65 const std::string file_path;
66 const int pixels_per_side; 66 const int pixels_per_side;
67 const LoadedCallback loaded_cb; 67 const LoadedCallback loaded_cb;
68 }; 68 };
69 69
70 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; 70 // Contains attributes retain for after the image is decoded.
71 struct ImageData {
72 ImageData(const ImageInfo& image_info, const std::string& data);
73 ~ImageData();
74
75 const ImageInfo image_info;
76 std::vector<unsigned char> data;
77 };
78
79 typedef std::queue<ImageData> ImageDataQueue;
71 80
72 ~UserImageLoader() override; 81 ~UserImageLoader() override;
73 82
74 // Reads the image from |image_info.file_path| and starts the decoding 83 // Reads the image from |image_info.file_path| and starts the decoding
75 // process. This method may only be invoked via the |background_task_runner_|. 84 // process. This method may only be invoked via the |background_task_runner_|.
76 void ReadAndDecodeImage(const ImageInfo& image_info); 85 void ReadAndDecodeImage(const ImageInfo& image_info);
77 86
78 // Decodes the image |data|. This method may only be invoked via the 87 // Decodes the image |data|. This method may only be invoked via the
79 // |background_task_runner_|. 88 // |background_task_runner_|.
80 void DecodeImage(const scoped_ptr<std::string> data, 89 void DecodeImage(const scoped_ptr<std::string> data,
81 const ImageInfo& image_info); 90 const ImageInfo& image_info);
82 91
83 // ImageDecoder::Delegate implementation. These callbacks will only be invoked 92 // ImageDecoder::Delegate implementation. These callbacks will only be invoked
84 // via the |background_task_runner_|. 93 // via the |background_task_runner_|.
85 void OnImageDecoded(const ImageDecoder* decoder, 94 void OnImageDecoded(const SkBitmap& decoded_image) override;
86 const SkBitmap& decoded_image) override; 95 void OnDecodeImageFailed() override;
87 void OnDecodeImageFailed(const ImageDecoder* decoder) override;
88 96
89 // The foreground task runner on which |this| is instantiated, Start() is 97 // The foreground task runner on which |this| is instantiated, Start() is
90 // called and LoadedCallbacks are invoked. 98 // called and LoadedCallbacks are invoked.
91 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; 99 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_;
92 100
93 // The background task runner on which file I/O, image decoding and resizing 101 // The background task runner on which file I/O, image decoding and resizing
94 // are done. 102 // are done.
95 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 103 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
96 104
97 // Specify how the file should be decoded in the utility process. 105 // Specify how the file should be decoded in the utility process.
98 const ImageDecoder::ImageCodec image_codec_; 106 const ImageDecoder::ImageCodec image_codec_;
99 107
100 // Holds information about the images currently being decoded. Accessed via 108 // Holds information about the images currently being decoded. Accessed via
101 // |background_task_runner_| only. 109 // |background_task_runner_| only.
102 ImageInfoMap image_info_map_; 110 ImageDataQueue image_data_queue_;
103 111
104 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); 112 DISALLOW_COPY_AND_ASSIGN(UserImageLoader);
105 }; 113 };
106 114
107 } // namespace chromeos 115 } // namespace chromeos
108 116
109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ 117 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698