Commit 9ea5dcb4 authored by thestig's avatar thestig Committed by Commit bot

Cleanup nits in PrintViewManager.

- Remove unused includes.
- Use auto and nullptr.
- Simplify code.

Review-Url: https://codereview.chromium.org/2272933002
Cr-Commit-Position: refs/heads/master@{#414802}
parent a4feb354
...@@ -8,10 +8,7 @@ ...@@ -8,10 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/print_preview_dialog_controller.h" #include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
...@@ -31,9 +28,7 @@ namespace { ...@@ -31,9 +28,7 @@ namespace {
// Keeps track of pending scripted print preview closures. // Keeps track of pending scripted print preview closures.
// No locking, only access on the UI thread. // No locking, only access on the UI thread.
typedef std::map<content::RenderProcessHost*, base::Closure> base::LazyInstance<std::map<content::RenderProcessHost*, base::Closure>>
ScriptedPrintPreviewClosureMap;
static base::LazyInstance<ScriptedPrintPreviewClosureMap>
g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER; g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER;
void EnableInternalPDFPluginForContents(int render_process_id, void EnableInternalPDFPluginForContents(int render_process_id,
...@@ -59,7 +54,7 @@ namespace printing { ...@@ -59,7 +54,7 @@ namespace printing {
PrintViewManager::PrintViewManager(content::WebContents* web_contents) PrintViewManager::PrintViewManager(content::WebContents* web_contents)
: PrintViewManagerBase(web_contents), : PrintViewManagerBase(web_contents),
print_preview_state_(NOT_PREVIEWING), print_preview_state_(NOT_PREVIEWING),
scripted_print_preview_rph_(NULL) { scripted_print_preview_rph_(nullptr) {
if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) { if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) {
EnableInternalPDFPluginForContents( EnableInternalPDFPluginForContents(
web_contents->GetRenderProcessHost()->GetID(), web_contents->GetRenderProcessHost()->GetID(),
...@@ -85,20 +80,21 @@ bool PrintViewManager::BasicPrint() { ...@@ -85,20 +80,21 @@ bool PrintViewManager::BasicPrint() {
PrintPreviewDialogController::GetInstance(); PrintPreviewDialogController::GetInstance();
if (!dialog_controller) if (!dialog_controller)
return false; return false;
content::WebContents* print_preview_dialog = content::WebContents* print_preview_dialog =
dialog_controller->GetPrintPreviewForContents(web_contents()); dialog_controller->GetPrintPreviewForContents(web_contents());
if (print_preview_dialog) { if (!print_preview_dialog)
return PrintNow();
if (!print_preview_dialog->GetWebUI()) if (!print_preview_dialog->GetWebUI())
return false; return false;
PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
print_preview_dialog->GetWebUI()->GetController()); print_preview_dialog->GetWebUI()->GetController());
print_preview_ui->OnShowSystemDialog(); print_preview_ui->OnShowSystemDialog();
return true; return true;
} else {
return PrintNow();
}
} }
#endif // ENABLE_BASIC_PRINTING #endif // defined(ENABLE_BASIC_PRINTING)
bool PrintViewManager::PrintPreviewNow(bool selection_only) { bool PrintViewManager::PrintPreviewNow(bool selection_only) {
// Users can send print commands all they want and it is beyond // Users can send print commands all they want and it is beyond
...@@ -127,14 +123,12 @@ void PrintViewManager::PrintPreviewDone() { ...@@ -127,14 +123,12 @@ void PrintViewManager::PrintPreviewDone() {
DCHECK_NE(NOT_PREVIEWING, print_preview_state_); DCHECK_NE(NOT_PREVIEWING, print_preview_state_);
if (print_preview_state_ == SCRIPTED_PREVIEW) { if (print_preview_state_ == SCRIPTED_PREVIEW) {
ScriptedPrintPreviewClosureMap& map = auto& map = g_scripted_print_preview_closure_map.Get();
g_scripted_print_preview_closure_map.Get(); auto it = map.find(scripted_print_preview_rph_);
ScriptedPrintPreviewClosureMap::iterator it =
map.find(scripted_print_preview_rph_);
CHECK(it != map.end()); CHECK(it != map.end());
it->second.Run(); it->second.Run();
map.erase(scripted_print_preview_rph_); map.erase(it);
scripted_print_preview_rph_ = NULL; scripted_print_preview_rph_ = nullptr;
} }
print_preview_state_ = NOT_PREVIEWING; print_preview_state_ = NOT_PREVIEWING;
} }
...@@ -160,16 +154,15 @@ void PrintViewManager::OnDidShowPrintDialog() { ...@@ -160,16 +154,15 @@ void PrintViewManager::OnDidShowPrintDialog() {
void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) { void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ScriptedPrintPreviewClosureMap& map = auto& map = g_scripted_print_preview_closure_map.Get();
g_scripted_print_preview_closure_map.Get();
content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost(); content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost();
// This should always be 0 once we get modal window.print(). if (base::ContainsKey(map, rph)) {
if (map.count(rph) != 0) {
// Renderer already handling window.print() in another View. // Renderer already handling window.print() in another View.
Send(reply_msg); Send(reply_msg);
return; return;
} }
if (print_preview_state_ != NOT_PREVIEWING) { if (print_preview_state_ != NOT_PREVIEWING) {
// If a user initiated print dialog is already open, ignore the scripted // If a user initiated print dialog is already open, ignore the scripted
// print message. // print message.
...@@ -186,11 +179,8 @@ void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) { ...@@ -186,11 +179,8 @@ void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) {
} }
print_preview_state_ = SCRIPTED_PREVIEW; print_preview_state_ = SCRIPTED_PREVIEW;
base::Closure callback = map[rph] = base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply,
base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply, base::Unretained(this), reply_msg);
base::Unretained(this),
reply_msg);
map[rph] = callback;
scripted_print_preview_rph_ = rph; scripted_print_preview_rph_ = rph;
} }
...@@ -201,6 +191,7 @@ void PrintViewManager::OnShowScriptedPrintPreview(bool source_is_modifiable) { ...@@ -201,6 +191,7 @@ void PrintViewManager::OnShowScriptedPrintPreview(bool source_is_modifiable) {
PrintPreviewDone(); PrintPreviewDone();
return; return;
} }
dialog_controller->PrintPreview(web_contents()); dialog_controller->PrintPreview(web_contents());
PrintHostMsg_RequestPrintPreview_Params params; PrintHostMsg_RequestPrintPreview_Params params;
params.is_modifiable = source_is_modifiable; params.is_modifiable = source_is_modifiable;
...@@ -224,7 +215,7 @@ bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { ...@@ -224,7 +215,7 @@ bool PrintViewManager::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
return handled ? true : PrintViewManagerBase::OnMessageReceived(message); return handled || PrintViewManagerBase::OnMessageReceived(message);
} }
} // namespace printing } // namespace printing
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment