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

Unified Diff: chrome/browser/printing/print_composite_client.cc

Issue 2653963002: [Experimental] Supporting OOPIF printing
Patch Set: Rename service, fix for webview, and connect to DiscardableMemoryManager Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/print_composite_client.cc
diff --git a/chrome/browser/printing/print_composite_client.cc b/chrome/browser/printing/print_composite_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c6dfe9fca7c12ffe4d40ae4436322b0cdbb7fd25
--- /dev/null
+++ b/chrome/browser/printing/print_composite_client.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/printing/print_composite_client.h"
+
+#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/time.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/print_subframe_details.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintCompositeClient);
+
+namespace printing {
+
+PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents)
+ : weak_factory_(this) {
+ registrar_.Add(this, content::NOTIFICATION_PRINT_SUBFRAME_BEGIN,
+ content::NotificationService::AllSources());
+}
+
+PrintCompositeClient::~PrintCompositeClient() {}
+
+void PrintCompositeClient::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(content::NOTIFICATION_PRINT_SUBFRAME_BEGIN, type);
+ content::PrintSubframeDetails* print_details =
+ content::Details<content::PrintSubframeDetails>(details).ptr();
+ PrepareSubframe(print_details->subframe_id, print_details->page_num);
+}
+
+void PrintCompositeClient::OnIsReadyToComposite(
+ int page_num,
+ base::SharedMemoryHandle handle,
+ uint32_t data_size,
+ const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
+ bool status) {
+ if (status) {
+ // Send to composite.
+ Composite(handle, data_size, callback, callback_task_runner);
+ } else {
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, base::Bind(&PrintCompositeClient::DoComposite,
+ weak_factory_.GetWeakPtr(), page_num, handle,
+ data_size, callback, callback_task_runner),
+ base::TimeDelta::FromMilliseconds(100));
+ }
+}
+
+void PrintCompositeClient::DoComposite(
+ int page_num,
+ base::SharedMemoryHandle handle,
+ uint32_t data_size,
+ const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
+ IsReadyToComposite(page_num,
+ base::Bind(&PrintCompositeClient::OnIsReadyToComposite,
+ base::Unretained(this), page_num, handle,
+ data_size, callback, callback_task_runner),
+ base::ThreadTaskRunnerHandle::Get());
+}
+
+} // namespace printing
« no previous file with comments | « chrome/browser/printing/print_composite_client.h ('k') | chrome/browser/printing/print_preview_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698