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

Unified Diff: base/test/scoped_task_scheduler.cc

Issue 2768873007: Add Support to Get a COM STA Task Runner from the Task Scheduler API (Closed)
Patch Set: Simplify COM Init for ScopedTaskScheduler Created 3 years, 9 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
« no previous file with comments | « base/test/scoped_task_scheduler.h ('k') | base/test/scoped_task_scheduler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_task_scheduler.cc
diff --git a/base/test/scoped_task_scheduler.cc b/base/test/scoped_task_scheduler.cc
index 61ed2c7730ffd0f30c79ff744ceebe122290db5d..931dbb9136916f8c8fae5f9fa3dd7660ba3bfcd0 100644
--- a/base/test/scoped_task_scheduler.cc
+++ b/base/test/scoped_task_scheduler.cc
@@ -23,6 +23,12 @@
#include "base/task_scheduler/task_scheduler.h"
#include "base/task_scheduler/task_tracker.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/time.h"
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include "base/win/scoped_com_initializer.h"
+#endif // defined(OS_WIN)
namespace base {
namespace test {
@@ -50,6 +56,10 @@ class TestTaskScheduler : public TaskScheduler {
const TaskTraits& traits) override;
scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits(
const TaskTraits& traits) override;
+#if defined(OS_WIN)
+ scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits(
+ const TaskTraits& traits) override;
+#endif // defined(OS_WIN)
std::vector<const HistogramBase*> GetHistograms() const override;
int GetMaxConcurrentTasksWithTraitsDeprecated(
const TaskTraits& traits) const override;
@@ -80,6 +90,13 @@ class TestTaskScheduler : public TaskScheduler {
return message_loop_->task_runner();
}
+#if defined(OS_WIN)
+ void EnsureCOMSTA() {
+ if (!scoped_com_initializer_)
+ scoped_com_initializer_ = MakeUnique<win::ScopedCOMInitializer>();
+ }
+#endif // defined(OS_WIN)
+
// |message_loop_owned_| will be non-null if this TestTaskScheduler owns the
// MessageLoop (wasn't provided an external one at construction).
// |message_loop_| will always be set and is used by this TestTaskScheduler to
@@ -96,6 +113,12 @@ class TestTaskScheduler : public TaskScheduler {
// TaskRunner set by external code.
scoped_refptr<SingleThreadTaskRunner> saved_task_runner_;
+#if defined(OS_WIN)
+ // Maintains the lifetime of the COM Single-Threaded Apartment. Allocation and
+ // deallocation should be done in the |message_loop_| via PostTask.
+ std::unique_ptr<win::ScopedCOMInitializer> scoped_com_initializer_;
+#endif // defined(OS_WIN)
+
// Handles shutdown behaviors and sets up the environment to run a task.
internal::TaskTracker task_tracker_;
@@ -168,6 +191,15 @@ TestTaskScheduler::CreateSingleThreadTaskRunnerWithTraits(
this, ExecutionMode::SINGLE_THREADED, traits));
}
+#if defined(OS_WIN)
+scoped_refptr<SingleThreadTaskRunner>
+TestTaskScheduler::CreateCOMSTATaskRunnerWithTraits(const TaskTraits& traits) {
+ EnsureCOMSTA();
+ return make_scoped_refptr(new TestTaskSchedulerTaskRunner(
+ this, ExecutionMode::SINGLE_THREADED, traits));
+}
+#endif // defined(OS_WIN)
+
std::vector<const HistogramBase*> TestTaskScheduler::GetHistograms() const {
NOTREACHED();
return std::vector<const HistogramBase*>();
« no previous file with comments | « base/test/scoped_task_scheduler.h ('k') | base/test/scoped_task_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698