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

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: Get rid of IDMap 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>
dcheng 2015/03/23 11:52:09 I think you can remove this #include.
Theresa 2015/03/23 17:33:09 Done.
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 {
19 class SequencedTaskRunner; 19 class SequencedTaskRunner;
20 } 20 }
21 21
22 namespace user_manager { 22 namespace user_manager {
23 class UserImage; 23 class UserImage;
24 } 24 }
25 25
26 namespace chromeos { 26 namespace chromeos {
27 27
28 // Helper that reads, decodes and optionally resizes an image on a background 28 // Helper that reads, decodes and optionally resizes an image on a background
29 // thread. Returns the image in the form of an SkBitmap. 29 // thread. Returns the image in the form of an SkBitmap.
30 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, 30 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader> {
31 public ImageDecoder::Delegate {
32 public: 31 public:
33 // Callback used to return the result of an image load operation. 32 // Callback used to return the result of an image load operation.
34 typedef base::Callback<void(const user_manager::UserImage& user_image)> 33 typedef base::Callback<void(const user_manager::UserImage& user_image)>
35 LoadedCallback; 34 LoadedCallback;
36 35
37 // All file I/O, decoding and resizing are done via |background_task_runner|. 36 // All file I/O, decoding and resizing are done via |background_task_runner|.
38 UserImageLoader( 37 UserImageLoader(
39 ImageDecoder::ImageCodec image_codec, 38 ImageDecoder::ImageCodec image_codec,
40 scoped_refptr<base::SequencedTaskRunner> background_task_runner); 39 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
41 40
(...skipping 18 matching lines...) Expand all
60 ImageInfo(const std::string& file_path, 59 ImageInfo(const std::string& file_path,
61 int pixels_per_side, 60 int pixels_per_side,
62 const LoadedCallback& loaded_cb); 61 const LoadedCallback& loaded_cb);
63 ~ImageInfo(); 62 ~ImageInfo();
64 63
65 const std::string file_path; 64 const std::string file_path;
66 const int pixels_per_side; 65 const int pixels_per_side;
67 const LoadedCallback loaded_cb; 66 const LoadedCallback loaded_cb;
68 }; 67 };
69 68
70 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; 69 class UserImageRequest : public ImageDecoder::ImageRequest {
70 public:
71 UserImageRequest(const ImageInfo& image_info,
72 const std::string& image_data,
73 UserImageLoader* user_image_loader);
71 74
72 ~UserImageLoader() override; 75 // ImageDecoder::ImageRequest implementation. These callbacks will only be
76 // invoked
dcheng 2015/03/23 11:52:08 This comment needs to be updated / rewrapped.
Theresa 2015/03/23 17:33:09 I rewrapped. I think the comment is still accurate
dcheng 2015/03/24 05:18:18 This class has no background_task_runner_ member i
Theresa 2015/03/24 23:51:42 Done.
77 // via the |background_task_runner_|.
78 void OnImageDecoded(const SkBitmap& decoded_image) override;
79 void OnDecodeImageFailed() override;
80
81 const ImageInfo image_info_;
dcheng 2015/03/23 11:52:08 Convention is to make these private and use access
Theresa 2015/03/23 17:33:09 Done.
82 std::vector<unsigned char> image_data_;
dcheng 2015/03/23 11:52:08 Having to copy this is pretty sad. But I don't see
Theresa 2015/03/23 17:33:09 Acknowledged.
83 UserImageLoader* user_image_loader_;
84
85 private:
86 ~UserImageRequest() override;
87 };
88
89 ~UserImageLoader();
73 90
74 // Reads the image from |image_info.file_path| and starts the decoding 91 // 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_|. 92 // process. This method may only be invoked via the |background_task_runner_|.
76 void ReadAndDecodeImage(const ImageInfo& image_info); 93 void ReadAndDecodeImage(const ImageInfo& image_info);
77 94
78 // Decodes the image |data|. This method may only be invoked via the 95 // Decodes the image |data|. This method may only be invoked via the
79 // |background_task_runner_|. 96 // |background_task_runner_|.
80 void DecodeImage(const scoped_ptr<std::string> data, 97 void DecodeImage(const scoped_ptr<std::string> data,
81 const ImageInfo& image_info); 98 const ImageInfo& image_info);
82 99
83 // ImageDecoder::Delegate implementation. These callbacks will only be invoked
84 // via the |background_task_runner_|.
85 void OnImageDecoded(const ImageDecoder* decoder,
86 const SkBitmap& decoded_image) override;
87 void OnDecodeImageFailed(const ImageDecoder* decoder) override;
88
89 // The foreground task runner on which |this| is instantiated, Start() is 100 // The foreground task runner on which |this| is instantiated, Start() is
90 // called and LoadedCallbacks are invoked. 101 // called and LoadedCallbacks are invoked.
91 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; 102 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_;
92 103
93 // The background task runner on which file I/O, image decoding and resizing 104 // The background task runner on which file I/O, image decoding and resizing
94 // are done. 105 // are done.
95 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 106 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
96 107
97 // Specify how the file should be decoded in the utility process. 108 // Specify how the file should be decoded in the utility process.
98 const ImageDecoder::ImageCodec image_codec_; 109 const ImageDecoder::ImageCodec image_codec_;
99 110
100 // Holds information about the images currently being decoded. Accessed via
101 // |background_task_runner_| only.
102 ImageInfoMap image_info_map_;
103
104 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); 111 DISALLOW_COPY_AND_ASSIGN(UserImageLoader);
105 }; 112 };
106 113
107 } // namespace chromeos 114 } // namespace chromeos
108 115
109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ 116 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698