| Index: chrome/browser/android/vr_shell/vr_thread_envoy.h
|
| diff --git a/chrome/browser/android/vr_shell/vr_thread_envoy.h b/chrome/browser/android/vr_shell/vr_thread_envoy.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9430e6f8759f5a38bc2059be5f27b065c82a96cf
|
| --- /dev/null
|
| +++ b/chrome/browser/android/vr_shell/vr_thread_envoy.h
|
| @@ -0,0 +1,51 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_THREAD_ENVOY_H_
|
| +#define CHROME_BROWSER_ANDROID_VR_SHELL_VR_THREAD_ENVOY_H_
|
| +
|
| +#include <memory>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/time/time.h"
|
| +
|
| +namespace vr_shell {
|
| +
|
| +class VrShell;
|
| +
|
| +// Interface for communication between the main and gl threads.
|
| +class VrThreadEnvoy {
|
| + public:
|
| + virtual ~VrThreadEnvoy() {}
|
| +
|
| + // Posts a task to call the given function with the given args on the main
|
| + // thread.
|
| + template <typename Functor, typename... Args>
|
| + void PostTaskToMainThread(Functor&& functor, Args&&... args) {
|
| + // We use PostDelayedTask insted of PostTask to make testing easier.
|
| + // PostTask is not virtual so test subclasses can't override it.
|
| + GetMainThreadTaskRunner()->PostDelayedTask(
|
| + FROM_HERE,
|
| + base::Bind(std::forward<Functor>(functor), std::forward<Args>(args)...),
|
| + base::TimeDelta());
|
| + }
|
| +
|
| + // Same as PostTaskToMainThread but functor is expected to be a member
|
| + // function of VrShell.
|
| + template <typename Functor, typename... Args>
|
| + void PostTaskToMainThreadShell(Functor&& functor, Args&&... args) {
|
| + PostTaskToMainThread(std::forward<Functor>(functor), GetVrShell(),
|
| + std::forward<Args>(args)...);
|
| + }
|
| +
|
| + private:
|
| + virtual base::WeakPtr<VrShell> GetVrShell() = 0;
|
| + virtual scoped_refptr<base::SingleThreadTaskRunner>
|
| + GetMainThreadTaskRunner() = 0;
|
| +};
|
| +
|
| +} // namespace vr_shell
|
| +
|
| +#endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_THREAD_ENVOY_H_
|
|
|