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

Unified Diff: device/wake_lock/wake_lock_service_context.h

Issue 2734943003: Device Service: Decouple Wake Lock from //content (Closed)
Patch Set: Rebase 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 | « device/wake_lock/wake_lock_context_provider.cc ('k') | device/wake_lock/wake_lock_service_context.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/wake_lock/wake_lock_service_context.h
diff --git a/device/wake_lock/wake_lock_service_context.h b/device/wake_lock/wake_lock_service_context.h
index 01e7ebef29d1c6df794266af38e405b3ef41176d..0baa1a79c394dfe79c5f460ba35fdf2da2533dbf 100644
--- a/device/wake_lock/wake_lock_service_context.h
+++ b/device/wake_lock/wake_lock_service_context.h
@@ -12,25 +12,47 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
+#include "device/wake_lock/public/interfaces/wake_lock_context.mojom.h"
#include "device/wake_lock/wake_lock_service_impl.h"
+#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/public/cpp/bindings/strong_binding_set.h"
#include "ui/gfx/native_widget_types.h"
namespace device {
class PowerSaveBlocker;
-class WakeLockServiceContext {
+// Callback that maps a context ID to the NativeView associated with
+// that context. This callback is provided to the Device Service by its
+// embedder.
+using WakeLockContextCallback = base::Callback<gfx::NativeView(int)>;
+
+// Serves requests for WakeLockService connections within a given context.
+
+// Note that the lifetime model of WakeLockContext is somewhat complex: It must
+// stay alive as long as either
+// (1) Its Mojo connection is still valid (as the client might make future
+// GetWakeLock() calls) OR
+// (2) There are still live WakeLock instances that it has instantiated (since
+// they call into it when they receive Mojo requests from *their* clients).
+// Consequently, WakeLockContext monitors the state of the connections described
+// in (1) and (2), dying only when *all* of those connections go away.
+class WakeLockServiceContext : public mojom::WakeLockContext {
public:
WakeLockServiceContext(
+ mojom::WakeLockContextRequest request,
+ int context_id,
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
- base::Callback<gfx::NativeView()> native_view_getter);
- ~WakeLockServiceContext();
+ const WakeLockContextCallback& native_view_getter);
+ ~WakeLockServiceContext() override;
- // Creates a WakeLockServiceImpl that is strongly bound to |request|.
- void CreateService(mojo::InterfaceRequest<mojom::WakeLockService> request);
+ // mojom::WakeLockContext:
+ void GetWakeLock(
+ mojo::InterfaceRequest<mojom::WakeLockService> request) override;
+ void HasWakeLockForTests(
+ const HasWakeLockForTestsCallback& callback) override;
// Requests wake lock.
void RequestWakeLock();
@@ -38,13 +60,14 @@ class WakeLockServiceContext {
// Cancels pending wake lock request.
void CancelWakeLock();
- // Used by tests.
- bool HasWakeLockForTests() const;
-
private:
void CreateWakeLock();
void RemoveWakeLock();
void UpdateWakeLock();
+ void OnContextBindingError();
+
+ // Checks whether this instance is still needed, and if not, destroys it.
+ void DestroyIfNoLongerNeeded();
scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
@@ -53,9 +76,16 @@ class WakeLockServiceContext {
// The actual power save blocker for screen.
std::unique_ptr<PowerSaveBlocker> wake_lock_;
- base::Callback<gfx::NativeView()> native_view_getter_;
- base::WeakPtrFactory<WakeLockServiceContext> weak_factory_;
+#if defined(OS_ANDROID)
+ int context_id_;
+ WakeLockContextCallback native_view_getter_;
+#endif
+
+ mojo::Binding<mojom::WakeLockContext> context_binding_;
+ bool context_binding_encountered_error_;
+
+ mojo::StrongBindingSet<mojom::WakeLockService> wake_lock_bindings_;
DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext);
};
« no previous file with comments | « device/wake_lock/wake_lock_context_provider.cc ('k') | device/wake_lock/wake_lock_service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698