| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/printing/print_composite_client.h" |
| 6 |
| 7 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "base/time/time.h" |
| 9 #include "content/public/browser/notification_details.h" |
| 10 #include "content/public/browser/notification_service.h" |
| 11 #include "content/public/browser/notification_source.h" |
| 12 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/browser/print_subframe_details.h" |
| 14 |
| 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintCompositeClient); |
| 16 |
| 17 namespace printing { |
| 18 |
| 19 PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents) |
| 20 : weak_factory_(this) { |
| 21 registrar_.Add(this, content::NOTIFICATION_PRINT_SUBFRAME_BEGIN, |
| 22 content::NotificationService::AllSources()); |
| 23 } |
| 24 |
| 25 PrintCompositeClient::~PrintCompositeClient() {} |
| 26 |
| 27 void PrintCompositeClient::Observe( |
| 28 int type, |
| 29 const content::NotificationSource& source, |
| 30 const content::NotificationDetails& details) { |
| 31 DCHECK_EQ(content::NOTIFICATION_PRINT_SUBFRAME_BEGIN, type); |
| 32 content::PrintSubframeDetails* print_details = |
| 33 content::Details<content::PrintSubframeDetails>(details).ptr(); |
| 34 PrepareSubframe(print_details->subframe_id, print_details->page_num); |
| 35 } |
| 36 |
| 37 void PrintCompositeClient::OnIsReadyToComposite( |
| 38 int page_num, |
| 39 base::SharedMemoryHandle handle, |
| 40 uint32_t data_size, |
| 41 const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback, |
| 42 scoped_refptr<base::SequencedTaskRunner> callback_task_runner, |
| 43 bool status) { |
| 44 if (status) { |
| 45 // Send to composite. |
| 46 Composite(handle, data_size, callback, callback_task_runner); |
| 47 } else { |
| 48 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 49 FROM_HERE, base::Bind(&PrintCompositeClient::DoComposite, |
| 50 weak_factory_.GetWeakPtr(), page_num, handle, |
| 51 data_size, callback, callback_task_runner), |
| 52 base::TimeDelta::FromMilliseconds(100)); |
| 53 } |
| 54 } |
| 55 |
| 56 void PrintCompositeClient::DoComposite( |
| 57 int page_num, |
| 58 base::SharedMemoryHandle handle, |
| 59 uint32_t data_size, |
| 60 const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback, |
| 61 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { |
| 62 IsReadyToComposite(page_num, |
| 63 base::Bind(&PrintCompositeClient::OnIsReadyToComposite, |
| 64 base::Unretained(this), page_num, handle, |
| 65 data_size, callback, callback_task_runner), |
| 66 base::ThreadTaskRunnerHandle::Get()); |
| 67 } |
| 68 |
| 69 } // namespace printing |
| OLD | NEW |