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

Side by Side Diff: printing/printed_document.cc

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "printing/printed_document.h" 5 #include "printing/printed_document.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "app/text_elider.h" 12 #include "app/text_elider.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/i18n/file_util_icu.h" 15 #include "base/i18n/file_util_icu.h"
16 #include "base/lazy_instance.h"
16 #include "base/message_loop.h" 17 #include "base/message_loop.h"
17 #include "base/singleton.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "base/i18n/time_formatting.h" 20 #include "base/i18n/time_formatting.h"
21 #include "gfx/font.h" 21 #include "gfx/font.h"
22 #include "printing/page_number.h" 22 #include "printing/page_number.h"
23 #include "printing/page_overlays.h" 23 #include "printing/page_overlays.h"
24 #include "printing/printed_pages_source.h" 24 #include "printing/printed_pages_source.h"
25 #include "printing/printed_page.h" 25 #include "printing/printed_page.h"
26 #include "printing/units.h" 26 #include "printing/units.h"
27 #include "skia/ext/platform_device.h" 27 #include "skia/ext/platform_device.h"
28 28
29 namespace { 29 namespace {
30 30
31 struct PrintDebugDumpPath { 31 struct PrintDebugDumpPath {
32 PrintDebugDumpPath() 32 PrintDebugDumpPath()
33 : enabled(false) { 33 : enabled(false) {
34 } 34 }
35 35
36 bool enabled; 36 bool enabled;
37 FilePath debug_dump_path; 37 FilePath debug_dump_path;
38 }; 38 };
39 39
40 Singleton<PrintDebugDumpPath> g_debug_dump_info; 40 static base::LazyInstance<PrintDebugDumpPath> g_debug_dump_info(
41 base::LINKER_INITIALIZED);
41 42
42 } // namespace 43 } // namespace
43 44
44 namespace printing { 45 namespace printing {
45 46
46 PrintedDocument::PrintedDocument(const PrintSettings& settings, 47 PrintedDocument::PrintedDocument(const PrintSettings& settings,
47 PrintedPagesSource* source, 48 PrintedPagesSource* source,
48 int cookie) 49 int cookie)
49 : mutable_(source), 50 : mutable_(source),
50 immutable_(settings, source, cookie) { 51 immutable_(settings, source, cookie) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } else { 238 } else {
238 output = UTF16ToWideHack(gfx::ElideText(WideToUTF16Hack(output), 239 output = UTF16ToWideHack(gfx::ElideText(WideToUTF16Hack(output),
239 font, bounding.width(), false)); 240 font, bounding.width(), false));
240 } 241 }
241 } 242 }
242 243
243 DrawHeaderFooter(context, output, bounding); 244 DrawHeaderFooter(context, output, bounding);
244 } 245 }
245 246
246 void PrintedDocument::DebugDump(const PrintedPage& page) { 247 void PrintedDocument::DebugDump(const PrintedPage& page) {
247 if (!g_debug_dump_info->enabled) 248 if (!g_debug_dump_info.Get().enabled)
248 return; 249 return;
249 250
250 string16 filename; 251 string16 filename;
251 filename += date(); 252 filename += date();
252 filename += ASCIIToUTF16("_"); 253 filename += ASCIIToUTF16("_");
253 filename += time(); 254 filename += time();
254 filename += ASCIIToUTF16("_"); 255 filename += ASCIIToUTF16("_");
255 filename += name(); 256 filename += name();
256 filename += ASCIIToUTF16("_"); 257 filename += ASCIIToUTF16("_");
257 filename += ASCIIToUTF16(StringPrintf("%02d", page.page_number())); 258 filename += ASCIIToUTF16(StringPrintf("%02d", page.page_number()));
258 filename += ASCIIToUTF16("_.emf"); 259 filename += ASCIIToUTF16("_.emf");
259 #if defined(OS_WIN) 260 #if defined(OS_WIN)
260 page.native_metafile()->SaveTo( 261 page.native_metafile()->SaveTo(
261 g_debug_dump_info->debug_dump_path.Append(filename).ToWStringHack()); 262 g_debug_dump_info.Get().debug_dump_path.Append(filename).ToWStringHack());
262 #else // OS_WIN 263 #else // OS_WIN
263 NOTIMPLEMENTED(); 264 NOTIMPLEMENTED();
264 #endif // OS_WIN 265 #endif // OS_WIN
265 } 266 }
266 267
267 void PrintedDocument::set_debug_dump_path(const FilePath& debug_dump_path) { 268 void PrintedDocument::set_debug_dump_path(const FilePath& debug_dump_path) {
268 g_debug_dump_info->enabled = !debug_dump_path.empty(); 269 g_debug_dump_info.Get().enabled = !debug_dump_path.empty();
269 g_debug_dump_info->debug_dump_path = debug_dump_path; 270 g_debug_dump_info.Get().debug_dump_path = debug_dump_path;
270 } 271 }
271 272
272 const FilePath& PrintedDocument::debug_dump_path() { 273 const FilePath& PrintedDocument::debug_dump_path() {
273 return g_debug_dump_info->debug_dump_path; 274 return g_debug_dump_info.Get().debug_dump_path;
274 } 275 }
275 276
276 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) 277 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source)
277 : source_(source), 278 : source_(source),
278 expected_page_count_(0), 279 expected_page_count_(0),
279 page_count_(0), 280 page_count_(0),
280 shrink_factor(0) { 281 shrink_factor(0) {
281 } 282 }
282 283
283 PrintedDocument::Mutable::~Mutable() { 284 PrintedDocument::Mutable::~Mutable() {
284 } 285 }
285 286
286 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, 287 PrintedDocument::Immutable::Immutable(const PrintSettings& settings,
287 PrintedPagesSource* source, 288 PrintedPagesSource* source,
288 int cookie) 289 int cookie)
289 : settings_(settings), 290 : settings_(settings),
290 source_message_loop_(MessageLoop::current()), 291 source_message_loop_(MessageLoop::current()),
291 name_(source->RenderSourceName()), 292 name_(source->RenderSourceName()),
292 url_(source->RenderSourceUrl()), 293 url_(source->RenderSourceUrl()),
293 cookie_(cookie) { 294 cookie_(cookie) {
294 SetDocumentDate(); 295 SetDocumentDate();
295 } 296 }
296 297
297 PrintedDocument::Immutable::~Immutable() { 298 PrintedDocument::Immutable::~Immutable() {
298 } 299 }
299 300
300 } // namespace printing 301 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698