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

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

Issue 1159363002: [Download Notification] Show preview if downloaded file is image (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments #12 Created 5 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_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/files/file.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/sequence_checker.h" 15 #include "base/sequence_checker.h"
15 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
17 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
18 #include "content/public/browser/utility_process_host.h" 19 #include "content/public/browser/utility_process_host.h"
19 #include "content/public/browser/utility_process_host_client.h" 20 #include "content/public/browser/utility_process_host_client.h"
20 21
21 class SkBitmap; 22 class SkBitmap;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 base::SequenceChecker sequence_checker_; 65 base::SequenceChecker sequence_checker_;
65 }; 66 };
66 67
67 enum ImageCodec { 68 enum ImageCodec {
68 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). 69 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage).
69 #if defined(OS_CHROMEOS) 70 #if defined(OS_CHROMEOS)
70 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. 71 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec.
71 #endif // defined(OS_CHROMEOS) 72 #endif // defined(OS_CHROMEOS)
72 }; 73 };
73 74
75 static void StartByFilePath(
76 ImageRequest* image_request,
77 const base::FilePath& image_file_path);
78
74 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and 79 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and
75 // shrink_to_fit = false. 80 // shrink_to_fit = false.
76 static void Start(ImageRequest* image_request, 81 static void Start(ImageRequest* image_request,
77 const std::string& image_data); 82 const std::string& image_data);
78 83
79 // Starts asynchronous image decoding. Once finished, the callback will be 84 // Starts asynchronous image decoding. Once finished, the callback will be
80 // posted back to image_request's |task_runner_|. 85 // posted back to image_request's |task_runner_|.
81 static void StartWithOptions(ImageRequest* image_request, 86 static void StartWithOptions(ImageRequest* image_request,
82 const std::string& image_data, 87 const std::string& image_data,
83 ImageCodec image_codec, 88 ImageCodec image_codec,
84 bool shrink_to_fit); 89 bool shrink_to_fit);
85 90
86 // Removes all instances of |image_request| from |image_request_id_map_|, 91 // Removes all instances of |image_request| from |image_request_id_map_|,
87 // ensuring callbacks are not made to the image_request after it is destroyed. 92 // ensuring callbacks are not made to the image_request after it is destroyed.
88 static void Cancel(ImageRequest* image_request); 93 static void Cancel(ImageRequest* image_request);
89 94
90 private: 95 private:
91 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>; 96 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>;
92 97
93 using RequestMap = std::map<int, ImageRequest*>; 98 using RequestMap = std::map<int, ImageRequest*>;
94 99
95 ImageDecoder(); 100 ImageDecoder();
96 // It's a reference counted object, so destructor is private. 101 // It's a reference counted object, so destructor is private.
97 ~ImageDecoder() override; 102 ~ImageDecoder() override;
98 103
99 // Sends a request to the sandboxed process to decode the image. Starts 104 // Sends a request to the sandboxed process to decode the image. Starts
100 // batch mode if necessary. If the utility process fails to start, 105 // batch mode if necessary. If the utility process fails to start,
101 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|. 106 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|.
102 void DecodeImageInSandbox(int request_id, 107 void DecodeImageInSandbox(int request_id,
108 base::File image_file,
103 const std::vector<unsigned char>& image_data, 109 const std::vector<unsigned char>& image_data,
104 ImageCodec image_codec, 110 ImageCodec image_codec,
105 bool shrink_to_fit); 111 bool shrink_to_fit);
106 112
107 void StartWithOptionsImpl(ImageRequest* image_request, 113 void StartWithOptionsImpl(ImageRequest* image_request,
114 const base::FilePath& image_file_path,
108 const std::string& image_data, 115 const std::string& image_data,
109 ImageCodec image_codec, 116 ImageCodec image_codec,
110 bool shrink_to_fit); 117 bool shrink_to_fit);
111 void CancelImpl(ImageRequest* image_request); 118 void CancelImpl(ImageRequest* image_request);
112 119
113 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|. 120 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|.
114 // If the utility process fails to start, the method resets 121 // If the utility process fails to start, the method resets
115 // |utility_process_host_| and returns. 122 // |utility_process_host_| and returns.
116 void StartBatchMode(); 123 void StartBatchMode();
117 124
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 156 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
150 157
151 // Calls StopBatchMode() after |kBatchModeTimeoutSeconds| have elapsed, 158 // Calls StopBatchMode() after |kBatchModeTimeoutSeconds| have elapsed,
152 // unless a new decoding request resets the timer. 159 // unless a new decoding request resets the timer.
153 scoped_ptr<base::DelayTimer<ImageDecoder>> batch_mode_timer_; 160 scoped_ptr<base::DelayTimer<ImageDecoder>> batch_mode_timer_;
154 161
155 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 162 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
156 }; 163 };
157 164
158 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ 165 #endif // CHROME_BROWSER_IMAGE_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698