Commit b9bfea77 authored by dmazzoni's avatar dmazzoni Committed by Commit bot

Pass a TaskRunner through ViewsDelegate to put AX init on FILE thread

Adds an interface to ViewsDelegate to get a TaskRunner for a thread that
can be used for initialization tasks (implemented using the FILE thread),
and passes that TaskRunner to the ATK accessibility initialization code,
which currently does I/O on the main thread, causing a perf issue.

This change just adds the plumbing to get the TaskRunner there.
This will be followed up by this change that actually moves the initialization
to the other thread: https://codereview.chromium.org/1028553003/

BUG=468112

Review URL: https://codereview.chromium.org/1089003003

Cr-Commit-Position: refs/heads/master@{#327117}
parent f44602c3
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_window_state.h" #include "chrome/browser/ui/browser_window_state.h"
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/context_factory.h" #include "content/public/browser/context_factory.h"
#include "grit/chrome_unscaled_resources.h" #include "grit/chrome_unscaled_resources.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -388,6 +389,16 @@ std::string ChromeViewsDelegate::GetApplicationName() { ...@@ -388,6 +389,16 @@ std::string ChromeViewsDelegate::GetApplicationName() {
return chrome::VersionInfo().Name(); return chrome::VersionInfo().Name();
} }
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
scoped_refptr<base::TaskRunner>
ChromeViewsDelegate::GetTaskRunnerForAuraLinuxAccessibilityInit() {
// This should be on the FILE thread so that we can open libatk-bridge.so
// without blocking.
return content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::FILE);
}
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
int ChromeViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, int ChromeViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor,
const base::Closure& callback) { const base::Closure& callback) {
......
...@@ -49,6 +49,10 @@ class ChromeViewsDelegate : public views::ViewsDelegate { ...@@ -49,6 +49,10 @@ class ChromeViewsDelegate : public views::ViewsDelegate {
#endif #endif
ui::ContextFactory* GetContextFactory() override; ui::ContextFactory* GetContextFactory() override;
std::string GetApplicationName() override; std::string GetApplicationName() override;
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
scoped_refptr<base::TaskRunner>
GetTaskRunnerForAuraLinuxAccessibilityInit() override;
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
int GetAppbarAutohideEdges(HMONITOR monitor, int GetAppbarAutohideEdges(HMONITOR monitor,
const base::Closure& callback) override; const base::Closure& callback) override;
......
...@@ -140,6 +140,14 @@ AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { ...@@ -140,6 +140,14 @@ AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() {
} }
AtkUtilAuraLinux::AtkUtilAuraLinux() { AtkUtilAuraLinux::AtkUtilAuraLinux() {
}
void AtkUtilAuraLinux::Initialize(
scoped_refptr<base::TaskRunner> init_task_runner) {
// TODO(k.czech): use |init_task_runner| to post a task to do the
// initialization rather than doing it on this thread.
// http://crbug.com/468112
// Register our util class. // Register our util class.
g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE));
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "ui/accessibility/ax_export.h" #include "ui/accessibility/ax_export.h"
namespace base {
class TaskRunner;
}
namespace ui { namespace ui {
// This singleton class initializes ATK (accessibility toolkit) and // This singleton class initializes ATK (accessibility toolkit) and
...@@ -21,6 +25,8 @@ class AtkUtilAuraLinux { ...@@ -21,6 +25,8 @@ class AtkUtilAuraLinux {
AtkUtilAuraLinux(); AtkUtilAuraLinux();
virtual ~AtkUtilAuraLinux(); virtual ~AtkUtilAuraLinux();
void Initialize(scoped_refptr<base::TaskRunner> init_task_runner);
private: private:
friend struct DefaultSingletonTraits<AtkUtilAuraLinux>; friend struct DefaultSingletonTraits<AtkUtilAuraLinux>;
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/task_runner.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/atk_util_auralinux.h" #include "ui/accessibility/platform/atk_util_auralinux.h"
#include "ui/accessibility/platform/ax_platform_node_delegate.h" #include "ui/accessibility/platform/ax_platform_node_delegate.h"
...@@ -287,7 +288,12 @@ AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr; ...@@ -287,7 +288,12 @@ AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr;
// static // static
void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) { void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) {
application_ = application; application_ = application;
AtkUtilAuraLinux::GetInstance(); }
// static
void AXPlatformNodeAuraLinux::StaticInitialize(
scoped_refptr<base::TaskRunner> init_task_runner) {
AtkUtilAuraLinux::GetInstance()->Initialize(init_task_runner);
} }
AtkRole AXPlatformNodeAuraLinux::GetAtkRole() { AtkRole AXPlatformNodeAuraLinux::GetAtkRole() {
......
...@@ -7,9 +7,14 @@ ...@@ -7,9 +7,14 @@
#include <atk/atk.h> #include <atk/atk.h>
#include "base/memory/ref_counted.h"
#include "ui/accessibility/ax_export.h" #include "ui/accessibility/ax_export.h"
#include "ui/accessibility/platform/ax_platform_node_base.h" #include "ui/accessibility/platform/ax_platform_node_base.h"
namespace base {
class TaskRunner;
}
namespace ui { namespace ui {
// Implements accessibility on Aura Linux using ATK. // Implements accessibility on Aura Linux using ATK.
...@@ -22,6 +27,10 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase { ...@@ -22,6 +27,10 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
AX_EXPORT static void SetApplication(AXPlatformNode* application); AX_EXPORT static void SetApplication(AXPlatformNode* application);
static AXPlatformNode* application() { return application_; } static AXPlatformNode* application() { return application_; }
// Do static initialization using the given task runner for file operations.
AX_EXPORT static void StaticInitialize(
scoped_refptr<base::TaskRunner> init_task_runner);
AtkRole GetAtkRole(); AtkRole GetAtkRole();
void GetAtkState(AtkStateSet* state_set); void GetAtkState(AtkStateSet* state_set);
void GetAtkRelations(AtkRelationSet* atk_relation_set); void GetAtkRelations(AtkRelationSet* atk_relation_set);
......
...@@ -125,6 +125,13 @@ class AuraLinuxApplication ...@@ -125,6 +125,13 @@ class AuraLinuxApplication
ViewsDelegate::views_delegate->GetApplicationName()); ViewsDelegate::views_delegate->GetApplicationName());
} }
ui::AXPlatformNodeAuraLinux::SetApplication(platform_node_); ui::AXPlatformNodeAuraLinux::SetApplication(platform_node_);
if (ViewsDelegate::views_delegate) {
scoped_refptr<base::TaskRunner> init_task_runner =
ViewsDelegate::views_delegate->
GetTaskRunnerForAuraLinuxAccessibilityInit();
if (init_task_runner)
ui::AXPlatformNodeAuraLinux::StaticInitialize(init_task_runner);
}
} }
~AuraLinuxApplication() override { ~AuraLinuxApplication() override {
......
...@@ -91,6 +91,13 @@ std::string ViewsDelegate::GetApplicationName() { ...@@ -91,6 +91,13 @@ std::string ViewsDelegate::GetApplicationName() {
return program.BaseName().AsUTF8Unsafe(); return program.BaseName().AsUTF8Unsafe();
} }
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
scoped_refptr<base::TaskRunner>
ViewsDelegate::GetTaskRunnerForAuraLinuxAccessibilityInit() {
return nullptr;
}
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
int ViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, int ViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor,
const base::Closure& callback) { const base::Closure& callback) {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace base { namespace base {
class TaskRunner;
class TimeDelta; class TimeDelta;
} }
...@@ -138,6 +139,13 @@ class VIEWS_EXPORT ViewsDelegate { ...@@ -138,6 +139,13 @@ class VIEWS_EXPORT ViewsDelegate {
// Returns the user-visible name of the application. // Returns the user-visible name of the application.
virtual std::string GetApplicationName(); virtual std::string GetApplicationName();
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Get a task runner suitable for posting initialization tasks for
// Aura Linux accessibility.
virtual scoped_refptr<base::TaskRunner>
GetTaskRunnerForAuraLinuxAccessibilityInit();
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
// Starts a query for the appbar autohide edges of the specified monitor and // Starts a query for the appbar autohide edges of the specified monitor and
// returns the current value. If the query finds the edges have changed from // returns the current value. If the query finds the edges have changed from
......
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