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

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

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

Powered by Google App Engine
This is Rietveld 408576698