| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/browser/wake_lock/wake_lock_context_host.h" | 5 #include "content/browser/wake_lock/wake_lock_context_host.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "content/public/common/service_manager_connection.h" | 9 #include "content/public/common/service_manager_connection.h" |
| 10 #include "device/wake_lock/public/interfaces/wake_lock_context_provider.mojom.h" | 10 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 12 #include "services/device/public/interfaces/constants.mojom.h" | 12 #include "services/device/public/interfaces/constants.mojom.h" |
| 13 #include "services/service_manager/public/cpp/connector.h" | 13 #include "services/service_manager/public/cpp/connector.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 base::StaticAtomicSequenceNumber g_unique_id; | 19 base::StaticAtomicSequenceNumber g_unique_id; |
| 20 | 20 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 31 WakeLockContextHost::WakeLockContextHost(WebContents* web_contents) | 31 WakeLockContextHost::WakeLockContextHost(WebContents* web_contents) |
| 32 : id_(g_unique_id.GetNext()), web_contents_(web_contents) { | 32 : id_(g_unique_id.GetNext()), web_contents_(web_contents) { |
| 33 g_id_to_context_host.Get()[id_] = this; | 33 g_id_to_context_host.Get()[id_] = this; |
| 34 | 34 |
| 35 // Connect to a WakeLockContext, associating it with |id_| (note that in some | 35 // Connect to a WakeLockContext, associating it with |id_| (note that in some |
| 36 // testing contexts, the service manager connection isn't initialized). | 36 // testing contexts, the service manager connection isn't initialized). |
| 37 if (ServiceManagerConnection::GetForProcess()) { | 37 if (ServiceManagerConnection::GetForProcess()) { |
| 38 service_manager::Connector* connector = | 38 service_manager::Connector* connector = |
| 39 ServiceManagerConnection::GetForProcess()->GetConnector(); | 39 ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 40 DCHECK(connector); | 40 DCHECK(connector); |
| 41 device::mojom::WakeLockContextProviderPtr context_provider; | 41 device::mojom::WakeLockProviderPtr wake_lock_provider; |
| 42 connector->BindInterface(device::mojom::kServiceName, | 42 connector->BindInterface(device::mojom::kServiceName, |
| 43 mojo::MakeRequest(&context_provider)); | 43 mojo::MakeRequest(&wake_lock_provider)); |
| 44 context_provider->GetWakeLockContextForID( | 44 wake_lock_provider->GetWakeLockContextForID( |
| 45 id_, mojo::MakeRequest(&wake_lock_context_)); | 45 id_, mojo::MakeRequest(&wake_lock_context_)); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 WakeLockContextHost::~WakeLockContextHost() { | 49 WakeLockContextHost::~WakeLockContextHost() { |
| 50 g_id_to_context_host.Get().erase(id_); | 50 g_id_to_context_host.Get().erase(id_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // static | 53 // static |
| 54 gfx::NativeView WakeLockContextHost::GetNativeViewForContext(int context_id) { | 54 gfx::NativeView WakeLockContextHost::GetNativeViewForContext(int context_id) { |
| 55 WakeLockContextHost* context_host = ContextHostFromId(context_id); | 55 WakeLockContextHost* context_host = ContextHostFromId(context_id); |
| 56 if (context_host) | 56 if (context_host) |
| 57 return context_host->web_contents_->GetNativeView(); | 57 return context_host->web_contents_->GetNativeView(); |
| 58 return nullptr; | 58 return nullptr; |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace content | 61 } // namespace content |
| OLD | NEW |