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