OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 // A collection of rendered pages. The settings are immutable. If the print | 26 // A collection of rendered pages. The settings are immutable. If the print |
27 // settings are changed, a new PrintedDocument must be created. | 27 // settings are changed, a new PrintedDocument must be created. |
28 // Warning: May be accessed from many threads at the same time. Only one thread | 28 // Warning: May be accessed from many threads at the same time. Only one thread |
29 // will have write access. Sensible functions are protected by a lock. | 29 // will have write access. Sensible functions are protected by a lock. |
30 // Warning: Once a page is loaded, it cannot be replaced. Pages may be discarded | 30 // Warning: Once a page is loaded, it cannot be replaced. Pages may be discarded |
31 // under low memory conditions. | 31 // under low memory conditions. |
32 class PRINTING_EXPORT PrintedDocument | 32 class PRINTING_EXPORT PrintedDocument |
33 : public base::RefCountedThreadSafe<PrintedDocument> { | 33 : public base::RefCountedThreadSafe<PrintedDocument> { |
34 public: | 34 public: |
35 // A delegate can be used to deviated the rendering of the pages to a | |
36 // specific destination. | |
37 class Delegate: public base::RefCountedThreadSafe<Delegate> { | |
Albert Bodenhamer
2012/06/15 18:41:24
Perhaps "PrintDestinationInterface" instead of "De
MAD
2012/06/19 14:24:10
Good idea... Will do...
MAD
2012/06/28 15:48:14
Done.
| |
38 public: | |
39 virtual void SetPageCount(int page_count) = 0; | |
40 virtual void SetPageContent(int page_number, | |
41 void* content, | |
42 size_t content_size) = 0; | |
43 }; | |
44 | |
35 // The cookie shall be unique and has a specific relationship with its | 45 // The cookie shall be unique and has a specific relationship with its |
36 // originating source and settings. | 46 // originating source and settings. |
37 PrintedDocument(const PrintSettings& settings, | 47 PrintedDocument(const PrintSettings& settings, |
38 PrintedPagesSource* source, | 48 PrintedPagesSource* source, |
49 Delegate* delegate, | |
39 int cookie); | 50 int cookie); |
40 | 51 |
41 // Sets a page's data. 0-based. Takes metafile ownership. | 52 // Sets a page's data. 0-based. Takes metafile ownership. |
42 // Note: locks for a short amount of time. | 53 // Note: locks for a short amount of time. |
43 void SetPage(int page_number, Metafile* metafile, double shrink, | 54 void SetPage(int page_number, Metafile* metafile, double shrink, |
44 const gfx::Size& paper_size, const gfx::Rect& page_rect); | 55 const gfx::Size& paper_size, const gfx::Rect& page_rect); |
45 | 56 |
46 // Retrieves a page. If the page is not available right now, it | 57 // Retrieves a page. If the page is not available right now, it |
47 // requests to have this page be rendered and returns false. | 58 // requests to have this page be rendered and returns false. |
48 // Note: locks for a short amount of time. | 59 // Note: locks for a short amount of time. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 140 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
130 // Page number of the first page. | 141 // Page number of the first page. |
131 int first_page; | 142 int first_page; |
132 #endif | 143 #endif |
133 }; | 144 }; |
134 | 145 |
135 // Contains all the immutable stuff. All this stuff can be accessed without | 146 // Contains all the immutable stuff. All this stuff can be accessed without |
136 // any lock held. This is because it can't be changed after the object's | 147 // any lock held. This is because it can't be changed after the object's |
137 // construction. | 148 // construction. |
138 struct Immutable { | 149 struct Immutable { |
139 Immutable(const PrintSettings& settings, PrintedPagesSource* source, | 150 Immutable(const PrintSettings& settings, |
151 PrintedPagesSource* source, | |
152 Delegate* delegate, | |
140 int cookie); | 153 int cookie); |
141 ~Immutable(); | 154 ~Immutable(); |
142 | 155 |
143 // Print settings used to generate this document. Immutable. | 156 // Print settings used to generate this document. Immutable. |
144 PrintSettings settings_; | 157 PrintSettings settings_; |
145 | 158 |
146 // Native thread for the render source. | 159 // Native thread for the render source. |
147 MessageLoop* source_message_loop_; | 160 MessageLoop* source_message_loop_; |
148 | 161 |
149 // Document name. Immutable. | 162 // Document name. Immutable. |
150 string16 name_; | 163 string16 name_; |
151 | 164 |
165 // A potential Delegate where to redirect page rendering if not NULL. | |
166 Delegate* delegate_; | |
167 | |
152 // Cookie to uniquely identify this document. It is used to make sure that a | 168 // Cookie to uniquely identify this document. It is used to make sure that a |
153 // PrintedPage is correctly belonging to the PrintedDocument. Since | 169 // PrintedPage is correctly belonging to the PrintedDocument. Since |
154 // PrintedPage generation is completely asynchronous, it could be easy to | 170 // PrintedPage generation is completely asynchronous, it could be easy to |
155 // mess up and send the page to the wrong document. It can be viewed as a | 171 // mess up and send the page to the wrong document. It can be viewed as a |
156 // simpler hash of PrintSettings since a new document is made each time the | 172 // simpler hash of PrintSettings since a new document is made each time the |
157 // print settings change. | 173 // print settings change. |
158 int cookie_; | 174 int cookie_; |
159 }; | 175 }; |
160 | 176 |
161 void DebugDump(const PrintedPage& page); | 177 void DebugDump(const PrintedPage& page); |
162 | 178 |
163 // All writable data member access must be guarded by this lock. Needs to be | 179 // All writable data member access must be guarded by this lock. Needs to be |
164 // mutable since it can be acquired from const member functions. | 180 // mutable since it can be acquired from const member functions. |
165 mutable base::Lock lock_; | 181 mutable base::Lock lock_; |
166 | 182 |
167 // All the mutable members. | 183 // All the mutable members. |
168 Mutable mutable_; | 184 Mutable mutable_; |
169 | 185 |
170 // All the immutable members. | 186 // All the immutable members. |
171 const Immutable immutable_; | 187 const Immutable immutable_; |
172 | 188 |
173 DISALLOW_COPY_AND_ASSIGN(PrintedDocument); | 189 DISALLOW_COPY_AND_ASSIGN(PrintedDocument); |
174 }; | 190 }; |
175 | 191 |
176 } // namespace printing | 192 } // namespace printing |
177 | 193 |
178 #endif // PRINTING_PRINTED_DOCUMENT_H_ | 194 #endif // PRINTING_PRINTED_DOCUMENT_H_ |
OLD | NEW |