Commit bac30e6f authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Migrate ArcService to BrowserContextKeyedService part 24.

This CL migrates ArcVoiceInteraction{Framework,ArcHome}Service classes.

BUG=672829
TEST=Ran try. Ran on DUT.

Change-Id: Id46d1b3ab424b340e1c28509f0d349f531de6db8
Reviewed-on: https://chromium-review.googlesource.com/572677
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487378}
parent cd466ce0
......@@ -36,7 +36,6 @@
#include "chrome/browser/chromeos/arc/wallpaper/arc_wallpaper_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/arc_session.h"
#include "components/arc/arc_session_runner.h"
......@@ -96,14 +95,6 @@ void ArcServiceLauncher::Initialize() {
// List in lexicographical order.
arc_service_manager_->AddService(
base::MakeUnique<ArcIntentHelperBridge>(arc_bridge_service));
if (chromeos::switches::IsVoiceInteractionEnabled()) {
arc_service_manager_->AddService(
base::MakeUnique<ArcVoiceInteractionFrameworkService>(
arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<ArcVoiceInteractionArcHomeService>(
arc_bridge_service));
}
arc_service_manager_->AddService(
base::MakeUnique<ArcVolumeMounterBridge>(arc_bridge_service));
arc_service_manager_->AddService(
......@@ -179,6 +170,8 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
ArcTracingBridge::GetForBrowserContext(profile);
ArcTtsService::GetForBrowserContext(profile);
ArcUserSessionService::GetForBrowserContext(profile);
ArcVoiceInteractionArcHomeService::GetForBrowserContext(profile);
ArcVoiceInteractionFrameworkService::GetForBrowserContext(profile);
arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>(
arc_service_manager_->arc_bridge_service(),
......
......@@ -10,6 +10,7 @@
#include "ash/shell.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
......@@ -21,7 +22,9 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/instance_holder.h"
#include "content/public/browser/browser_thread.h"
......@@ -80,23 +83,69 @@ void RequestVoiceInteractionStructureCallback(
callback.Run(std::move(root));
}
// Singleton factory for ArcVoiceInteractionArcHomeService.
class ArcVoiceInteractionArcHomeServiceFactory
: public internal::ArcBrowserContextKeyedServiceFactoryBase<
ArcVoiceInteractionArcHomeService,
ArcVoiceInteractionArcHomeServiceFactory> {
public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
static constexpr const char* kName =
"ArcVoiceInteractionArcHomeServiceFactory";
static ArcVoiceInteractionArcHomeServiceFactory* GetInstance() {
return base::Singleton<ArcVoiceInteractionArcHomeServiceFactory>::get();
}
private:
friend base::DefaultSingletonTraits<ArcVoiceInteractionArcHomeServiceFactory>;
ArcVoiceInteractionArcHomeServiceFactory() {
DependsOn(ArcVoiceInteractionFrameworkService::GetFactory());
}
~ArcVoiceInteractionArcHomeServiceFactory() override = default;
// BrowserContextKeyedServiceFactory override:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override {
if (!chromeos::switches::IsVoiceInteractionEnabled())
return nullptr;
return ArcBrowserContextKeyedServiceFactoryBase::BuildServiceInstanceFor(
context);
}
};
} // namespace
// static
ArcVoiceInteractionArcHomeService*
ArcVoiceInteractionArcHomeService::GetForBrowserContext(
content::BrowserContext* context) {
return ArcVoiceInteractionArcHomeServiceFactory::GetForBrowserContext(
context);
}
ArcVoiceInteractionArcHomeService::ArcVoiceInteractionArcHomeService(
content::BrowserContext* context,
ArcBridgeService* bridge_service)
: ArcService(bridge_service), binding_(this) {
arc_bridge_service()->voice_interaction_arc_home()->AddObserver(this);
: context_(context), arc_bridge_service_(bridge_service), binding_(this) {
arc_bridge_service_->voice_interaction_arc_home()->AddObserver(this);
}
ArcVoiceInteractionArcHomeService::~ArcVoiceInteractionArcHomeService() {
arc_bridge_service()->voice_interaction_arc_home()->RemoveObserver(this);
// TODO(hidehiko): Currently, the lifetime of ArcBridgeService and
// BrowserContextKeyedService is not nested.
// If ArcServiceManager::Get() returns nullptr, it is already destructed,
// so do not touch it.
if (ArcServiceManager::Get())
arc_bridge_service_->voice_interaction_arc_home()->RemoveObserver(this);
}
void ArcVoiceInteractionArcHomeService::OnInstanceReady() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
mojom::VoiceInteractionArcHomeInstance* home_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_arc_home(), Init);
arc_bridge_service_->voice_interaction_arc_home(), Init);
DCHECK(home_instance);
mojom::VoiceInteractionArcHomeHostPtr host_proxy;
binding_.Bind(mojo::MakeRequest(&host_proxy));
......@@ -108,8 +157,7 @@ void ArcVoiceInteractionArcHomeService::GetVoiceInteractionStructure(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto* framework_service =
ArcServiceManager::Get()
->GetService<ArcVoiceInteractionFrameworkService>();
ArcVoiceInteractionFrameworkService::GetForBrowserContext(context_);
if (!framework_service->ValidateTimeSinceUserInteraction()) {
callback.Run(mojom::VoiceInteractionStructure::New());
return;
......
......@@ -6,26 +6,38 @@
#define CHROME_BROWSER_CHROMEOS_ARC_VOICE_INTERACTION_ARC_VOICE_INTERACTION_ARC_HOME_SERVICE_H_
#include "base/macros.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/voice_interaction_arc_home.mojom.h"
#include "components/arc/instance_holder.h"
#include "components/keyed_service/core/keyed_service.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/accessibility/ax_tree_update.h"
namespace content {
class BrowserContext;
} // namespace content
namespace ui {
struct AXSnapshotNodeAndroid;
} // ui
namespace arc {
class ArcBridgeService;
// ArcVoiceInteractionArcHomeService provides view hierarchy to to ARC to be
// used by VoiceInteractionSession. This class lives on the UI thread.
class ArcVoiceInteractionArcHomeService
: public ArcService,
: public KeyedService,
public mojom::VoiceInteractionArcHomeHost,
public InstanceHolder<mojom::VoiceInteractionArcHomeInstance>::Observer {
public:
explicit ArcVoiceInteractionArcHomeService(ArcBridgeService* bridge_service);
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcVoiceInteractionArcHomeService* GetForBrowserContext(
content::BrowserContext* context);
ArcVoiceInteractionArcHomeService(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcVoiceInteractionArcHomeService() override;
// InstanceHolder<mojom::VoiceInteractionArcHomeInstance> overrides;
......@@ -41,6 +53,9 @@ class ArcVoiceInteractionArcHomeService
const ui::AXSnapshotNodeAndroid& view_structure);
private:
content::BrowserContext* const context_;
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
mojo::Binding<mojom::VoiceInteractionArcHomeHost> binding_;
DISALLOW_COPY_AND_ASSIGN(ArcVoiceInteractionArcHomeService);
......
......@@ -16,13 +16,14 @@
#include "base/containers/flat_set.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/task_scheduler/post_task.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
......@@ -30,6 +31,7 @@
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_util.h"
#include "components/arc/instance_holder.h"
#include "components/exo/surface.h"
......@@ -158,27 +160,71 @@ void EncodeAndReturnImage(
callback);
}
// Singleton factory for ArcVoiceInteractionFrameworkService.
class ArcVoiceInteractionFrameworkServiceFactory
: public internal::ArcBrowserContextKeyedServiceFactoryBase<
ArcVoiceInteractionFrameworkService,
ArcVoiceInteractionFrameworkServiceFactory> {
public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
static constexpr const char* kName =
"ArcVoiceInteractionFrameworkServiceFactory";
static ArcVoiceInteractionFrameworkServiceFactory* GetInstance() {
return base::Singleton<ArcVoiceInteractionFrameworkServiceFactory>::get();
}
private:
friend base::DefaultSingletonTraits<
ArcVoiceInteractionFrameworkServiceFactory>;
ArcVoiceInteractionFrameworkServiceFactory() = default;
~ArcVoiceInteractionFrameworkServiceFactory() override = default;
// BrowserContextKeyedServiceFactory override:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override {
if (!chromeos::switches::IsVoiceInteractionEnabled())
return nullptr;
return ArcBrowserContextKeyedServiceFactoryBase::BuildServiceInstanceFor(
context);
}
};
} // namespace
// static
const char ArcVoiceInteractionFrameworkService::kArcServiceName[] =
"arc::ArcVoiceInteractionFrameworkService";
ArcVoiceInteractionFrameworkService*
ArcVoiceInteractionFrameworkService::GetForBrowserContext(
content::BrowserContext* context) {
return ArcVoiceInteractionFrameworkServiceFactory::GetForBrowserContext(
context);
}
KeyedServiceBaseFactory* ArcVoiceInteractionFrameworkService::GetFactory() {
return ArcVoiceInteractionFrameworkServiceFactory::GetInstance();
}
ArcVoiceInteractionFrameworkService::ArcVoiceInteractionFrameworkService(
content::BrowserContext* context,
ArcBridgeService* bridge_service)
: ArcService(bridge_service), binding_(this) {
arc_bridge_service()->voice_interaction_framework()->AddObserver(this);
: context_(context), arc_bridge_service_(bridge_service), binding_(this) {
arc_bridge_service_->voice_interaction_framework()->AddObserver(this);
}
ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() {
arc_bridge_service()->voice_interaction_framework()->RemoveObserver(this);
// TODO(hidehiko): Currently, the lifetime of ArcBridgeService and
// BrowserContextKeyedService is not nested.
// If ArcServiceManager::Get() returns nullptr, it is already destructed,
// so do not touch it.
if (ArcServiceManager::Get())
arc_bridge_service_->voice_interaction_framework()->RemoveObserver(this);
}
void ArcVoiceInteractionFrameworkService::OnInstanceReady() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(), Init);
arc_bridge_service_->voice_interaction_framework(), Init);
DCHECK(framework_instance);
mojom::VoiceInteractionFrameworkHostPtr host_proxy;
binding_.Bind(mojo::MakeRequest(&host_proxy));
......@@ -323,7 +369,7 @@ void ArcVoiceInteractionFrameworkService::StartVoiceInteractionSetupWizard() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc::mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(),
arc_bridge_service_->voice_interaction_framework(),
StartVoiceInteractionSetupWizard);
if (!framework_instance)
return;
......@@ -334,7 +380,7 @@ void ArcVoiceInteractionFrameworkService::SetMetalayerVisibility(bool visible) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(),
arc_bridge_service_->voice_interaction_framework(),
SetMetalayerVisibility);
if (!framework_instance) {
CallAndResetMetalayerCallback();
......@@ -357,7 +403,7 @@ void ArcVoiceInteractionFrameworkService::SetVoiceInteractionEnabled(
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(),
arc_bridge_service_->voice_interaction_framework(),
SetVoiceInteractionEnabled);
if (!framework_instance)
return;
......@@ -370,7 +416,7 @@ void ArcVoiceInteractionFrameworkService::SetVoiceInteractionContextEnabled(
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(),
arc_bridge_service_->voice_interaction_framework(),
SetVoiceInteractionContextEnabled);
if (!framework_instance)
return;
......@@ -381,7 +427,7 @@ void ArcVoiceInteractionFrameworkService::StartSessionFromUserInteraction(
const gfx::Rect& rect) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
if (!Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean(
prefs::kArcVoiceInteractionValuePropAccepted)) {
// If voice interaction value prop already showing, return.
if (chromeos::LoginDisplayHost::default_host())
......@@ -396,7 +442,7 @@ void ArcVoiceInteractionFrameworkService::StartSessionFromUserInteraction(
return;
}
if (!arc_bridge_service()->voice_interaction_framework()->has_instance()) {
if (!arc_bridge_service_->voice_interaction_framework()->has_instance()) {
SetArcCpuRestriction(false);
return;
}
......@@ -407,14 +453,14 @@ void ArcVoiceInteractionFrameworkService::StartSessionFromUserInteraction(
if (rect.IsEmpty()) {
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(),
arc_bridge_service_->voice_interaction_framework(),
StartVoiceInteractionSession);
DCHECK(framework_instance);
framework_instance->StartVoiceInteractionSession();
} else {
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->voice_interaction_framework(),
arc_bridge_service_->voice_interaction_framework(),
StartVoiceInteractionSessionForRegion);
DCHECK(framework_instance);
framework_instance->StartVoiceInteractionSessionForRegion(rect);
......
......@@ -9,32 +9,48 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/voice_interaction_framework.mojom.h"
#include "components/arc/instance_holder.h"
#include "components/keyed_service/core/keyed_service.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_handler.h"
class KeyedServiceBaseFactory;
namespace content {
class BrowserContext;
} // namespace content
namespace gfx {
class Rect;
} // namespace gfx
namespace arc {
class ArcBridgeService;
// This provides voice interaction context (currently screenshots)
// to ARC to be used by VoiceInteractionSession. This class lives on the UI
// thread.
class ArcVoiceInteractionFrameworkService
: public ArcService,
: public KeyedService,
public mojom::VoiceInteractionFrameworkHost,
public ui::AcceleratorTarget,
public ui::EventHandler,
public InstanceHolder<
mojom::VoiceInteractionFrameworkInstance>::Observer {
public:
explicit ArcVoiceInteractionFrameworkService(
ArcBridgeService* bridge_service);
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcVoiceInteractionFrameworkService* GetForBrowserContext(
content::BrowserContext* context);
// Returns factory for ArcVoiceInteractionFrameworkService.
static KeyedServiceBaseFactory* GetFactory();
ArcVoiceInteractionFrameworkService(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcVoiceInteractionFrameworkService() override;
// InstanceHolder<mojom::VoiceInteractionFrameworkInstance> overrides.
......@@ -86,9 +102,6 @@ class ArcVoiceInteractionFrameworkService
// Start the voice interaction setup wizard in container.
void StartVoiceInteractionSetupWizard();
// For supporting ArcServiceManager::GetService<T>().
static const char kArcServiceName[];
private:
void SetMetalayerVisibility(bool visible);
......@@ -96,6 +109,8 @@ class ArcVoiceInteractionFrameworkService
bool InitiateUserInteraction();
content::BrowserContext* context_;
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager
mojo::Binding<mojom::VoiceInteractionFrameworkHost> binding_;
base::Closure metalayer_closed_callback_;
bool metalayer_enabled_ = false;
......
......@@ -15,7 +15,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/prefs/pref_service_syncable_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/chrome_switches.h"
......@@ -111,13 +111,12 @@ class DialogLauncher : public content::NotificationObserver {
// If voice interaction value prop needs to be shown, the tutorial will be
// shown after the voice interaction OOBE flow.
if (arc::IsArcPlayStoreEnabledForProfile(
ProfileManager::GetActiveUserProfile()) &&
if (arc::IsArcPlayStoreEnabledForProfile(profile_) &&
!profile_->GetPrefs()->GetBoolean(
prefs::kArcVoiceInteractionValuePropAccepted)) {
auto* service =
arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(
profile_);
if (service)
service->StartSessionFromUserInteraction(gfx::Rect());
} else {
......
......@@ -91,7 +91,6 @@
#include "chromeos/settings/timezone_settings.h"
#include "chromeos/timezone/timezone_provider.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
#include "components/crash/content/app/breakpad_linux.h"
#include "components/pairing/bluetooth_controller_pairing_controller.h"
#include "components/pairing/bluetooth_host_pairing_controller.h"
......@@ -1608,9 +1607,9 @@ bool WizardController::ShouldShowVoiceInteractionValueProp() const {
}
void WizardController::StartVoiceInteractionSetupWizard() {
arc::ArcVoiceInteractionFrameworkService* service =
arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
auto* service =
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(
ProfileManager::GetActiveUserProfile());
if (service)
service->StartVoiceInteractionSetupWizard();
}
......
......@@ -9,13 +9,13 @@
#include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.h"
#include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
#include "components/arc/arc_service_manager.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/app_list/presenter/app_list_presenter_impl.h"
#include "ui/gfx/geometry/rect.h"
AppListPresenterService::AppListPresenterService() : binding_(this) {
AppListPresenterService::AppListPresenterService(Profile* profile)
: profile_(profile), binding_(this) {
content::ServiceManagerConnection* connection =
content::ServiceManagerConnection::GetForProcess();
if (connection && connection->GetConnector()) {
......@@ -47,8 +47,8 @@ void AppListPresenterService::ToggleAppList(int64_t display_id) {
}
void AppListPresenterService::StartVoiceInteractionSession() {
auto* service = arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
auto* service =
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(profile_);
if (service)
service->StartSessionFromUserInteraction(gfx::Rect());
}
......
......@@ -9,6 +9,8 @@
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/app_list/presenter/app_list_presenter.mojom.h"
class Profile;
namespace app_list {
class AppListPresenterImpl;
}
......@@ -16,7 +18,7 @@ class AppListPresenterImpl;
// A service providing the Mojo interface to manipulate the App List.
class AppListPresenterService : public app_list::mojom::AppListPresenter {
public:
AppListPresenterService();
explicit AppListPresenterService(Profile* profile);
~AppListPresenterService() override;
// app_list::mojom::AppListPresenter:
......@@ -28,6 +30,7 @@ class AppListPresenterService : public app_list::mojom::AppListPresenter {
private:
app_list::AppListPresenterImpl* GetPresenter();
Profile* const profile_; // Owned by ProfileManager.
mojo::Binding<app_list::mojom::AppListPresenter> binding_;
DISALLOW_COPY_AND_ASSIGN(AppListPresenterService);
......
......@@ -111,7 +111,8 @@ void AppListServiceAsh::Init(Profile* initial_profile) {
// The AppListPresenterService ctor calls AppListServiceAsh::GetInstance(),
// which isn't available in the AppListServiceAsh constructor, so init here.
// This establishes the mojo connections between the app list and presenter.
app_list_presenter_service_ = base::MakeUnique<AppListPresenterService>();
app_list_presenter_service_ =
base::MakeUnique<AppListPresenterService>(initial_profile);
// Ensure the StartPageService is created here. This early initialization is
// necessary to allow the WebContents to load before the app list is shown.
......
......@@ -12,15 +12,12 @@
#include "ash/utility/screenshot_controller.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.h"
#include "chrome/browser/chromeos/note_taking_helper.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h"
......@@ -31,8 +28,9 @@ namespace chromeos {
class VoiceInteractionScreenshotDelegate : public ash::ScreenshotDelegate {
public:
VoiceInteractionScreenshotDelegate() {}
~VoiceInteractionScreenshotDelegate() override {}
explicit VoiceInteractionScreenshotDelegate(Profile* profile)
: profile_(profile) {}
~VoiceInteractionScreenshotDelegate() override = default;
private:
void HandleTakeScreenshotForAllRootWindows() override { NOTIMPLEMENTED(); }
......@@ -40,8 +38,8 @@ class VoiceInteractionScreenshotDelegate : public ash::ScreenshotDelegate {
void HandleTakePartialScreenshot(aura::Window* window,
const gfx::Rect& rect) override {
auto* framework =
arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(
profile_);
if (!framework)
return;
double device_scale_factor = window->layer()->device_scale_factor();
......@@ -55,6 +53,8 @@ class VoiceInteractionScreenshotDelegate : public ash::ScreenshotDelegate {
bool CanTakeScreenshot() override { return true; }
Profile* const profile_; // Owned by ProfileManager.
DISALLOW_COPY_AND_ASSIGN(VoiceInteractionScreenshotDelegate);
};
......@@ -181,7 +181,7 @@ void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) {
// into a separate tool next to "Capture region".
if (!voice_interaction_screenshot_delegate_) {
voice_interaction_screenshot_delegate_ =
base::MakeUnique<VoiceInteractionScreenshotDelegate>();
base::MakeUnique<VoiceInteractionScreenshotDelegate>(profile_);
}
screenshot_delegate = voice_interaction_screenshot_delegate_.get();
} else {
......@@ -203,19 +203,14 @@ void PaletteDelegateChromeOS::CancelPartialScreenshot() {
}
bool PaletteDelegateChromeOS::IsMetalayerSupported() {
if (!arc::IsArcAllowedForProfile(profile_))
return false;
arc::ArcVoiceInteractionFrameworkService* service =
arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
auto* service =
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(profile_);
return service && service->IsMetalayerSupported();
}
void PaletteDelegateChromeOS::ShowMetalayer(const base::Closure& closed) {
arc::ArcVoiceInteractionFrameworkService* service =
arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
auto* service =
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(profile_);
if (!service) {
if (!closed.is_null())
closed.Run();
......@@ -225,9 +220,8 @@ void PaletteDelegateChromeOS::ShowMetalayer(const base::Closure& closed) {
}
void PaletteDelegateChromeOS::HideMetalayer() {
arc::ArcVoiceInteractionFrameworkService* service =
arc::ArcServiceManager::Get()
->GetService<arc::ArcVoiceInteractionFrameworkService>();
auto* service =
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(profile_);
if (!service)
return;
service->HideMetalayer();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment