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

Side by Side Diff: chrome/browser/printing/printer_query.h

Issue 63137: Make the PrintDlgEx() call in the UI thread. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 | « chrome/browser/printing/print_job_worker.cc ('k') | chrome/browser/printing/printer_query.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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_ 5 #ifndef CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
6 #define CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_ 6 #define CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
7 7
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/ref_counted.h" 9 #include "base/task.h"
10 #include "chrome/browser/printing/print_job_worker_owner.h" 10 #include "chrome/browser/printing/print_job_worker_owner.h"
11 11
12 class CancelableTask; 12 class CancelableTask;
13 class MessageLoop; 13 class MessageLoop;
14 14
15 namespace base { 15 namespace base {
16 class Thread; 16 class Thread;
17 } 17 }
18 18
19 namespace printing { 19 namespace printing {
20 20
21 class PrintJobWorker; 21 class PrintJobWorker;
22 22
23 // Query the printer for settings. 23 // Query the printer for settings in a worker thread for default settings and
24 // in |ui_message_loop| for ASK_USER request.
24 class PrinterQuery : public base::RefCountedThreadSafe<PrinterQuery>, 25 class PrinterQuery : public base::RefCountedThreadSafe<PrinterQuery>,
25 public PrintJobWorkerOwner { 26 public PrintJobWorkerOwner {
26 public: 27 public:
27 // GetSettings() UI parameter. 28 // GetSettings() UI parameter.
28 enum GetSettingsAskParam { 29 enum GetSettingsAskParam {
29 DEFAULTS, 30 DEFAULTS,
30 ASK_USER, 31 ASK_USER,
31 }; 32 };
32 33
33 PrinterQuery(); 34 PrinterQuery(MessageLoop* ui_message_loop);
34 virtual ~PrinterQuery(); 35 virtual ~PrinterQuery();
35 36
36 // PrintJobWorkerOwner 37 // PrintJobWorkerOwner
37 virtual void AddRef() { 38 virtual void AddRef() {
38 return base::RefCountedThreadSafe<PrinterQuery>::AddRef(); 39 return base::RefCountedThreadSafe<PrinterQuery>::AddRef();
39 } 40 }
40 virtual void Release() { 41 virtual void Release() {
41 return base::RefCountedThreadSafe<PrinterQuery>::Release(); 42 return base::RefCountedThreadSafe<PrinterQuery>::Release();
42 } 43 }
43 virtual void GetSettingsDone(const PrintSettings& new_settings, 44 virtual void GetSettingsDone(const PrintSettings& new_settings,
44 PrintingContext::Result result); 45 PrintingContext::Result result);
45 virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner); 46 virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner);
46 virtual MessageLoop* message_loop() { 47 virtual MessageLoop* message_loop() {
47 return ui_message_loop_; 48 return message_loop_;
48 } 49 }
49 virtual const PrintSettings& settings() const { return settings_; } 50 virtual const PrintSettings& settings() const { return settings_; }
50 51
51 virtual int cookie() const { return cookie_; } 52 virtual int cookie() const { return cookie_; }
52 53
53 // Initializes the printing context. It is fine to call this function multiple 54 // Initializes the printing context. It is fine to call this function multiple
54 // times to reinitialize the settings. |parent_window| parameter will be the 55 // times to reinitialize the settings. |parent_window| parameter will be the
55 // owner of the print setting dialog box. It is unused when 56 // owner of the print setting dialog box. It is unused when
56 // |ask_for_user_settings| is DEFAULTS. 57 // |ask_for_user_settings| is DEFAULTS.
57 void GetSettings(GetSettingsAskParam ask_user_for_settings, 58 void GetSettings(GetSettingsAskParam ask_user_for_settings,
58 HWND parent_window, 59 HWND parent_window,
59 int expected_page_count, 60 int expected_page_count,
60 CancelableTask* callback); 61 CancelableTask* callback);
61 62
62 // Stops the worker thread since the client is done with this object. 63 // Stops the worker thread since the client is done with this object.
63 void StopWorker(); 64 void StopWorker();
64 65
65 // Returns true if the Print... dialog box is currently displayed. 66 // Returns true if the Print... dialog box is currently displayed.
66 bool is_print_dialog_box_shown() const; 67 bool is_print_dialog_box_shown() const;
67 68
68 // Returns true if a GetSettings() call is pending completion. 69 // Returns true if a GetSettings() call is pending completion.
69 bool is_callback_pending() const; 70 bool is_callback_pending() const;
70 71
71 PrintingContext::Result last_status() const { return last_status_; } 72 PrintingContext::Result last_status() const { return last_status_; }
72 73
73 // Returns if a worker thread is still associated to this instance. 74 // Returns if a worker thread is still associated to this instance.
74 bool is_valid() const; 75 bool is_valid() const;
75 76
76 private: 77 private:
78 // Main UI thread for displaying the Print... Dialog.
79 MessageLoop* ui_message_loop_;
80
77 // Main message loop reference. Used to send notifications in the right 81 // Main message loop reference. Used to send notifications in the right
78 // thread. 82 // thread.
79 MessageLoop* const ui_message_loop_; 83 MessageLoop* const message_loop_;
80 84
81 // All the UI is done in a worker thread because many Win32 print functions 85 // All the UI is done in a worker thread because many Win32 print functions
82 // are blocking and enters a message loop without your consent. There is one 86 // are blocking and enters a message loop without your consent. There is one
83 // worker thread per print job. 87 // worker thread per print job.
84 scoped_ptr<PrintJobWorker> worker_; 88 scoped_ptr<PrintJobWorker> worker_;
85 89
86 // Cache of the print context settings for access in the UI thread. 90 // Cache of the print context settings for access in the UI thread.
87 PrintSettings settings_; 91 PrintSettings settings_;
88 92
89 // Is the Print... dialog box currently shown. 93 // Is the Print... dialog box currently shown.
90 bool is_print_dialog_box_shown_; 94 bool is_print_dialog_box_shown_;
91 95
92 // Cookie that make this instance unique. 96 // Cookie that make this instance unique.
93 int cookie_; 97 int cookie_;
94 98
95 // Results from the last GetSettingsDone() callback. 99 // Results from the last GetSettingsDone() callback.
96 PrintingContext::Result last_status_; 100 PrintingContext::Result last_status_;
97 101
98 // Task waiting to be executed. 102 // Task waiting to be executed.
99 scoped_ptr<CancelableTask> callback_; 103 scoped_ptr<CancelableTask> callback_;
100 104
101 DISALLOW_COPY_AND_ASSIGN(PrinterQuery); 105 DISALLOW_COPY_AND_ASSIGN(PrinterQuery);
102 }; 106 };
103 107
108 // A single-use printer query task for default settings. Makes it easy to defer
109 // the task to a worker thread (like WorkerPool) and executes the callbacks in
110 // the caller's thread..
111 // TODO(maruel): Extract common functionality in a template?
112 class DefaultSettingsPrinterQueryTask : public Task {
113 public:
114 // Information about the printer setting.
115 struct Result {
116 Result();
117
118 void Run();
119
120 PrintingContext printing_context;
121 PrintingContext::Result result;
122 private:
123 DISALLOW_COPY_AND_ASSIGN(Result);
124 };
125
126 // |reply_message_loop| is optional and is equivalent to
127 // MessageLoop::current() if NULL.
128 DefaultSettingsPrinterQueryTask(MessageLoop* reply_message_loop);
129 virtual ~DefaultSettingsPrinterQueryTask() { }
130
131 virtual void Run();
132 virtual void Cancel();
133
134 // The reply task will be posted to reply_message_loop specified in the
135 // constructor. Takes ownership.
136 // TODO(maruel): We could get away by using UnboundMethod<> instead.
137 void set_reply_task(CancelableTask* reply_task) {
138 reply_task_->reply_task_.reset(reply_task);
139 }
140 // Retrieves the results. Mainly useful while creating the NewRunnableMethod()
141 // to specify to set_reply_task().
142 Result* result() { return &reply_task_->result_; }
143
144 private:
145 class ReplyTask : public CancelableTask {
146 public:
147 ReplyTask();
148 virtual ~ReplyTask() { }
149
150 virtual void Run();
151 virtual void Cancel();
152
153 scoped_ptr<CancelableTask> reply_task_;
154 Result result_;
155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(ReplyTask);
158 };
159
160 ReplyTask* reply_task_;
161 MessageLoop* reply_message_loop_;
162
163 DISALLOW_COPY_AND_ASSIGN(DefaultSettingsPrinterQueryTask);
164 };
165
104 } // namespace printing 166 } // namespace printing
105 167
106 #endif // CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_ 168 #endif // CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job_worker.cc ('k') | chrome/browser/printing/printer_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698