Skip to content

Commit

Permalink
capture_mode: Skeleton
Browse files Browse the repository at this point in the history
This CL adds the initial skeleton for the Capture Mode feature.
Future CLs will implement the actual functionality.

BUG=1105227

Change-Id: I2d8d61aa431b6bd9599e8cec65d4836a42eee695
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2327855
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793367}
  • Loading branch information
Ahmed Fakhry authored and Commit Bot committed Jul 30, 2020
1 parent a2ceefb commit 0c6efef
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ component("ash") {
"public/cpp/autotest_ambient_api.h",
"public/cpp/autotest_desks_api.h",
"public/cpp/autotest_private_api_utils.h",
"public/cpp/capture_mode_delegate.h",
"public/cpp/debug_utils.h",
"public/cpp/docked_magnifier_controller.h",
"public/cpp/event_rewriter_controller.h",
Expand Down Expand Up @@ -250,6 +251,8 @@ component("ash") {
"bluetooth_devices_observer.h",
"cancel_mode.cc",
"cancel_mode.h",
"capture_mode/capture_mode_controller.cc",
"capture_mode/capture_mode_controller.h",
"clipboard/clipboard_history.cc",
"clipboard/clipboard_history.h",
"clipboard/clipboard_history_controller.cc",
Expand Down Expand Up @@ -2291,6 +2294,8 @@ static_library("test_support") {
"assistant/test/test_assistant_web_view.h",
"assistant/test/test_assistant_web_view_factory.cc",
"assistant/test/test_assistant_web_view_factory.h",
"capture_mode/test_capture_mode_delegate.cc",
"capture_mode/test_capture_mode_delegate.h",
"display/display_configuration_controller_test_api.cc",
"display/display_configuration_controller_test_api.h",
"display/mirror_window_test_api.cc",
Expand Down
3 changes: 3 additions & 0 deletions ash/capture_mode/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
afakhry@chromium.org

# COMPONENT: UI>Shell>ScreenCapture
53 changes: 53 additions & 0 deletions ash/capture_mode/capture_mode_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2020 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 "ash/capture_mode/capture_mode_controller.h"

#include <utility>

#include "base/check.h"
#include "base/check_op.h"

namespace ash {

namespace {

CaptureModeController* g_instance = nullptr;

} // namespace

CaptureModeController::CaptureModeController(
std::unique_ptr<CaptureModeDelegate> delegate)
: delegate_(std::move(delegate)) {
DCHECK_EQ(g_instance, nullptr);
g_instance = this;
}

CaptureModeController::~CaptureModeController() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}

// static
CaptureModeController* CaptureModeController::Get() {
DCHECK(g_instance);
return g_instance;
}

void CaptureModeController::Start() {
StartWith(type_, source_);
}

void CaptureModeController::StartWith(CaptureModeType type,
CaptureModeSource source) {
type_ = type;
source_ = source;
// TODO(afakhry): Fill in here.
}

void CaptureModeController::Stop() {
// TODO(afakhry): Fill in here.
}

} // namespace ash
58 changes: 58 additions & 0 deletions ash/capture_mode/capture_mode_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2020 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 ASH_CAPTURE_MODE_CAPTURE_MODE_CONTROLLER_H_
#define ASH_CAPTURE_MODE_CAPTURE_MODE_CONTROLLER_H_

#include <memory>

#include "ash/public/cpp/capture_mode_delegate.h"

namespace ash {

// Defines the capture type Capture Mode is currently using.
enum class CaptureModeType {
kImage,
kVideo,
};

// Defines the source of the capture used by Capture Mode.
enum class CaptureModeSource {
kFullscreen,
kRegion,
kWindow,
};

// Controls starting and ending a Capture Mode session and its behavior.
class CaptureModeController {
public:
explicit CaptureModeController(std::unique_ptr<CaptureModeDelegate> delegate);
CaptureModeController(const CaptureModeController&) = delete;
CaptureModeController& operator=(const CaptureModeController&) = delete;
~CaptureModeController();

// Convenience function to get the controller instance, which is created and
// owned by Shell.
static CaptureModeController* Get();

// Starts a new capture session with the most-recently used |type_| and
// |source_|.
void Start();

// Starts a new capture session with the specific given |type| and |source|.
void StartWith(CaptureModeType type, CaptureModeSource source);

// Stops an existing capture session.
void Stop();

private:
std::unique_ptr<CaptureModeDelegate> delegate_;

CaptureModeType type_ = CaptureModeType::kImage;
CaptureModeSource source_ = CaptureModeSource::kRegion;
};

} // namespace ash

#endif // ASH_CAPTURE_MODE_CAPTURE_MODE_CONTROLLER_H_
16 changes: 16 additions & 0 deletions ash/capture_mode/test_capture_mode_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020 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 "ash/capture_mode/test_capture_mode_delegate.h"

#include "base/files/file_path.h"

namespace ash {

base::FilePath TestCaptureModeDelegate::GetActiveUserDownloadsDir() const {
// TODO(afakhry): Add proper code to enable testing.
return base::FilePath();
}

} // namespace ash
25 changes: 25 additions & 0 deletions ash/capture_mode/test_capture_mode_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020 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 ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_
#define ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_

#include "ash/public/cpp/capture_mode_delegate.h"

namespace ash {

class TestCaptureModeDelegate : public CaptureModeDelegate {
public:
TestCaptureModeDelegate() = default;
TestCaptureModeDelegate(const TestCaptureModeDelegate&) = delete;
TestCaptureModeDelegate& operator=(const TestCaptureModeDelegate&) = delete;
~TestCaptureModeDelegate() override = default;

// CaptureModeDelegate:
base::FilePath GetActiveUserDownloadsDir() const override;
};

} // namespace ash

#endif // ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_
7 changes: 7 additions & 0 deletions ash/public/cpp/ash_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const base::Feature kAllowAmbientEQ{"AllowAmbientEQ",
const base::Feature kAutoNightLight{"AutoNightLight",
base::FEATURE_DISABLED_BY_DEFAULT};

const base::Feature kCaptureMode{"CaptureMode",
base::FEATURE_DISABLED_BY_DEFAULT};

const base::Feature kContextualNudges{"ContextualNudges",
base::FEATURE_ENABLED_BY_DEFAULT};

Expand Down Expand Up @@ -147,6 +150,10 @@ bool IsAutoNightLightEnabled() {
return base::FeatureList::IsEnabled(kAutoNightLight);
}

bool IsCaptureModeEnabled() {
return base::FeatureList::IsEnabled(kCaptureMode);
}

bool IsHideArcMediaNotificationsEnabled() {
return base::FeatureList::IsEnabled(kMediaSessionNotification) &&
base::FeatureList::IsEnabled(kHideArcMediaNotifications);
Expand Down
6 changes: 6 additions & 0 deletions ash/public/cpp/ash_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ ASH_PUBLIC_EXPORT extern const base::Feature kAllowAmbientEQ;
// certain devices.
ASH_PUBLIC_EXPORT extern const base::Feature kAutoNightLight;

// Enables the Capture Mode feature which is an enhanced screenshot and screen
// capture user experience.
ASH_PUBLIC_EXPORT extern const base::Feature kCaptureMode;

// Enables contextual nudges for gesture education.
ASH_PUBLIC_EXPORT extern const base::Feature kContextualNudges;

Expand Down Expand Up @@ -176,6 +180,8 @@ ASH_PUBLIC_EXPORT bool IsPerDeskShelfEnabled();

ASH_PUBLIC_EXPORT bool IsAutoNightLightEnabled();

ASH_PUBLIC_EXPORT bool IsCaptureModeEnabled();

ASH_PUBLIC_EXPORT bool IsHideArcMediaNotificationsEnabled();

ASH_PUBLIC_EXPORT bool IsKeyboardShortcutViewerAppEnabled();
Expand Down
30 changes: 30 additions & 0 deletions ash/public/cpp/capture_mode_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020 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 ASH_PUBLIC_CPP_CAPTURE_MODE_DELEGATE_H_
#define ASH_PUBLIC_CPP_CAPTURE_MODE_DELEGATE_H_

#include "ash/public/cpp/ash_public_export.h"

namespace base {
class FilePath;
} // namespace base

namespace ash {

// Defines the interface for the delegate of CaptureModeController, that can be
// implemented by an ash client (e.g. Chrome). The CaptureModeController owns
// the instance of this delegate.
class ASH_PUBLIC_EXPORT CaptureModeDelegate {
public:
virtual ~CaptureModeDelegate() = default;

// Returns the path to the active user's downloads directory. This will never
// be called if the user is not logged in.
virtual base::FilePath GetActiveUserDownloadsDir() const = 0;
};

} // namespace ash

#endif // ASH_PUBLIC_CPP_CAPTURE_MODE_DELEGATE_H_
6 changes: 6 additions & 0 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/assistant/assistant_controller_impl.h"
#include "ash/autoclick/autoclick_controller.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/clipboard/clipboard_history_controller.h"
#include "ash/dbus/ash_dbus_services.h"
#include "ash/detachable_base/detachable_base_handler.h"
Expand Down Expand Up @@ -917,6 +918,11 @@ void Shell::Init(
accessibility_controller_ = std::make_unique<AccessibilityControllerImpl>();
toast_manager_ = std::make_unique<ToastManagerImpl>();

if (features::IsCaptureModeEnabled()) {
capture_mode_controller_ = std::make_unique<CaptureModeController>(
shell_delegate_->CreateCaptureModeDelegate());
}

// Accelerometer file reader starts listening to tablet mode controller.
AccelerometerReader::GetInstance()->StartListenToTabletModeController();

Expand Down
2 changes: 2 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class BluetoothNotificationController;
class BluetoothPowerController;
class BrightnessControlDelegate;
class AshColorProvider;
class CaptureModeController;
class CrosDisplayConfig;
class DesksController;
class DetachableBaseHandler;
Expand Down Expand Up @@ -706,6 +707,7 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<ShelfController> shelf_controller_;
std::unique_ptr<ShelfWindowWatcher> shelf_window_watcher_;
std::unique_ptr<ShellDelegate> shell_delegate_;
std::unique_ptr<CaptureModeController> capture_mode_controller_;
std::unique_ptr<ShutdownControllerImpl> shutdown_controller_;
std::unique_ptr<SystemNotificationController> system_notification_controller_;
std::unique_ptr<SystemTrayModel> system_tray_model_;
Expand Down
7 changes: 6 additions & 1 deletion ash/shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class OSExchangeData;
namespace ash {

class AccessibilityDelegate;
class CaptureModeDelegate;
class ScreenshotDelegate;
class BackGestureContextualNudgeDelegate;
class BackGestureContextualNudgeController;
Expand All @@ -38,12 +39,16 @@ class BackGestureContextualNudgeController;
class ASH_EXPORT ShellDelegate {
public:
// The Shell owns the delegate.
virtual ~ShellDelegate() {}
virtual ~ShellDelegate() = default;

// Returns true if |window| can be shown for the delegate's concept of current
// user.
virtual bool CanShowWindowForUser(const aura::Window* window) const = 0;

// Creates and returns the delegate of the Capture Mode feature.
virtual std::unique_ptr<CaptureModeDelegate> CreateCaptureModeDelegate()
const = 0;

// TODO(jamescook): Replace with a mojo-compatible interface.
virtual std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() = 0;

Expand Down
8 changes: 8 additions & 0 deletions ash/test_shell_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "ash/test_shell_delegate.h"

#include <memory>

#include "ash/accessibility/default_accessibility_delegate.h"
#include "ash/capture_mode/test_capture_mode_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/test_screenshot_delegate.h"
#include "ash/wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h"
Expand All @@ -20,6 +23,11 @@ bool TestShellDelegate::CanShowWindowForUser(const aura::Window* window) const {
return true;
}

std::unique_ptr<CaptureModeDelegate>
TestShellDelegate::CreateCaptureModeDelegate() const {
return std::make_unique<TestCaptureModeDelegate>();
}

std::unique_ptr<ScreenshotDelegate>
TestShellDelegate::CreateScreenshotDelegate() {
return std::make_unique<TestScreenshotDelegate>();
Expand Down
2 changes: 2 additions & 0 deletions ash/test_shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class TestShellDelegate : public ShellDelegate {

// Overridden from ShellDelegate:
bool CanShowWindowForUser(const aura::Window* window) const override;
std::unique_ptr<CaptureModeDelegate> CreateCaptureModeDelegate()
const override;
std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
std::unique_ptr<BackGestureContextualNudgeDelegate>
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,8 @@ static_library("ui") {
"ash/chrome_accessibility_delegate.h",
"ash/chrome_browser_main_extra_parts_ash.cc",
"ash/chrome_browser_main_extra_parts_ash.h",
"ash/chrome_capture_mode_delegate.cc",
"ash/chrome_capture_mode_delegate.h",
"ash/chrome_launcher_prefs.cc",
"ash/chrome_launcher_prefs.h",
"ash/chrome_new_window_client.cc",
Expand Down
21 changes: 21 additions & 0 deletions chrome/browser/ui/ash/chrome_capture_mode_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2020 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 "chrome/browser/ui/ash/chrome_capture_mode_delegate.h"

#include "base/files/file_path.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/login/login_state/login_state.h"

ChromeCaptureModeDelegate::ChromeCaptureModeDelegate() = default;

ChromeCaptureModeDelegate::~ChromeCaptureModeDelegate() = default;

base::FilePath ChromeCaptureModeDelegate::GetActiveUserDownloadsDir() const {
DCHECK(chromeos::LoginState::Get()->IsUserLoggedIn());
DownloadPrefs* download_prefs =
DownloadPrefs::FromBrowserContext(ProfileManager::GetActiveUserProfile());
return download_prefs->DownloadPath();
}
Loading

0 comments on commit 0c6efef

Please sign in to comment.