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

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: ran git cl format as suggested 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).
Mathieu 2017/03/01 14:36:23 mention that people can pass gfx::Size() and what
tschumann 2017/03/01 19:40:08 Done.
86 static void StartWithOptions(ImageRequest* image_request, 93 static void StartWithOptions(ImageRequest* image_request,
87 std::vector<uint8_t> image_data, 94 std::vector<uint8_t> image_data,
88 ImageCodec image_codec, 95 ImageCodec image_codec,
89 bool shrink_to_fit); 96 bool shrink_to_fit,
97 const gfx::Size& desired_image_frame_size);
90 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. 98 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy.
91 static void StartWithOptions(ImageRequest* image_request, 99 static void StartWithOptions(ImageRequest* image_request,
92 const std::string& image_data, 100 const std::string& image_data,
93 ImageCodec image_codec, 101 ImageCodec image_codec,
94 bool shrink_to_fit); 102 bool shrink_to_fit);
95 103
96 // Removes all instances of |image_request| from |image_request_id_map_|, 104 // 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. 105 // ensuring callbacks are not made to the image_request after it is destroyed.
98 static void Cancel(ImageRequest* image_request); 106 static void Cancel(ImageRequest* image_request);
99 107
100 private: 108 private:
101 using RequestMap = std::map<int, ImageRequest*>; 109 using RequestMap = std::map<int, ImageRequest*>;
102 110
103 ImageDecoder(); 111 ImageDecoder();
104 ~ImageDecoder() = delete; 112 ~ImageDecoder() = delete;
105 113
106 void StartWithOptionsImpl(ImageRequest* image_request, 114 void StartWithOptionsImpl(ImageRequest* image_request,
107 std::vector<uint8_t> image_data, 115 std::vector<uint8_t> image_data,
108 ImageCodec image_codec, 116 ImageCodec image_codec,
109 bool shrink_to_fit); 117 bool shrink_to_fit,
118 const gfx::Size& desired_image_frame_size);
110 119
111 void CancelImpl(ImageRequest* image_request); 120 void CancelImpl(ImageRequest* image_request);
112 121
113 // IPC message handlers. 122 // IPC message handlers.
114 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id); 123 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id);
115 void OnDecodeImageFailed(int request_id); 124 void OnDecodeImageFailed(int request_id);
116 125
117 // id to use for the next Start() request that comes in. 126 // id to use for the next Start() request that comes in.
118 int image_request_id_counter_; 127 int image_request_id_counter_;
119 128
120 // Map of request id's to ImageRequests. 129 // Map of request id's to ImageRequests.
121 RequestMap image_request_id_map_; 130 RequestMap image_request_id_map_;
122 131
123 // Protects |image_request_id_map_| and |image_request_id_counter_|. 132 // Protects |image_request_id_map_| and |image_request_id_counter_|.
124 base::Lock map_lock_; 133 base::Lock map_lock_;
125 134
126 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 135 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
127 }; 136 };
128 137
129 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ 138 #endif // CHROME_BROWSER_IMAGE_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698