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

Side by Side Diff: chrome/renderer/mock_render_thread.cc

Issue 7365003: Print Preview: Make preview generation event driven to eliminate synchronous messages. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: clang fix Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/mock_render_thread.h ('k') | chrome/renderer/print_web_view_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer/mock_render_thread.h" 5 #include "chrome/renderer/mock_render_thread.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "chrome/common/extensions/extension_messages.h" 11 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/print_messages.h" 12 #include "chrome/common/print_messages.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
16 #include "ipc/ipc_message_utils.h" 16 #include "ipc/ipc_message_utils.h"
17 #include "ipc/ipc_sync_message.h" 17 #include "ipc/ipc_sync_message.h"
18 #include "printing/print_job_constants.h" 18 #include "printing/print_job_constants.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 MockRenderThread::MockRenderThread() 21 MockRenderThread::MockRenderThread()
22 : routing_id_(0), 22 : routing_id_(0),
23 opener_id_(0), 23 opener_id_(0),
24 widget_(NULL), 24 widget_(NULL),
25 reply_deserializer_(NULL), 25 reply_deserializer_(NULL),
26 printer_(new MockPrinter), 26 printer_(new MockPrinter),
27 print_dialog_user_response_(true), 27 print_dialog_user_response_(true),
28 cancel_print_preview_(false) { 28 print_preview_pages_remaining_(0) {
29 } 29 }
30 30
31 MockRenderThread::~MockRenderThread() { 31 MockRenderThread::~MockRenderThread() {
32 } 32 }
33 33
34 // Called by the Widget. The routing_id must match the routing id assigned 34 // Called by the Widget. The routing_id must match the routing id assigned
35 // to the Widget in reply to ViewHostMsg_CreateWidget message. 35 // to the Widget in reply to ViewHostMsg_CreateWidget message.
36 void MockRenderThread::AddRoute(int32 routing_id, 36 void MockRenderThread::AddRoute(int32 routing_id,
37 IPC::Channel::Listener* listener) { 37 IPC::Channel::Listener* listener) {
38 EXPECT_EQ(routing_id_, routing_id); 38 EXPECT_EQ(routing_id_, routing_id);
(...skipping 15 matching lines...) Expand all
54 void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { 54 void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
55 filter->OnFilterRemoved(); 55 filter->OnFilterRemoved();
56 } 56 }
57 57
58 58
59 bool MockRenderThread::IsIncognitoProcess() const { 59 bool MockRenderThread::IsIncognitoProcess() const {
60 return false; 60 return false;
61 } 61 }
62 62
63 // Called by the Widget. Used to send messages to the browser. 63 // Called by the Widget. Used to send messages to the browser.
64 // We short-circuit the mechanim and handle the messages right here on this 64 // We short-circuit the mechanism and handle the messages right here on this
65 // class. 65 // class.
66 bool MockRenderThread::Send(IPC::Message* msg) { 66 bool MockRenderThread::Send(IPC::Message* msg) {
67 // We need to simulate a synchronous channel, thus we are going to receive 67 // We need to simulate a synchronous channel, thus we are going to receive
68 // through this function messages, messages with reply and reply messages. 68 // through this function messages, messages with reply and reply messages.
69 // We can only handle one synchronous message at a time. 69 // We can only handle one synchronous message at a time.
70 if (msg->is_reply()) { 70 if (msg->is_reply()) {
71 if (reply_deserializer_.get()) { 71 if (reply_deserializer_.get()) {
72 reply_deserializer_->SerializeOutputParameters(*msg); 72 reply_deserializer_->SerializeOutputParameters(*msg);
73 reply_deserializer_.reset(); 73 reply_deserializer_.reset();
74 } 74 }
(...skipping 21 matching lines...) Expand all
96 96
97 // Some messages we do special handling. 97 // Some messages we do special handling.
98 bool handled = true; 98 bool handled = true;
99 bool msg_is_ok = true; 99 bool msg_is_ok = true;
100 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) 100 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok)
101 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget) 101 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget)
102 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, 102 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension,
103 OnMsgOpenChannelToExtension) 103 OnMsgOpenChannelToExtension)
104 IPC_MESSAGE_HANDLER(PrintHostMsg_GetDefaultPrintSettings, 104 IPC_MESSAGE_HANDLER(PrintHostMsg_GetDefaultPrintSettings,
105 OnGetDefaultPrintSettings) 105 OnGetDefaultPrintSettings)
106 IPC_MESSAGE_HANDLER(PrintHostMsg_ScriptedPrint, 106 IPC_MESSAGE_HANDLER(PrintHostMsg_ScriptedPrint, OnScriptedPrint)
107 OnScriptedPrint) 107 IPC_MESSAGE_HANDLER(PrintHostMsg_UpdatePrintSettings, OnUpdatePrintSettings)
108 IPC_MESSAGE_HANDLER(PrintHostMsg_UpdatePrintSettings,
109 OnUpdatePrintSettings)
110 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, 108 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount,
111 OnDidGetPrintedPagesCount) 109 OnDidGetPrintedPagesCount)
112 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) 110 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage)
113 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, 111 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount,
114 OnDidPreviewPage) 112 OnDidGetPreviewPageCount)
113 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, OnDidPreviewPage)
115 #if defined(OS_WIN) 114 #if defined(OS_WIN)
116 IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) 115 IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection)
117 #endif 116 #endif
118 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, 117 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer,
119 OnAllocateSharedMemoryBuffer) 118 OnAllocateSharedMemoryBuffer)
120 #if defined(OS_CHROMEOS) 119 #if defined(OS_CHROMEOS)
121 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, 120 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting,
122 OnAllocateTempFileForPrinting) 121 OnAllocateTempFileForPrinting)
123 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, 122 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten,
124 OnTempFileForPrintingWritten) 123 OnTempFileForPrintingWritten)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (printer_.get()) 204 if (printer_.get())
206 printer_->SetPrintedPagesCount(cookie, number_pages); 205 printer_->SetPrintedPagesCount(cookie, number_pages);
207 } 206 }
208 207
209 void MockRenderThread::OnDidPrintPage( 208 void MockRenderThread::OnDidPrintPage(
210 const PrintHostMsg_DidPrintPage_Params& params) { 209 const PrintHostMsg_DidPrintPage_Params& params) {
211 if (printer_.get()) 210 if (printer_.get())
212 printer_->PrintPage(params); 211 printer_->PrintPage(params);
213 } 212 }
214 213
215 void MockRenderThread::OnDidPreviewPage(int page_number, bool* cancel) { 214 void MockRenderThread::OnDidGetPreviewPageCount(int document_cookie,
216 *cancel = cancel_print_preview_; 215 int number_pages) {
216 print_preview_pages_remaining_ = number_pages;
217 }
218
219 void MockRenderThread::OnDidPreviewPage(int page_number) {
220 if (page_number < 0)
221 return;
222 print_preview_pages_remaining_--;
217 } 223 }
218 224
219 void MockRenderThread::OnUpdatePrintSettings( 225 void MockRenderThread::OnUpdatePrintSettings(
220 int document_cookie, 226 int document_cookie,
221 const DictionaryValue& job_settings, 227 const DictionaryValue& job_settings,
222 PrintMsg_PrintPages_Params* params) { 228 PrintMsg_PrintPages_Params* params) {
223 // Check and make sure the required settings are all there. 229 // Check and make sure the required settings are all there.
224 // We don't actually care about the values. 230 // We don't actually care about the values.
225 std::string dummy_string; 231 std::string dummy_string;
226 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || 232 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) ||
227 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || 233 !job_settings.GetBoolean(printing::kSettingCollate, NULL) ||
228 !job_settings.GetBoolean(printing::kSettingColor, NULL) || 234 !job_settings.GetBoolean(printing::kSettingColor, NULL) ||
229 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || 235 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) ||
230 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || 236 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) ||
231 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || 237 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) ||
232 !job_settings.GetInteger(printing::kSettingCopies, NULL)) { 238 !job_settings.GetInteger(printing::kSettingCopies, NULL)) {
233 return; 239 return;
234 } 240 }
235 241
236 // Just return the default settings. 242 // Just return the default settings.
237 if (printer_.get()) 243 if (printer_.get())
238 printer_->UpdateSettings(document_cookie, params); 244 printer_->UpdateSettings(document_cookie, params);
239 } 245 }
240 246
241 void MockRenderThread::set_print_dialog_user_response(bool response) { 247 void MockRenderThread::set_print_dialog_user_response(bool response) {
242 print_dialog_user_response_ = response; 248 print_dialog_user_response_ = response;
243 } 249 }
244 250
245 void MockRenderThread::set_cancel_print_preview(bool cancel) { 251 int MockRenderThread::print_preview_pages_remaining() {
246 cancel_print_preview_ = cancel; 252 return print_preview_pages_remaining_;
247 } 253 }
OLDNEW
« no previous file with comments | « chrome/renderer/mock_render_thread.h ('k') | chrome/renderer/print_web_view_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698