| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/local_discovery/pwg_raster_converter.h" | 5 #include "chrome/browser/printing/pwg_raster_converter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "chrome/common/chrome_utility_messages.h" | 19 #include "chrome/common/chrome_utility_messages.h" |
| 20 #include "chrome/common/chrome_utility_printing_messages.h" | 20 #include "chrome/common/chrome_utility_printing_messages.h" |
| 21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/cloud_devices/common/cloud_device_description.h" | 22 #include "components/cloud_devices/common/cloud_device_description.h" |
| 23 #include "components/cloud_devices/common/printer_description.h" | 23 #include "components/cloud_devices/common/printer_description.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/child_process_data.h" | 25 #include "content/public/browser/child_process_data.h" |
| 26 #include "content/public/browser/utility_process_host.h" | 26 #include "content/public/browser/utility_process_host.h" |
| 27 #include "content/public/browser/utility_process_host_client.h" | 27 #include "content/public/browser/utility_process_host_client.h" |
| 28 #include "printing/pdf_render_settings.h" | 28 #include "printing/pdf_render_settings.h" |
| 29 #include "printing/pwg_raster_settings.h" | 29 #include "printing/pwg_raster_settings.h" |
| 30 #include "printing/units.h" | 30 #include "printing/units.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/gfx/geometry/rect.h" | 32 #include "ui/gfx/geometry/rect.h" |
| 33 #include "ui/gfx/geometry/size.h" | 33 #include "ui/gfx/geometry/size.h" |
| 34 | 34 |
| 35 namespace local_discovery { | 35 namespace printing { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 using content::BrowserThread; | 39 using content::BrowserThread; |
| 40 | 40 |
| 41 class FileHandlers { | 41 class FileHandlers { |
| 42 public: | 42 public: |
| 43 FileHandlers() {} | 43 FileHandlers() {} |
| 44 | 44 |
| 45 ~FileHandlers() { | 45 ~FileHandlers() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // 2. Create file on the FILE thread. | 107 // 2. Create file on the FILE thread. |
| 108 // 3. Start utility process and start conversion on the IO thread. | 108 // 3. Start utility process and start conversion on the IO thread. |
| 109 // 4. Run result callback on the UI thread. | 109 // 4. Run result callback on the UI thread. |
| 110 // 5. Instance is destroyed from any thread that has the last reference. | 110 // 5. Instance is destroyed from any thread that has the last reference. |
| 111 // 6. FileHandlers destroyed on the FILE thread. | 111 // 6. FileHandlers destroyed on the FILE thread. |
| 112 // This step posts |FileHandlers| to be destroyed on the FILE thread. | 112 // This step posts |FileHandlers| to be destroyed on the FILE thread. |
| 113 // All these steps work sequentially, so no data should be accessed | 113 // All these steps work sequentially, so no data should be accessed |
| 114 // simultaneously by several threads. | 114 // simultaneously by several threads. |
| 115 class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient { | 115 class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient { |
| 116 public: | 116 public: |
| 117 explicit PwgUtilityProcessHostClient( | 117 PwgUtilityProcessHostClient( |
| 118 const printing::PdfRenderSettings& settings, | 118 const PdfRenderSettings& settings, |
| 119 const printing::PwgRasterSettings& bitmap_settings); | 119 const PwgRasterSettings& bitmap_settings); |
| 120 | 120 |
| 121 void Convert(base::RefCountedMemory* data, | 121 void Convert(base::RefCountedMemory* data, |
| 122 const PWGRasterConverter::ResultCallback& callback); | 122 const PWGRasterConverter::ResultCallback& callback); |
| 123 | 123 |
| 124 // UtilityProcessHostClient implementation. | 124 // UtilityProcessHostClient implementation. |
| 125 void OnProcessCrashed(int exit_code) override; | 125 void OnProcessCrashed(int exit_code) override; |
| 126 bool OnMessageReceived(const IPC::Message& message) override; | 126 bool OnMessageReceived(const IPC::Message& message) override; |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 ~PwgUtilityProcessHostClient() override; | 129 ~PwgUtilityProcessHostClient() override; |
| 130 | 130 |
| 131 // Message handlers. | 131 // Message handlers. |
| 132 void OnProcessStarted(); | 132 void OnProcessStarted(); |
| 133 void OnSucceeded(); | 133 void OnSucceeded(); |
| 134 void OnFailed(); | 134 void OnFailed(); |
| 135 | 135 |
| 136 void RunCallback(bool success); | 136 void RunCallback(bool success); |
| 137 | 137 |
| 138 void StartProcessOnIOThread(); | 138 void StartProcessOnIOThread(); |
| 139 | 139 |
| 140 void RunCallbackOnUIThread(bool success); | 140 void RunCallbackOnUIThread(bool success); |
| 141 void OnFilesReadyOnUIThread(); | 141 void OnFilesReadyOnUIThread(); |
| 142 | 142 |
| 143 scoped_ptr<FileHandlers, BrowserThread::DeleteOnFileThread> files_; | 143 scoped_ptr<FileHandlers, BrowserThread::DeleteOnFileThread> files_; |
| 144 printing::PdfRenderSettings settings_; | 144 PdfRenderSettings settings_; |
| 145 printing::PwgRasterSettings bitmap_settings_; | 145 PwgRasterSettings bitmap_settings_; |
| 146 PWGRasterConverter::ResultCallback callback_; | 146 PWGRasterConverter::ResultCallback callback_; |
| 147 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 147 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(PwgUtilityProcessHostClient); | 149 DISALLOW_COPY_AND_ASSIGN(PwgUtilityProcessHostClient); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 PwgUtilityProcessHostClient::PwgUtilityProcessHostClient( | 152 PwgUtilityProcessHostClient::PwgUtilityProcessHostClient( |
| 153 const printing::PdfRenderSettings& settings, | 153 const printing::PdfRenderSettings& settings, |
| 154 const printing::PwgRasterSettings& bitmap_settings) | 154 const printing::PwgRasterSettings& bitmap_settings) |
| 155 : settings_(settings), bitmap_settings_(bitmap_settings) {} | 155 : settings_(settings), bitmap_settings_(bitmap_settings) {} |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 result.odd_page_transform = printing::TRANSFORM_FLIP_HORIZONTAL; | 356 result.odd_page_transform = printing::TRANSFORM_FLIP_HORIZONTAL; |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 result.rotate_all_pages = raster_capability.value().rotate_all_pages; | 360 result.rotate_all_pages = raster_capability.value().rotate_all_pages; |
| 361 | 361 |
| 362 result.reverse_page_order = raster_capability.value().reverse_order_streaming; | 362 result.reverse_page_order = raster_capability.value().reverse_order_streaming; |
| 363 return result; | 363 return result; |
| 364 } | 364 } |
| 365 | 365 |
| 366 } // namespace local_discovery | 366 } // namespace printing |
| OLD | NEW |