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

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

Issue 1068743002: Fix two race conditions in ImageDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused WeakPtr<>. Created 5 years, 8 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') | chrome/browser/image_decoder.cc » ('J')
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // Starts asynchronous image decoding. Once finished, the callback will be 69 // Starts asynchronous image decoding. Once finished, the callback will be
70 // posted back to image_request's |task_runner_|. 70 // posted back to image_request's |task_runner_|.
71 static void StartWithOptions(ImageRequest* image_request, 71 static void StartWithOptions(ImageRequest* image_request,
72 const std::string& image_data, 72 const std::string& image_data,
73 ImageCodec image_codec, 73 ImageCodec image_codec,
74 bool shrink_to_fit); 74 bool shrink_to_fit);
75 75
76 // Removes all instances of image_request from |image_request_id_map_|, 76 // Removes all instances of image_request from |image_request_id_map_|,
77 // ensuring callbacks are not made to the image_request after it is destroyed. 77 // ensuring callbacks are not made to the image_request after it is destroyed.
78 // May be called from any thread.
79 // NOTE: This may block if called from a different thread than the
80 // ImageRequest's rask runner.
Lei Zhang 2015/04/08 01:30:10 typo
Anand Mistry (off Chromium) 2015/04/08 03:13:46 Done.
78 static void Cancel(ImageRequest* image_request); 81 static void Cancel(ImageRequest* image_request);
79 82
80 private: 83 private:
84 class Job;
81 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>; 85 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>;
82 86
83 ImageDecoder(); 87 ImageDecoder();
84 // It's a reference counted object, so destructor is private. 88 // It's a reference counted object, so destructor is private.
85 ~ImageDecoder() override; 89 ~ImageDecoder() override;
86 90
87 // Sends a request to the sandboxed process to decode the image. Starts 91 // Sends a request to the sandboxed process to decode the image. Starts
88 // batch mode if necessary. If the utility process fails to start, 92 // batch mode if necessary. If the utility process fails to start,
89 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|. 93 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|.
90 void DecodeImageInSandbox(ImageRequest* image_request, 94 void DecodeImageInSandbox(int request_id,
91 const std::vector<unsigned char>& image_data, 95 const std::vector<unsigned char>& image_data,
92 ImageCodec image_codec, 96 ImageCodec image_codec,
93 bool shrink_to_fit); 97 bool shrink_to_fit);
94 98
99 void StartWithOptionsImpl(ImageRequest* image_request,
100 const std::string& image_data,
101 ImageCodec image_codec,
102 bool shrink_to_fit);
95 void CancelImpl(ImageRequest* image_request); 103 void CancelImpl(ImageRequest* image_request);
96 104
97 using RequestMap = std::map<int, ImageRequest*>; 105 using RequestMap = std::map<int, scoped_refptr<Job>>;
98 106
99 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|. 107 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|.
100 // If the utility process fails to start, the method resets 108 // If the utility process fails to start, the method resets
101 // |utility_process_host_| and returns. 109 // |utility_process_host_| and returns.
102 void StartBatchMode(); 110 void StartBatchMode();
103 111
104 // Stops batch mode if no requests have come in since 112 // Stops batch mode if no requests have come in since
105 // kBatchModeTimeoutSeconds. 113 // kBatchModeTimeoutSeconds.
106 void StopBatchMode(); 114 void StopBatchMode();
107 115
108 // Overidden from UtilityProcessHostClient. 116 // Overidden from UtilityProcessHostClient.
109 bool OnMessageReceived(const IPC::Message& message) override; 117 bool OnMessageReceived(const IPC::Message& message) override;
110 118
111 // IPC message handlers. 119 // IPC message handlers.
112 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id); 120 void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id);
113 void OnDecodeImageFailed(int request_id); 121 void OnDecodeImageFailed(int request_id);
114 122
123 // Removes the job from the map of requests.
124 void RemoveJob(const scoped_refptr<Job>& job);
125
115 // id to use for the next Start request that comes in. 126 // id to use for the next Start request that comes in.
116 int image_request_id_counter_; 127 int image_request_id_counter_;
117 128
118 // Map of request id's to ImageRequests. 129 // Map of request id's to ImageRequests.
119 RequestMap image_request_id_map_; 130 RequestMap image_request_id_map_;
120 131
121 // Protects |image_request_id_map_| and |image_request_id_counter_|. 132 // Protects |image_request_id_map_| and |image_request_id_counter_|.
122 base::Lock map_lock_; 133 base::Lock map_lock_;
123 134
124 // The UtilityProcessHost requests are sent to. 135 // The UtilityProcessHost requests are sent to.
125 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 136 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
126 137
127 // Calls StopBatchMode after kBatchModeTimeoutSeconds have elapsed. 138 // Calls StopBatchMode after kBatchModeTimeoutSeconds have elapsed.
128 base::RepeatingTimer<ImageDecoder> batch_mode_timer_; 139 base::RepeatingTimer<ImageDecoder> batch_mode_timer_;
129 140
130 // The time Start was last called. 141 // The time Start was last called.
131 base::TimeTicks last_request_; 142 base::TimeTicks last_request_;
132 143
133 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 144 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
134 }; 145 };
135 146
136 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ 147 #endif // CHROME_BROWSER_IMAGE_DECODER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/image_decoder.cc » ('j') | chrome/browser/image_decoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698