Avoid double-InitCache() in SimpleDoomBetween test, leak
[chromium-blink-merge.git] / printing / backend / printing_info_win.cc
blob0e4509430d2397803efbb44ce77779a4235b1372
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
3 // found in the LICENSE file.
5 #include "printing/backend/printing_info_win.h"
7 #include "base/logging.h"
9 namespace printing {
11 namespace internal {
13 uint8* GetDriverInfo(HANDLE printer, int level) {
14 DWORD size = 0;
15 ::GetPrinterDriver(printer, NULL, level, NULL, 0, &size);
16 if (size == 0) {
17 return NULL;
19 scoped_ptr<uint8[]> buffer(new uint8[size]);
20 memset(buffer.get(), 0, size);
21 if (!::GetPrinterDriver(printer, NULL, level, buffer.get(), size, &size)) {
22 return NULL;
24 return buffer.release();
27 uint8* GetPrinterInfo(HANDLE printer, int level) {
28 DWORD size = 0;
29 ::GetPrinter(printer, level, NULL, 0, &size);
30 if (size == 0) {
31 LOG(WARNING) << "Failed to get size of PRINTER_INFO_" << level <<
32 ", error = " << GetLastError();
33 return NULL;
35 scoped_ptr<uint8[]> buffer(new uint8[size]);
36 memset(buffer.get(), 0, size);
37 if (!::GetPrinter(printer, level, buffer.get(), size, &size)) {
38 LOG(WARNING) << "Failed to get PRINTER_INFO_" << level <<
39 ", error = " << GetLastError();
40 return NULL;
42 return buffer.release();
45 } // namespace internal
47 UserDefaultDevMode::UserDefaultDevMode() : dev_mode_(NULL) {
50 bool UserDefaultDevMode::Init(HANDLE printer) {
51 if (info_9_.Init(printer))
52 dev_mode_ = info_9_.get()->pDevMode;
54 if (!dev_mode_ && info_8_.Init(printer))
55 dev_mode_ = info_8_.get()->pDevMode;
57 if (!dev_mode_ && info_2_.Init(printer))
58 dev_mode_ = info_2_.get()->pDevMode;
60 return dev_mode_ != NULL;
63 UserDefaultDevMode::~UserDefaultDevMode() {
66 } // namespace printing