| OLD | NEW | 
|---|
| 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/compiler_specific.h" | 12 #include "base/compiler_specific.h" | 
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" | 
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" | 
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" | 
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" | 
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" | 
| 18 #include "content/public/browser/utility_process_host.h" | 18 #include "content/public/browser/utility_process_host.h" | 
| 19 #include "content/public/browser/utility_process_host_client.h" | 19 #include "content/public/browser/utility_process_host_client.h" | 
|  | 20 #include "services/image_decoder/public/interfaces/image_decoder.mojom.h" | 
| 20 | 21 | 
| 21 class SkBitmap; | 22 class SkBitmap; | 
| 22 | 23 | 
| 23 // This is a helper class for decoding images safely in a utility process. To | 24 // This is a helper class for decoding images safely in a utility process. To | 
| 24 // use this, call ImageDecoder::Start(...) or | 25 // use this, call ImageDecoder::Start(...) or | 
| 25 // ImageDecoder::StartWithOptions(...) on any thread. | 26 // ImageDecoder::StartWithOptions(...) on any thread. | 
| 26 // | 27 // | 
| 27 // Internally, most of the work happens on the IO thread, and then | 28 // Internally, most of the work happens on the IO thread, and then | 
| 28 // the callback (ImageRequest::OnImageDecoded or | 29 // the callback (ImageRequest::OnImageDecoded or | 
| 29 // ImageRequest::OnDecodeImageFailed) is posted back to the |task_runner_| | 30 // ImageRequest::OnDecodeImageFailed) is posted back to the |task_runner_| | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 118 | 119 | 
| 119   // Overidden from UtilityProcessHostClient. | 120   // Overidden from UtilityProcessHostClient. | 
| 120   void OnProcessCrashed(int exit_code) override; | 121   void OnProcessCrashed(int exit_code) override; | 
| 121   void OnProcessLaunchFailed() override; | 122   void OnProcessLaunchFailed() override; | 
| 122   bool OnMessageReceived(const IPC::Message& message) override; | 123   bool OnMessageReceived(const IPC::Message& message) override; | 
| 123 | 124 | 
| 124   // IPC message handlers. | 125   // IPC message handlers. | 
| 125   void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id); | 126   void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id); | 
| 126   void OnDecodeImageFailed(int request_id); | 127   void OnDecodeImageFailed(int request_id); | 
| 127 | 128 | 
|  | 129   // Mojo IPC callback. | 
|  | 130   void OnDecodeImageDone(int request_id, skia::BitmapPtr image); | 
|  | 131 | 
| 128   // Removes the job from the map of requests. | 132   // Removes the job from the map of requests. | 
| 129   void RemoveJob(const scoped_refptr<Job>& job); | 133   void RemoveJob(const scoped_refptr<Job>& job); | 
| 130 | 134 | 
| 131   // id to use for the next Start request that comes in. | 135   // id to use for the next Start request that comes in. | 
| 132   int image_request_id_counter_; | 136   int image_request_id_counter_; | 
| 133 | 137 | 
| 134   // Map of request id's to ImageRequests. | 138   // Map of request id's to ImageRequests. | 
| 135   RequestMap image_request_id_map_; | 139   RequestMap image_request_id_map_; | 
| 136 | 140 | 
| 137   // Protects |image_request_id_map_| and |image_request_id_counter_|. | 141   // Protects |image_request_id_map_| and |image_request_id_counter_|. | 
| 138   base::Lock map_lock_; | 142   base::Lock map_lock_; | 
| 139 | 143 | 
| 140   // The UtilityProcessHost requests are sent to. | 144   // The UtilityProcessHost requests are sent to. | 
| 141   base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 145   base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 
| 142 | 146 | 
| 143   // Calls StopBatchMode after kBatchModeTimeoutSeconds have elapsed. | 147   // Calls StopBatchMode after kBatchModeTimeoutSeconds have elapsed. | 
| 144   base::RepeatingTimer<ImageDecoder> batch_mode_timer_; | 148   base::RepeatingTimer<ImageDecoder> batch_mode_timer_; | 
| 145 | 149 | 
| 146   // The time Start was last called. | 150   // The time Start was last called. | 
| 147   base::TimeTicks last_request_; | 151   base::TimeTicks last_request_; | 
| 148 | 152 | 
|  | 153   // Mojo service connection. Must always be bound/reset and used on the IO | 
|  | 154   // thread. | 
|  | 155   services::ImageDecoderPtr decoder_; | 
|  | 156 | 
| 149   DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | 157   DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | 
| 150 }; | 158 }; | 
| 151 | 159 | 
| 152 #endif  // CHROME_BROWSER_IMAGE_DECODER_H_ | 160 #endif  // CHROME_BROWSER_IMAGE_DECODER_H_ | 
| OLD | NEW | 
|---|