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

Side by Side Diff: chrome/browser/android/vr_shell/vr_thread_envoy.h

Issue 2833773005: Pause drawing webvr when the App button is pressed (Closed)
Patch Set: Add unittest + cleanup Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_THREAD_ENVOY_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_THREAD_ENVOY_H_
7
8 #include <memory>
9
10 #include "base/bind.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13
14 namespace vr_shell {
15
16 class VrShell;
17
18 // Interface for communication between the main and gl threads.
19 class VrThreadEnvoy {
20 public:
21 virtual ~VrThreadEnvoy() {}
22
23 // Posts a task to call the given function with the given args on the main
24 // thread.
25 template <typename Functor, typename... Args>
26 void PostTaskToMainThread(Functor&& functor, Args&&... args) {
27 // We use PostDelayedTask insted of PostTask to make testing easier.
28 // PostTask is not virtual so test subclasses can't override it.
29 GetMainThreadTaskRunner()->PostDelayedTask(
30 FROM_HERE,
31 base::Bind(std::forward<Functor>(functor), std::forward<Args>(args)...),
32 base::TimeDelta());
33 }
34
35 // Same as PostTaskToMainThread but functor is expected to be a member
36 // function of VrShell.
37 template <typename Functor, typename... Args>
38 void PostTaskToMainThreadShell(Functor&& functor, Args&&... args) {
39 PostTaskToMainThread(std::forward<Functor>(functor), GetVrShell(),
40 std::forward<Args>(args)...);
41 }
42
43 private:
44 virtual base::WeakPtr<VrShell> GetVrShell() = 0;
45 virtual scoped_refptr<base::SingleThreadTaskRunner>
46 GetMainThreadTaskRunner() = 0;
47 };
48
49 } // namespace vr_shell
50
51 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_THREAD_ENVOY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698