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

Side by Side Diff: chrome/browser/printing/print_dialog_cloud_win.cc

Issue 2965803002: Move more printing code off of the FILE thread. (Closed)
Patch Set: tweak Created 3 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
« no previous file with comments | « no previous file | chrome/browser/printing/printer_manager_dialog_linux.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/printing/print_dialog_cloud.h" 5 #include "chrome/browser/printing/print_dialog_cloud.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/task_scheduler/post_task.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "components/cloud_devices/common/cloud_devices_urls.h" 28 #include "components/cloud_devices/common/cloud_devices_urls.h"
28 #include "components/google/core/browser/google_util.h" 29 #include "components/google/core/browser/google_util.h"
29 #include "content/public/browser/browser_context.h" 30 #include "content/public/browser/browser_context.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 101 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
101 ui::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 102 ui::PAGE_TRANSITION_AUTO_BOOKMARK, false));
102 if (data && data->size()) { 103 if (data && data->size()) {
103 new PrintDataSetter(web_contents, data, print_job_title, print_ticket, 104 new PrintDataSetter(web_contents, data, print_job_title, print_ticket,
104 file_type); 105 file_type);
105 } 106 }
106 } 107 }
107 108
108 scoped_refptr<base::RefCountedMemory> ReadFile( 109 scoped_refptr<base::RefCountedMemory> ReadFile(
109 const base::FilePath& path_to_file) { 110 const base::FilePath& path_to_file) {
110 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
111 scoped_refptr<base::RefCountedMemory> data; 111 scoped_refptr<base::RefCountedMemory> data;
112 int64_t file_size = 0; 112 int64_t file_size = 0;
113 if (base::GetFileSize(path_to_file, &file_size) && file_size != 0) { 113 if (base::GetFileSize(path_to_file, &file_size) && file_size != 0) {
114 if (file_size > kMaxFileSize) { 114 if (file_size > kMaxFileSize) {
115 DLOG(WARNING) << " print data file too large to reserve space"; 115 DLOG(WARNING) << " print data file too large to reserve space";
116 return data; 116 return data;
117 } 117 }
118 std::string file_data; 118 std::string file_data;
119 file_data.reserve(static_cast<size_t>(file_size)); 119 file_data.reserve(static_cast<size_t>(file_size));
120 if (base::ReadFileToString(path_to_file, &file_data)) 120 if (base::ReadFileToString(path_to_file, &file_data))
121 data = base::RefCountedString::TakeString(&file_data); 121 data = base::RefCountedString::TakeString(&file_data);
122 } 122 }
123 base::DeleteFile(path_to_file, false); 123 base::DeleteFile(path_to_file, false);
124 return data; 124 return data;
125 } 125 }
126 126
127 void CreatePrintDialogForFile(content::BrowserContext* browser_context, 127 void CreatePrintDialogForFile(content::BrowserContext* browser_context,
128 const base::FilePath& path_to_file, 128 const base::FilePath& path_to_file,
129 const base::string16& print_job_title, 129 const base::string16& print_job_title,
130 const base::string16& print_ticket, 130 const base::string16& print_ticket,
131 const std::string& file_type) { 131 const std::string& file_type) {
132 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 132 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
133 content::BrowserThread::PostTaskAndReplyWithResult( 133 base::PostTaskWithTraitsAndReplyWithResult(
134 content::BrowserThread::FILE, FROM_HERE, 134 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
135 base::Bind(&ReadFile, path_to_file), 135 base::Bind(&ReadFile, path_to_file),
136 base::Bind(&CreatePrintDialog, browser_context, 136 base::Bind(&CreatePrintDialog, browser_context, print_job_title,
137 print_job_title, print_ticket, file_type)); 137 print_ticket, file_type));
138 } 138 }
139 139
140 } // namespace 140 } // namespace
141 141
142 bool CreatePrintDialogFromCommandLine(Profile* profile, 142 bool CreatePrintDialogFromCommandLine(Profile* profile,
143 const base::CommandLine& command_line) { 143 const base::CommandLine& command_line) {
144 base::FilePath cloud_print_file = 144 base::FilePath cloud_print_file =
145 command_line.GetSwitchValuePath(switches::kCloudPrintFile); 145 command_line.GetSwitchValuePath(switches::kCloudPrintFile);
146 DCHECK(!cloud_print_file.empty()); 146 DCHECK(!cloud_print_file.empty());
147 if (cloud_print_file.empty()) 147 if (cloud_print_file.empty())
148 return false; 148 return false;
149 base::string16 print_job_title = 149 base::string16 print_job_title =
150 command_line.GetSwitchValueNative(switches::kCloudPrintJobTitle); 150 command_line.GetSwitchValueNative(switches::kCloudPrintJobTitle);
151 base::string16 print_job_print_ticket = 151 base::string16 print_job_print_ticket =
152 command_line.GetSwitchValueNative(switches::kCloudPrintPrintTicket); 152 command_line.GetSwitchValueNative(switches::kCloudPrintPrintTicket);
153 std::string file_type = 153 std::string file_type =
154 command_line.GetSwitchValueASCII(switches::kCloudPrintFileType); 154 command_line.GetSwitchValueASCII(switches::kCloudPrintFileType);
155 if (file_type.empty()) 155 if (file_type.empty())
156 file_type = "application/pdf"; 156 file_type = "application/pdf";
157 CreatePrintDialogForFile(profile, cloud_print_file, print_job_title, 157 CreatePrintDialogForFile(profile, cloud_print_file, print_job_title,
158 print_job_print_ticket, file_type); 158 print_job_print_ticket, file_type);
159 return true; 159 return true;
160 } 160 }
161 161
162 } // namespace print_dialog_cloud 162 } // namespace print_dialog_cloud
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/printing/printer_manager_dialog_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698