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

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

Issue 2667993003: Don't use LazyInstance in chrome/browser/image_decoder.* (Closed)
Patch Set: auto* Created 3 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/image_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 }; 64 };
65 65
66 enum ImageCodec { 66 enum ImageCodec {
67 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). 67 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage).
68 #if defined(OS_CHROMEOS) 68 #if defined(OS_CHROMEOS)
69 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. 69 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec.
70 ROBUST_PNG_CODEC, // Restrict decoding to robust PNG codec. 70 ROBUST_PNG_CODEC, // Restrict decoding to robust PNG codec.
71 #endif // defined(OS_CHROMEOS) 71 #endif // defined(OS_CHROMEOS)
72 }; 72 };
73 73
74 ImageDecoder(); 74 static ImageDecoder* GetInstance();
75 ~ImageDecoder();
76 75
77 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and 76 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and
78 // shrink_to_fit = false. 77 // shrink_to_fit = false.
79 static void Start(ImageRequest* image_request, 78 static void Start(ImageRequest* image_request,
80 std::vector<uint8_t> image_data); 79 std::vector<uint8_t> image_data);
81 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. 80 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy.
82 static void Start(ImageRequest* image_request, 81 static void Start(ImageRequest* image_request,
83 const std::string& image_data); 82 const std::string& image_data);
84 83
85 // Starts asynchronous image decoding. Once finished, the callback will be 84 // Starts asynchronous image decoding. Once finished, the callback will be
86 // posted back to image_request's |task_runner_|. 85 // posted back to image_request's |task_runner_|.
87 static void StartWithOptions(ImageRequest* image_request, 86 static void StartWithOptions(ImageRequest* image_request,
88 std::vector<uint8_t> image_data, 87 std::vector<uint8_t> image_data,
89 ImageCodec image_codec, 88 ImageCodec image_codec,
90 bool shrink_to_fit); 89 bool shrink_to_fit);
91 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. 90 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy.
92 static void StartWithOptions(ImageRequest* image_request, 91 static void StartWithOptions(ImageRequest* image_request,
93 const std::string& image_data, 92 const std::string& image_data,
94 ImageCodec image_codec, 93 ImageCodec image_codec,
95 bool shrink_to_fit); 94 bool shrink_to_fit);
96 95
97 // Removes all instances of |image_request| from |image_request_id_map_|, 96 // Removes all instances of |image_request| from |image_request_id_map_|,
98 // ensuring callbacks are not made to the image_request after it is destroyed. 97 // ensuring callbacks are not made to the image_request after it is destroyed.
99 static void Cancel(ImageRequest* image_request); 98 static void Cancel(ImageRequest* image_request);
100 99
101 private: 100 private:
102 using RequestMap = std::map<int, ImageRequest*>; 101 using RequestMap = std::map<int, ImageRequest*>;
103 102
103 ImageDecoder();
104 ~ImageDecoder() = delete;
105
104 void StartWithOptionsImpl(ImageRequest* image_request, 106 void StartWithOptionsImpl(ImageRequest* image_request,
105 std::vector<uint8_t> image_data, 107 std::vector<uint8_t> image_data,
106 ImageCodec image_codec, 108 ImageCodec image_codec,
107 bool shrink_to_fit); 109 bool shrink_to_fit);
108 110
109 void CancelImpl(ImageRequest* image_request); 111 void CancelImpl(ImageRequest* image_request);
110 112
111 // IPC message handlers. 113 // IPC message handlers.
112 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id); 114 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id);
113 void OnDecodeImageFailed(int request_id); 115 void OnDecodeImageFailed(int request_id);
114 116
115 // id to use for the next Start() request that comes in. 117 // id to use for the next Start() request that comes in.
116 int image_request_id_counter_; 118 int image_request_id_counter_;
117 119
118 // Map of request id's to ImageRequests. 120 // Map of request id's to ImageRequests.
119 RequestMap image_request_id_map_; 121 RequestMap image_request_id_map_;
120 122
121 // Protects |image_request_id_map_| and |image_request_id_counter_|. 123 // Protects |image_request_id_map_| and |image_request_id_counter_|.
122 base::Lock map_lock_; 124 base::Lock map_lock_;
123 125
124 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 126 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
125 }; 127 };
126 128
127 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ 129 #endif // CHROME_BROWSER_IMAGE_DECODER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/image_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698