OLD | NEW |
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 #ifndef PRINTING_PRINTED_DOCUMENT_H_ | 5 #ifndef PRINTING_PRINTED_DOCUMENT_H_ |
6 #define PRINTING_PRINTED_DOCUMENT_H_ | 6 #define PRINTING_PRINTED_DOCUMENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // document_page_count() otherwise. | 91 // document_page_count() otherwise. |
92 // Note: locks for a short amount of time. | 92 // Note: locks for a short amount of time. |
93 int expected_page_count() const; | 93 int expected_page_count() const; |
94 | 94 |
95 // Getters. All these items are immutable hence thread-safe. | 95 // Getters. All these items are immutable hence thread-safe. |
96 const PrintSettings& settings() const { return immutable_.settings_; } | 96 const PrintSettings& settings() const { return immutable_.settings_; } |
97 const string16& name() const { | 97 const string16& name() const { |
98 return immutable_.name_; | 98 return immutable_.name_; |
99 } | 99 } |
100 const GURL& url() const { return immutable_.url_; } | 100 const GURL& url() const { return immutable_.url_; } |
101 const string16& date() const { return immutable_.date_; } | |
102 const string16& time() const { return immutable_.time_; } | |
103 int cookie() const { return immutable_.cookie_; } | 101 int cookie() const { return immutable_.cookie_; } |
104 | 102 |
105 // Sets a path where to dump printing output files for debugging. If never set | 103 // Sets a path where to dump printing output files for debugging. If never set |
106 // no files are generated. | 104 // no files are generated. |
107 static void set_debug_dump_path(const FilePath& debug_dump_path); | 105 static void set_debug_dump_path(const FilePath& debug_dump_path); |
108 | 106 |
109 static const FilePath& debug_dump_path(); | 107 static const FilePath& debug_dump_path(); |
110 | 108 |
111 private: | 109 private: |
112 friend class base::RefCountedThreadSafe<PrintedDocument>; | 110 friend class base::RefCountedThreadSafe<PrintedDocument>; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 }; | 145 }; |
148 | 146 |
149 // Contains all the immutable stuff. All this stuff can be accessed without | 147 // Contains all the immutable stuff. All this stuff can be accessed without |
150 // any lock held. This is because it can't be changed after the object's | 148 // any lock held. This is because it can't be changed after the object's |
151 // construction. | 149 // construction. |
152 struct Immutable { | 150 struct Immutable { |
153 Immutable(const PrintSettings& settings, PrintedPagesSource* source, | 151 Immutable(const PrintSettings& settings, PrintedPagesSource* source, |
154 int cookie); | 152 int cookie); |
155 ~Immutable(); | 153 ~Immutable(); |
156 | 154 |
157 // Sets the document's |date_| and |time_|. | |
158 void SetDocumentDate(); | |
159 | |
160 // Print settings used to generate this document. Immutable. | 155 // Print settings used to generate this document. Immutable. |
161 PrintSettings settings_; | 156 PrintSettings settings_; |
162 | 157 |
163 // Native thread for the render source. | 158 // Native thread for the render source. |
164 MessageLoop* source_message_loop_; | 159 MessageLoop* source_message_loop_; |
165 | 160 |
166 // Document name. Immutable. | 161 // Document name. Immutable. |
167 string16 name_; | 162 string16 name_; |
168 | 163 |
169 // URL that generated this document. Immutable. | 164 // URL that generated this document. Immutable. |
170 GURL url_; | 165 GURL url_; |
171 | 166 |
172 // The date on which this job started. Immutable. | |
173 string16 date_; | |
174 | |
175 // The time at which this job started. Immutable. | |
176 string16 time_; | |
177 | |
178 // Cookie to uniquely identify this document. It is used to make sure that a | 167 // Cookie to uniquely identify this document. It is used to make sure that a |
179 // PrintedPage is correctly belonging to the PrintedDocument. Since | 168 // PrintedPage is correctly belonging to the PrintedDocument. Since |
180 // PrintedPage generation is completely asynchronous, it could be easy to | 169 // PrintedPage generation is completely asynchronous, it could be easy to |
181 // mess up and send the page to the wrong document. It can be viewed as a | 170 // mess up and send the page to the wrong document. It can be viewed as a |
182 // simpler hash of PrintSettings since a new document is made each time the | 171 // simpler hash of PrintSettings since a new document is made each time the |
183 // print settings change. | 172 // print settings change. |
184 int cookie_; | 173 int cookie_; |
185 }; | 174 }; |
186 | 175 |
187 // Prints the headers and footers for one page in the specified context | |
188 // according to the current settings. | |
189 void PrintHeaderFooter(gfx::NativeDrawingContext context, | |
190 const PrintedPage& page, | |
191 PageOverlays::HorizontalPosition x, | |
192 PageOverlays::VerticalPosition y, | |
193 const gfx::Font& font) const; | |
194 | |
195 // Draws the computed |text| into |context| taking into account the bounding | |
196 // region |bounds|. |bounds| is the position in which to draw |text| and | |
197 // the minimum area needed to contain |text| which may not be larger than the | |
198 // header or footer itself. | |
199 // TODO(jhawkins): string16. | |
200 void DrawHeaderFooter(gfx::NativeDrawingContext context, | |
201 std::wstring text, | |
202 gfx::Rect bounds) const; | |
203 | |
204 void DebugDump(const PrintedPage& page); | 176 void DebugDump(const PrintedPage& page); |
205 | 177 |
206 // All writable data member access must be guarded by this lock. Needs to be | 178 // All writable data member access must be guarded by this lock. Needs to be |
207 // mutable since it can be acquired from const member functions. | 179 // mutable since it can be acquired from const member functions. |
208 mutable base::Lock lock_; | 180 mutable base::Lock lock_; |
209 | 181 |
210 // All the mutable members. | 182 // All the mutable members. |
211 Mutable mutable_; | 183 Mutable mutable_; |
212 | 184 |
213 // All the immutable members. | 185 // All the immutable members. |
214 const Immutable immutable_; | 186 const Immutable immutable_; |
215 | 187 |
216 DISALLOW_COPY_AND_ASSIGN(PrintedDocument); | 188 DISALLOW_COPY_AND_ASSIGN(PrintedDocument); |
217 }; | 189 }; |
218 | 190 |
219 } // namespace printing | 191 } // namespace printing |
220 | 192 |
221 #endif // PRINTING_PRINTED_DOCUMENT_H_ | 193 #endif // PRINTING_PRINTED_DOCUMENT_H_ |
OLD | NEW |