Skip to content

Commit

Permalink
VCD: Move Ash-Chrome only codes under ash/ folder
Browse files Browse the repository at this point in the history
This CL does:

1. Move CameraHalDispatcherImpl under ash/.
2. Move PowerManagerClientProxy into a standalone class under ash/.

Bug: b/175168296
Test: Build successfully
Change-Id: I60455aa8e593a5654c69af06957c509a26ac8964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589414
Reviewed-by: Shik Chen <shik@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Wei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#851072}
  • Loading branch information
Wei Lee authored and Chromium LUCI CQ committed Feb 5, 2021
1 parent d8ec970 commit 3e19bbb
Show file tree
Hide file tree
Showing 20 changed files with 247 additions and 128 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/camera_mic/vm_camera_mic_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "base/scoped_observation.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "components/keyed_service/core/keyed_service.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "chromeos/dbus/vm_permission_service/vm_permission_service.pb.h"
#include "components/prefs/pref_service.h"
#include "dbus/message.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include "third_party/cros_system_api/dbus/service_constants.h"

namespace {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/ash/media_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "chrome/browser/chromeos/camera_mic/vm_camera_mic_manager.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/mojom/cros_camera_service.mojom.h"
#include "ui/base/accelerators/media_keys_listener.h"

Expand Down
2 changes: 1 addition & 1 deletion components/arc/camera/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_rules = [
"+crypto/random.h",
"+media/capture/video/chromeos/camera_hal_dispatcher_impl.h",
"+media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h",
]
2 changes: 1 addition & 1 deletion components/arc/camera/arc_camera_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/session/arc_bridge_service.h"
#include "crypto/random.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#include "chromeos/audio/cras_audio_handler.h"
#include "content/browser/gpu/chromeos/video_capture_dependencies.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/public/cros_features.h"
#include "media/capture/video/chromeos/video_capture_device_factory_chromeos.h"
#endif
Expand Down
16 changes: 12 additions & 4 deletions media/capture/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ component("capture_lib") {
"video/chromeos/camera_device_delegate.h",
"video/chromeos/camera_hal_delegate.cc",
"video/chromeos/camera_hal_delegate.h",
"video/chromeos/camera_hal_dispatcher_impl.cc",
"video/chromeos/camera_hal_dispatcher_impl.h",
"video/chromeos/camera_metadata_utils.cc",
"video/chromeos/camera_metadata_utils.h",
"video/chromeos/capture_metadata_dispatcher.h",
Expand Down Expand Up @@ -340,7 +338,6 @@ component("capture_lib") {
deps += [
"//build/config/linux/libdrm",
"//chromeos/constants",
"//chromeos/dbus/power",
"//components/chromeos_camera:mojo_mjpeg_decode_accelerator",
"//components/chromeos_camera/common",
"//components/device_event_log",
Expand All @@ -350,6 +347,17 @@ component("capture_lib") {
]
}

if (is_chromeos_ash) {
sources += [
"video/chromeos/ash/camera_hal_dispatcher_impl.cc",
"video/chromeos/ash/camera_hal_dispatcher_impl.h",
"video/chromeos/ash/power_manager_client_proxy.cc",
"video/chromeos/ash/power_manager_client_proxy.h",
]

deps += [ "//chromeos/dbus/power" ]
}

if (is_fuchsia) {
sources += [
"video/fuchsia/video_capture_device_factory_fuchsia.cc",
Expand Down Expand Up @@ -544,10 +552,10 @@ test("capture_unittests") {

if (is_chromeos_ash) {
sources += [
"video/chromeos/ash/camera_hal_dispatcher_impl_unittest.cc",
"video/chromeos/camera_3a_controller_unittest.cc",
"video/chromeos/camera_device_delegate_unittest.cc",
"video/chromeos/camera_hal_delegate_unittest.cc",
"video/chromeos/camera_hal_dispatcher_impl_unittest.cc",
"video/chromeos/request_manager_unittest.cc",
"video/chromeos/token_manager_unittest.cc",
]
Expand Down
1 change: 0 additions & 1 deletion media/capture/video/chromeos/DEPS
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include_rules = [
"+ash/constants/ash_features.h",
"+chromeos/dbus",
"+components/chromeos_camera",
"+third_party/libsync",
]
3 changes: 3 additions & 0 deletions media/capture/video/chromeos/ash/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+chromeos/dbus",
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include <fcntl.h>
#include <grp.h>
#include <poll.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DISPATCHER_IMPL_H_
#define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DISPATCHER_IMPL_H_
#ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_ASH_CAMERA_HAL_DISPATCHER_IMPL_H_
#define MEDIA_CAPTURE_VIDEO_CHROMEOS_ASH_CAMERA_HAL_DISPATCHER_IMPL_H_

#include <memory>
#include <set>
Expand Down Expand Up @@ -280,4 +280,4 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final

} // namespace media

#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DISPATCHER_IMPL_H_
#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_ASH_CAMERA_HAL_DISPATCHER_IMPL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"

#include <memory>
#include <utility>
Expand Down
84 changes: 84 additions & 0 deletions media/capture/video/chromeos/ash/power_manager_client_proxy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/capture/video/chromeos/ash/power_manager_client_proxy.h"

namespace media {

PowerManagerClientProxy::PowerManagerClientProxy() = default;

void PowerManagerClientProxy::Init(
base::WeakPtr<Observer> observer,
const std::string& debug_info,
scoped_refptr<base::SingleThreadTaskRunner> observer_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> dbus_task_runner) {
observer_ = std::move(observer);
debug_info_ = debug_info;
observer_task_runner_ = std::move(observer_task_runner);
dbus_task_runner_ = std::move(dbus_task_runner);

dbus_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&PowerManagerClientProxy::InitOnDBusThread, this));
}

void PowerManagerClientProxy::Shutdown() {
dbus_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&PowerManagerClientProxy::ShutdownOnDBusThread, this));
}

void PowerManagerClientProxy::UnblockSuspend(
const base::UnguessableToken& unblock_suspend_token) {
dbus_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&PowerManagerClientProxy::UnblockSuspendOnDBusThread, this,
unblock_suspend_token));
}

PowerManagerClientProxy::~PowerManagerClientProxy() = default;

void PowerManagerClientProxy::InitOnDBusThread() {
DCHECK(dbus_task_runner_->RunsTasksInCurrentSequence());
chromeos::PowerManagerClient::Get()->AddObserver(this);
}

void PowerManagerClientProxy::ShutdownOnDBusThread() {
DCHECK(dbus_task_runner_->RunsTasksInCurrentSequence());
chromeos::PowerManagerClient::Get()->RemoveObserver(this);
}

void PowerManagerClientProxy::UnblockSuspendOnDBusThread(
const base::UnguessableToken& unblock_suspend_token) {
DCHECK(dbus_task_runner_->RunsTasksInCurrentSequence());
chromeos::PowerManagerClient::Get()->UnblockSuspend(unblock_suspend_token);
}

void PowerManagerClientProxy::SuspendImminentOnObserverThread(
base::UnguessableToken unblock_suspend_token) {
DCHECK(observer_task_runner_->RunsTasksInCurrentSequence());
// TODO(b/175168296): Ensure that the weak pointer |observer| is dereferenced
// and invalidated on the same thread.
if (observer_) {
observer_->SuspendImminent();
}
UnblockSuspend(std::move(unblock_suspend_token));
}

void PowerManagerClientProxy::SuspendImminent(
power_manager::SuspendImminent::Reason reason) {
auto token = base::UnguessableToken::Create();
chromeos::PowerManagerClient::Get()->BlockSuspend(token, debug_info_);
observer_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&PowerManagerClientProxy::SuspendImminentOnObserverThread,
this, std::move(token)));
}

void PowerManagerClientProxy::SuspendDone(base::TimeDelta sleep_duration) {
observer_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&Observer::SuspendDone, observer_));
}

} // namespace media
66 changes: 66 additions & 0 deletions media/capture/video/chromeos/ash/power_manager_client_proxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_ASH_POWER_MANAGER_CLIENT_PROXY_H_
#define MEDIA_CAPTURE_VIDEO_CHROMEOS_ASH_POWER_MANAGER_CLIENT_PROXY_H_

#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "chromeos/dbus/power/power_manager_client.h"

namespace media {

class PowerManagerClientProxy
: public base::RefCountedThreadSafe<PowerManagerClientProxy>,
public chromeos::PowerManagerClient::Observer {
public:
class Observer {
public:
virtual void SuspendDone() = 0;
virtual void SuspendImminent() = 0;
};

PowerManagerClientProxy();
PowerManagerClientProxy(const PowerManagerClientProxy&) = delete;
PowerManagerClientProxy& operator=(const PowerManagerClientProxy&) = delete;

void Init(base::WeakPtr<Observer> observer,
const std::string& debug_info,
scoped_refptr<base::SingleThreadTaskRunner> observer_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> dbus_task_runner);

void Shutdown();

void UnblockSuspend(const base::UnguessableToken& unblock_suspend_token);

private:
friend class base::RefCountedThreadSafe<PowerManagerClientProxy>;

~PowerManagerClientProxy() override;

void InitOnDBusThread();

void ShutdownOnDBusThread();

void UnblockSuspendOnDBusThread(
const base::UnguessableToken& unblock_suspend_token);

void SuspendImminentOnObserverThread(
base::UnguessableToken unblock_suspend_token);

// chromeos::PowerManagerClient::Observer:
void SuspendImminent(power_manager::SuspendImminent::Reason reason) final;

void SuspendDone(base::TimeDelta sleep_duration) final;

base::WeakPtr<Observer> observer_;
std::string debug_info_;
scoped_refptr<base::SingleThreadTaskRunner> observer_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> dbus_task_runner_;
};

} // namespace media

#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_ASH_POWER_MANAGER_CLIENT_PROXY_H_
2 changes: 1 addition & 1 deletion media/capture/video/chromeos/camera_hal_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include "base/system/system_monitor.h"
#include "base/unguessable_token.h"
#include "components/device_event_log/device_event_log.h"
#include "media/capture/video/chromeos/ash/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/camera_app_device_bridge_impl.h"
#include "media/capture/video/chromeos/camera_buffer_factory.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/camera_metadata_utils.h"
#include "media/capture/video/chromeos/video_capture_device_chromeos_delegate.h"
#include "media/capture/video/chromeos/video_capture_device_chromeos_halv3.h"
Expand Down

0 comments on commit 3e19bbb

Please sign in to comment.