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

Unified Diff: device/wake_lock/wake_lock_service_context.h

Issue 2734943003: Device Service: Decouple Wake Lock from //content (Closed)
Patch Set: Response to review + 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
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..a8c4e4b138df49ebc8938f213b312e8734907d6b 100644
--- a/device/wake_lock/wake_lock_service_context.h
+++ b/device/wake_lock/wake_lock_service_context.h
@@ -12,9 +12,10 @@
#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 "ui/gfx/native_widget_types.h"
@@ -22,15 +23,26 @@ 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.
+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();
+ 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 +50,11 @@ class WakeLockServiceContext {
// Cancels pending wake lock request.
void CancelWakeLock();
- // Used by tests.
- bool HasWakeLockForTests() const;
-
private:
void CreateWakeLock();
void RemoveWakeLock();
void UpdateWakeLock();
+ void OnConnectionError();
scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
@@ -53,9 +63,19 @@ 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_;
+ mojo::Binding<mojom::WakeLockContext> binding_;
+
+#if defined(OS_ANDROID)
+ int context_id_;
+ WakeLockContextCallback native_view_getter_;
+#endif
+
+ // The number of connections that the client has in this context,
+ // including both the connection to this implementation and all
+ // connections made via |GetWakeLock()|. When this number reaches
+ // 0 this instance isn't needed anymore and kills itself.
+ int num_connections_;
DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext);
};

Powered by Google App Engine
This is Rietveld 408576698