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

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

Issue 10830111: [cros] Encode user images when set from WebUI (regression fix). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_
7 7
8 #include <map> 8 #include <map>
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 MessageLoop; 16 class MessageLoop;
17 class SkBitmap; 17 class SkBitmap;
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 class UserImage; 21 class UserImage;
22 22
23 // A facility to read a file containing user image asynchronously in the IO 23 // A facility to read a file containing user image asynchronously in the IO
24 // thread. Returns the image in the form of an SkBitmap. 24 // thread. Returns the image in the form of an SkBitmap.
25 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, 25 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>,
26 public ImageDecoder::Delegate { 26 public ImageDecoder::Delegate {
27 public: 27 public:
28 // Callback used to inidicate that image has been loaded. 28 // Callback used to indicate that image has been loaded.
29 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback; 29 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback;
30 30
31 UserImageLoader(); 31 UserImageLoader();
32 32
33 // Start reading the image from |filepath| on the file thread. Calls 33 // Start reading the image from |filepath| on the file thread. Calls
34 // |loaded_cb| when image has been successfully loaded. 34 // |loaded_cb| when image has been successfully loaded.
35 // If |size| is positive, image is cropped and (if needed) downsized to 35 // If |size| is positive, image is cropped and (if needed) downsized to
36 // |size|x|size| pixels. 36 // |size|x|size| pixels.
37 // If |load_raw_image| is true, raw image is also passed to callback. 37 void Start(const std::string& filepath, int size,
38 void Start(const std::string& filepath, int size, bool load_raw_image,
39 const LoadedCallback& loaded_cb); 38 const LoadedCallback& loaded_cb);
40 39
41 private: 40 private:
42 friend class base::RefCountedThreadSafe<UserImageLoader>; 41 friend class base::RefCountedThreadSafe<UserImageLoader>;
43 42
44 // Contains attributes we need to know about each image we decode. 43 // Contains attributes we need to know about each image we decode.
45 struct ImageInfo { 44 struct ImageInfo {
46 ImageInfo(int size, bool load_raw_image, const LoadedCallback& loaded_cb); 45 ImageInfo(int size, const LoadedCallback& loaded_cb);
47 ~ImageInfo(); 46 ~ImageInfo();
48 47
49 int size; 48 const int size;
50 bool load_raw_image; 49 const LoadedCallback loaded_cb;
51 LoadedCallback loaded_cb;
52 }; 50 };
53 51
54 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; 52 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap;
55 53
56 virtual ~UserImageLoader(); 54 virtual ~UserImageLoader();
57 55
58 // Method that reads the file on the file thread and starts decoding it in 56 // Method that reads the file on the file thread and starts decoding it in
59 // sandboxed process. 57 // sandboxed process.
60 void LoadImage(const std::string& filepath, const ImageInfo& image_info); 58 void LoadImage(const std::string& filepath, const ImageInfo& image_info);
61 59
62 // ImageDecoder::Delegate implementation. 60 // ImageDecoder::Delegate implementation.
63 virtual void OnImageDecoded(const ImageDecoder* decoder, 61 virtual void OnImageDecoded(const ImageDecoder* decoder,
64 const SkBitmap& decoded_image) OVERRIDE; 62 const SkBitmap& decoded_image) OVERRIDE;
65 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; 63 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
66 64
67 // The message loop object of the thread in which we notify the delegate. 65 // The message loop object of the thread in which we notify the delegate.
68 MessageLoop* target_message_loop_; 66 MessageLoop* target_message_loop_;
69 67
70 // Holds info structures about all images we're trying to decode. 68 // Holds info structures about all images we're trying to decode.
71 // Accessed only on FILE thread. 69 // Accessed only on FILE thread.
72 ImageInfoMap image_info_map_; 70 ImageInfoMap image_info_map_;
73 71
74 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); 72 DISALLOW_COPY_AND_ASSIGN(UserImageLoader);
75 }; 73 };
76 74
77 } // namespace chromeos 75 } // namespace chromeos
78 76
79 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ 77 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698