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

Side by Side Diff: chrome/browser/image_decoder.h

Issue 2715153006: Set desired_image_size when decoding images for NTP Tile icons. (Closed)
Patch Set: comment formatting Created 3 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 (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_IMAGE_DECODER_H_ 5 #ifndef CHROME_BROWSER_IMAGE_DECODER_H_
6 #define CHROME_BROWSER_IMAGE_DECODER_H_ 6 #define CHROME_BROWSER_IMAGE_DECODER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/sequence_checker.h" 14 #include "base/sequence_checker.h"
15 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 17
18 namespace gfx {
19 class Size;
20 } // namespace gfx
21
18 class SkBitmap; 22 class SkBitmap;
19 23
20 // This is a helper class for decoding images safely in a sandboxed service. To 24 // This is a helper class for decoding images safely in a sandboxed service. To
21 // use this, call ImageDecoder::Start(...) or 25 // use this, call ImageDecoder::Start(...) or
22 // ImageDecoder::StartWithOptions(...) on any thread. 26 // ImageDecoder::StartWithOptions(...) on any thread.
23 // 27 //
24 // ImageRequest::OnImageDecoded or ImageRequest::OnDecodeImageFailed is posted 28 // ImageRequest::OnImageDecoded or ImageRequest::OnDecodeImageFailed is posted
25 // back to the |task_runner_| associated with the ImageRequest. 29 // back to the |task_runner_| associated with the ImageRequest.
26 // 30 //
27 // The Cancel() method runs on whichever thread called it. 31 // The Cancel() method runs on whichever thread called it.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and 80 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and
77 // shrink_to_fit = false. 81 // shrink_to_fit = false.
78 static void Start(ImageRequest* image_request, 82 static void Start(ImageRequest* image_request,
79 std::vector<uint8_t> image_data); 83 std::vector<uint8_t> image_data);
80 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. 84 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy.
81 static void Start(ImageRequest* image_request, 85 static void Start(ImageRequest* image_request,
82 const std::string& image_data); 86 const std::string& image_data);
83 87
84 // Starts asynchronous image decoding. Once finished, the callback will be 88 // Starts asynchronous image decoding. Once finished, the callback will be
85 // posted back to image_request's |task_runner_|. 89 // posted back to image_request's |task_runner_|.
90 // For images with multiple frames (e.g. ico files), a frame with a size as
91 // close as possible to |desired_image_frame_size| is chosen (tries to take
92 // one in larger size if there's no precise match). Passing gfx::Size() as
93 // |desired_image_frame_size| is also supported and will result in chosing the
94 // smallest available size.
86 static void StartWithOptions(ImageRequest* image_request, 95 static void StartWithOptions(ImageRequest* image_request,
87 std::vector<uint8_t> image_data, 96 std::vector<uint8_t> image_data,
88 ImageCodec image_codec, 97 ImageCodec image_codec,
89 bool shrink_to_fit); 98 bool shrink_to_fit,
99 const gfx::Size& desired_image_frame_size);
90 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. 100 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy.
91 static void StartWithOptions(ImageRequest* image_request, 101 static void StartWithOptions(ImageRequest* image_request,
92 const std::string& image_data, 102 const std::string& image_data,
93 ImageCodec image_codec, 103 ImageCodec image_codec,
94 bool shrink_to_fit); 104 bool shrink_to_fit);
95 105
96 // Removes all instances of |image_request| from |image_request_id_map_|, 106 // Removes all instances of |image_request| from |image_request_id_map_|,
97 // ensuring callbacks are not made to the image_request after it is destroyed. 107 // ensuring callbacks are not made to the image_request after it is destroyed.
98 static void Cancel(ImageRequest* image_request); 108 static void Cancel(ImageRequest* image_request);
99 109
100 private: 110 private:
101 using RequestMap = std::map<int, ImageRequest*>; 111 using RequestMap = std::map<int, ImageRequest*>;
102 112
103 ImageDecoder(); 113 ImageDecoder();
104 ~ImageDecoder() = delete; 114 ~ImageDecoder() = delete;
105 115
106 void StartWithOptionsImpl(ImageRequest* image_request, 116 void StartWithOptionsImpl(ImageRequest* image_request,
107 std::vector<uint8_t> image_data, 117 std::vector<uint8_t> image_data,
108 ImageCodec image_codec, 118 ImageCodec image_codec,
109 bool shrink_to_fit); 119 bool shrink_to_fit,
120 const gfx::Size& desired_image_frame_size);
110 121
111 void CancelImpl(ImageRequest* image_request); 122 void CancelImpl(ImageRequest* image_request);
112 123
113 // IPC message handlers. 124 // IPC message handlers.
114 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id); 125 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id);
115 void OnDecodeImageFailed(int request_id); 126 void OnDecodeImageFailed(int request_id);
116 127
117 // id to use for the next Start() request that comes in. 128 // id to use for the next Start() request that comes in.
118 int image_request_id_counter_; 129 int image_request_id_counter_;
119 130
120 // Map of request id's to ImageRequests. 131 // Map of request id's to ImageRequests.
121 RequestMap image_request_id_map_; 132 RequestMap image_request_id_map_;
122 133
123 // Protects |image_request_id_map_| and |image_request_id_counter_|. 134 // Protects |image_request_id_map_| and |image_request_id_counter_|.
124 base::Lock map_lock_; 135 base::Lock map_lock_;
125 136
126 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 137 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
127 }; 138 };
128 139
129 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ 140 #endif // CHROME_BROWSER_IMAGE_DECODER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/hats/hats_notification_controller_unittest.cc ('k') | chrome/browser/image_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698