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

Unified Diff: device/wake_lock/wake_lock_service_context.h

Issue 2734943003: Device Service: Decouple Wake Lock from //content (Closed)
Patch Set: Bugfix 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..28f14d761611d1b7875751909c4a9ab9918ad322 100644
--- a/device/wake_lock/wake_lock_service_context.h
+++ b/device/wake_lock/wake_lock_service_context.h
@@ -14,7 +14,9 @@
#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_service_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 +24,24 @@ namespace device {
class PowerSaveBlocker;
-class WakeLockServiceContext {
+// Callback that maps a context ID to the NativeView associated with
+// that context.
+using WakeLockContextCallback = base::Callback<gfx::NativeView(int)>;
+
+class WakeLockServiceContext : public mojom::WakeLockServiceContext {
public:
WakeLockServiceContext(
+ mojom::WakeLockServiceContextRequest request,
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::WakeLockServiceContext:
+ void SetContextID(int context_id) override;
+ void BindWakeLock(
+ mojo::InterfaceRequest<mojom::WakeLockService> request) override;
+ void HasWakeLockForTests(
+ const HasWakeLockForTestsCallback& callback) override;
// Requests wake lock.
void RequestWakeLock();
@@ -38,22 +49,29 @@ 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_;
+ int context_id_;
int num_lock_requests_;
// The actual power save blocker for screen.
std::unique_ptr<PowerSaveBlocker> wake_lock_;
- base::Callback<gfx::NativeView()> native_view_getter_;
+ WakeLockContextCallback native_view_getter_;
+
+ mojo::Binding<mojom::WakeLockServiceContext> binding_;
+
+ // The number of connections that the client has in this context,
+ // including both the connection to this implementation and all
+ // connections made via |BindWakeLock()|. When this number reaches
+ // 0 this instance isn't needed anymore and kills itself.
+ int num_connections_;
base::WeakPtrFactory<WakeLockServiceContext> weak_factory_;

Powered by Google App Engine
This is Rietveld 408576698