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

Unified Diff: chrome/service/cloud_print/print_system_win.cc

Issue 11050009: Use ScopedCOMInitializer in more places. While this doesn't always simplify code, it does mean we … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/service/cloud_print/print_system_win.cc
===================================================================
--- chrome/service/cloud_print/print_system_win.cc (revision 159813)
+++ chrome/service/cloud_print/print_system_win.cc (working copy)
@@ -15,6 +15,7 @@
#include "base/utf_string_conversions.h"
#include "base/win/object_watcher.h"
#include "base/win/scoped_bstr.h"
+#include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h"
#include "base/win/scoped_hdc.h"
#include "chrome/common/child_process_logging.h"
@@ -389,8 +390,7 @@
: last_page_printed_(-1),
job_id_(-1),
delegate_(NULL),
- saved_dc_(0),
- should_couninit_(false) {
+ saved_dc_(0) {
}
~Core() {}
@@ -514,10 +514,8 @@
job_progress_watcher_.StopWatching();
job_progress_watcher_.StartWatching(job_progress_event_.Get(), this);
}
- if (done && should_couninit_) {
- CoUninitialize();
- should_couninit_ = false;
- }
+ if (done)
+ com_initializer_.reset();
}
virtual void OnRenderPDFPagesToMetafileFailed() OVERRIDE {
@@ -595,8 +593,9 @@
job_progress_event_.Set(CreateEvent(NULL, TRUE, FALSE, NULL));
if (!job_progress_event_.Get())
return false;
- should_couninit_ = SUCCEEDED(CoInitializeEx(NULL,
- COINIT_MULTITHREADED));
+ scoped_ptr<base::win::ScopedCOMInitializer> com_initializer(
+ new base::win::ScopedCOMInitializer(
+ base::win::ScopedCOMInitializer::kMTA));
base::win::ScopedComPtr<IXpsPrintJobStream> doc_stream;
base::win::ScopedComPtr<IXpsPrintJobStream> print_ticket_stream;
bool ret = false;
@@ -628,6 +627,7 @@
if (SUCCEEDED(doc_stream->Close())) {
job_progress_watcher_.StartWatching(job_progress_event_.Get(),
this);
+ com_initializer_.swap(com_initializer);
ret = true;
}
}
@@ -639,10 +639,6 @@
xps_print_job_->Cancel();
xps_print_job_.Release();
}
- if (should_couninit_) {
- CoUninitialize();
- should_couninit_ = false;
- }
}
return ret;
}
@@ -662,7 +658,7 @@
base::win::ScopedHandle job_progress_event_;
base::win::ObjectWatcher job_progress_watcher_;
base::win::ScopedComPtr<IXpsPrintJob> xps_print_job_;
- bool should_couninit_;
+ scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_;
DISALLOW_COPY_AND_ASSIGN(Core);
};

Powered by Google App Engine
This is Rietveld 408576698