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

Side by Side Diff: content/browser/wake_lock/wake_lock_service_context.h

Issue 2378033002: Decouple WakeLock from direct //content dependencies (Closed)
Patch Set: Created 4 years, 2 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ 5 #ifndef CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_
6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ 6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/sequenced_task_runner.h"
14 #include "content/browser/wake_lock/wake_lock_service_impl.h" 17 #include "content/browser/wake_lock/wake_lock_service_impl.h"
15 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
16 #include "content/public/browser/web_contents_observer.h"
17 #include "mojo/public/cpp/bindings/interface_request.h" 19 #include "mojo/public/cpp/bindings/interface_request.h"
18 20 #include "ui/gfx/native_widget_types.h"
19 #if defined(OS_ANDROID)
20 #include "ui/android/view_android.h"
21 #endif // OS_ANDROID
22 21
23 namespace device { 22 namespace device {
24 class PowerSaveBlocker; 23 class PowerSaveBlocker;
25 } // namespace device 24 } // namespace device
26 25
27 namespace content { 26 namespace content {
28 27
29 class RenderFrameHost; 28 class CONTENT_EXPORT WakeLockServiceContext {
30 class WebContents;
31
32 class CONTENT_EXPORT WakeLockServiceContext : public WebContentsObserver {
33 public: 29 public:
34 explicit WakeLockServiceContext(WebContents* web_contents); 30 WakeLockServiceContext(
35 ~WakeLockServiceContext() override; 31 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
32 base::Callback<gfx::NativeView()> native_view_getter);
33 ~WakeLockServiceContext();
36 34
37 // Creates a WakeLockServiceImpl that is strongly bound to |request|. 35 // Creates a WakeLockServiceImpl that is strongly bound to |request|.
38 void CreateService( 36 void CreateService(
39 int render_process_id,
40 int render_frame_id,
41 mojo::InterfaceRequest<blink::mojom::WakeLockService> request); 37 mojo::InterfaceRequest<blink::mojom::WakeLockService> request);
42 38
43 // WebContentsObserver implementation. 39 // Requests wake lock.
44 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; 40 void RequestWakeLock();
45 41
46 // Requests wake lock for RenderFrame identified by |render_process_id| and 42 // Cancels pending wake lock request.
47 // |render_frame_id|. 43 void CancelWakeLock();
48 void RequestWakeLock(int render_process_id, int render_frame_id);
49
50 // Cancels wake lock request for RenderFrame identified by
51 // |render_process_id| and |render_frame_id|.
52 void CancelWakeLock(int render_process_id, int render_frame_id);
53 44
54 // Used by tests. 45 // Used by tests.
55 bool HasWakeLockForTests() const; 46 bool HasWakeLockForTests() const;
56 47
57 private: 48 private:
58 void CreateWakeLock(); 49 void CreateWakeLock();
59 void RemoveWakeLock(); 50 void RemoveWakeLock();
60 void UpdateWakeLock(); 51 void UpdateWakeLock();
61 52
62 // Set of (render_process_id, render_frame_id) pairs identifying all 53 scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
63 // RenderFrames requesting wake lock. 54 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
64 std::set<std::pair<int, int>> frames_requesting_lock_; 55
56 int num_lock_requests_;
65 57
66 // The actual power save blocker for screen. 58 // The actual power save blocker for screen.
67 std::unique_ptr<device::PowerSaveBlocker> wake_lock_; 59 std::unique_ptr<device::PowerSaveBlocker> wake_lock_;
60 base::Callback<gfx::NativeView()> native_view_getter_;
68 61
69 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; 62 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_;
70 63
71 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); 64 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext);
72 }; 65 };
73 66
74 } // namespace content 67 } // namespace content
75 68
76 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ 69 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/browser/wake_lock/wake_lock_service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698