REVIEW: access GetApplicationLocale on sequence that allows IO
This commit is contained in:
parent
1912fbb073
commit
a1592446da
13 changed files with 70 additions and 19 deletions
|
@ -842,7 +842,7 @@ void App::SetDesktopName(const std::string& desktop_name) {
|
|||
}
|
||||
|
||||
std::string App::GetLocale() {
|
||||
return l10n_util::GetApplicationLocale("");
|
||||
return g_browser_process->GetApplicationLocale();
|
||||
}
|
||||
|
||||
bool App::MakeSingleInstance(
|
||||
|
|
|
@ -126,10 +126,13 @@ net::HttpAuth::Scheme GetAuthSchemeFromString(const std::string& scheme) {
|
|||
void SetUserAgentInIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
const std::string& accept_lang,
|
||||
const std::string& user_agent) {
|
||||
std::string accept_lang_header = net::HttpUtil::GenerateAcceptLanguageHeader(
|
||||
accept_lang.empty() ? getter->GetURLRequestContext()
|
||||
->http_user_agent_settings()
|
||||
->GetAcceptLanguage()
|
||||
: accept_lang);
|
||||
getter->GetURLRequestContext()->set_http_user_agent_settings(
|
||||
new net::StaticHttpUserAgentSettings(
|
||||
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang),
|
||||
user_agent));
|
||||
new net::StaticHttpUserAgentSettings(accept_lang_header, user_agent));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -642,7 +645,7 @@ void Session::SetUserAgent(const std::string& user_agent,
|
|||
mate::Arguments* args) {
|
||||
browser_context_->SetUserAgent(user_agent);
|
||||
|
||||
std::string accept_lang = l10n_util::GetApplicationLocale("");
|
||||
std::string accept_lang;
|
||||
args->GetNext(&accept_lang);
|
||||
|
||||
scoped_refptr<brightray::URLRequestContextGetter> getter(
|
||||
|
|
|
@ -202,10 +202,6 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
|||
WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs);
|
||||
}
|
||||
|
||||
std::string AtomBrowserClient::GetApplicationLocale() {
|
||||
return l10n_util::GetApplicationLocale("");
|
||||
}
|
||||
|
||||
void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context,
|
||||
|
|
|
@ -53,7 +53,6 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
|||
CreateSpeechRecognitionManagerDelegate() override;
|
||||
void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
|
||||
content::WebPreferences* prefs) override;
|
||||
std::string GetApplicationLocale() override;
|
||||
void OverrideSiteInstanceForNavigation(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context,
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "device/geolocation/geolocation_delegate.h"
|
||||
#include "device/geolocation/geolocation_provider.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "v8/include/v8-debug.h"
|
||||
|
||||
#if defined(USE_X11)
|
||||
|
@ -129,6 +130,12 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
|||
JavascriptEnvironment::Initialize();
|
||||
}
|
||||
|
||||
int AtomBrowserMainParts::PreCreateThreads() {
|
||||
fake_browser_process_->SetApplicationLocale(
|
||||
l10n_util::GetApplicationLocale(""));
|
||||
return brightray::BrowserMainParts::PreCreateThreads();
|
||||
}
|
||||
|
||||
void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||
js_env_->OnMessageLoopCreated();
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
|||
// content::BrowserMainParts:
|
||||
void PreEarlyInitialization() override;
|
||||
void PostEarlyInitialization() override;
|
||||
int PreCreateThreads() override;
|
||||
void PreMainMessageLoopRun() override;
|
||||
bool MainMessageLoopRun(int* result_code) override;
|
||||
void PostMainMessageLoopStart() override;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "base/bind.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "content/public/browser/stream_handle.h"
|
||||
#include "content/public/browser/stream_info.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
@ -193,7 +194,7 @@ void PdfViewerHandler::GetStrings(const base::ListValue* args) {
|
|||
SET_STRING("tooltipZoomOut", "Zoom out");
|
||||
#undef SET_STRING
|
||||
|
||||
webui::SetLoadTimeDataDefaults(l10n_util::GetApplicationLocale(""),
|
||||
webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(),
|
||||
result.get());
|
||||
ResolveJavascriptCallback(*callback_id, *result);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "brightray/browser/browser_client.h"
|
||||
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/path_service.h"
|
||||
#include "brightray/browser/browser_context.h"
|
||||
#include "brightray/browser/browser_main_parts.h"
|
||||
|
@ -11,16 +12,41 @@
|
|||
#include "brightray/browser/media/media_capture_devices_dispatcher.h"
|
||||
#include "brightray/browser/notification_presenter.h"
|
||||
#include "brightray/browser/platform_notification_service.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
BrowserClient* g_browser_client;
|
||||
|
||||
base::LazyInstance<std::string>::DestructorAtExit
|
||||
g_io_thread_application_locale = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
std::string g_application_locale;
|
||||
|
||||
void SetApplicationLocaleOnIOThread(const std::string& locale) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
g_io_thread_application_locale.Get() = locale;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
void BrowserClient::SetApplicationLocale(const std::string& locale) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
if (!BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&SetApplicationLocaleOnIOThread, locale))) {
|
||||
g_io_thread_application_locale.Get() = locale;
|
||||
}
|
||||
g_application_locale = locale;
|
||||
}
|
||||
|
||||
BrowserClient* BrowserClient::Get() {
|
||||
return g_browser_client;
|
||||
}
|
||||
|
@ -88,4 +114,10 @@ content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() {
|
|||
return new DevToolsManagerDelegate;
|
||||
}
|
||||
|
||||
std::string BrowserClient::GetApplicationLocale() {
|
||||
if (BrowserThread::CurrentlyOn(BrowserThread::IO))
|
||||
return g_io_thread_application_locale.Get();
|
||||
return g_application_locale;
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -20,6 +20,7 @@ class PlatformNotificationService;
|
|||
class BrowserClient : public content::ContentBrowserClient {
|
||||
public:
|
||||
static BrowserClient* Get();
|
||||
static void SetApplicationLocale(const std::string& locale);
|
||||
|
||||
BrowserClient();
|
||||
~BrowserClient();
|
||||
|
@ -47,6 +48,7 @@ class BrowserClient : public content::ContentBrowserClient {
|
|||
net::NetLog* GetNetLog() override;
|
||||
base::FilePath GetDefaultDownloadDirectory() override;
|
||||
content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
|
||||
std::string GetApplicationLocale() override;
|
||||
|
||||
protected:
|
||||
// Subclasses should override this to provide their own BrowserMainParts
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "brightray/browser/browser_context.h"
|
||||
#include "brightray/browser/devtools_manager_delegate.h"
|
||||
#include "brightray/browser/media/media_capture_devices_dispatcher.h"
|
||||
|
@ -275,6 +276,9 @@ int BrowserMainParts::PreCreateThreads() {
|
|||
if (!views::LayoutProvider::Get())
|
||||
layout_provider_.reset(new views::LayoutProvider());
|
||||
|
||||
// Initialize the app locale.
|
||||
BrowserClient::SetApplicationLocale(l10n_util::GetApplicationLocale(""));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "base/strings/string_util.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "brightray/browser/net/devtools_network_controller_handle.h"
|
||||
#include "brightray/browser/net/devtools_network_transaction_factory.h"
|
||||
#include "brightray/browser/net/require_ct_delegate.h"
|
||||
|
@ -53,7 +54,6 @@
|
|||
#include "net/url_request/url_request_intercepting_job_factory.h"
|
||||
#include "net/url_request/url_request_job_factory_impl.h"
|
||||
#include "storage/browser/quota/special_storage_policy.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "url/url_constants.h"
|
||||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
|
@ -142,7 +142,7 @@ URLRequestContextGetter::URLRequestContextGetter(
|
|||
protocol_interceptors_(std::move(protocol_interceptors)),
|
||||
job_factory_(nullptr) {
|
||||
// Must first be created on the UI thread.
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
if (protocol_handlers)
|
||||
std::swap(protocol_handlers_, *protocol_handlers);
|
||||
|
@ -168,7 +168,7 @@ net::HostResolver* URLRequestContextGetter::host_resolver() {
|
|||
}
|
||||
|
||||
net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
if (!url_request_context_.get()) {
|
||||
ct_delegate_.reset(new RequireCTDelegate);
|
||||
|
@ -204,10 +204,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
|||
storage_->set_channel_id_service(base::MakeUnique<net::ChannelIDService>(
|
||||
new net::DefaultChannelIDStore(nullptr)));
|
||||
|
||||
std::string accept_lang = l10n_util::GetApplicationLocale("");
|
||||
storage_->set_http_user_agent_settings(base::WrapUnique(
|
||||
new net::StaticHttpUserAgentSettings(
|
||||
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang),
|
||||
storage_->set_http_user_agent_settings(
|
||||
base::WrapUnique(new net::StaticHttpUserAgentSettings(
|
||||
net::HttpUtil::GenerateAcceptLanguageHeader(
|
||||
BrowserClient::Get()->GetApplicationLocale()),
|
||||
user_agent_)));
|
||||
|
||||
std::unique_ptr<net::HostResolver> host_resolver(
|
||||
|
|
|
@ -20,8 +20,12 @@ BrowserProcess::~BrowserProcess() {
|
|||
g_browser_process = NULL;
|
||||
}
|
||||
|
||||
void BrowserProcess::SetApplicationLocale(const std::string& locale) {
|
||||
locale_ = locale;
|
||||
}
|
||||
|
||||
std::string BrowserProcess::GetApplicationLocale() {
|
||||
return l10n_util::GetApplicationLocale("");
|
||||
return locale_;
|
||||
}
|
||||
|
||||
IconManager* BrowserProcess::GetIconManager() {
|
||||
|
|
|
@ -28,6 +28,7 @@ class BrowserProcess {
|
|||
BrowserProcess();
|
||||
~BrowserProcess();
|
||||
|
||||
void SetApplicationLocale(const std::string& locale);
|
||||
std::string GetApplicationLocale();
|
||||
IconManager* GetIconManager();
|
||||
|
||||
|
@ -36,6 +37,7 @@ class BrowserProcess {
|
|||
private:
|
||||
std::unique_ptr<printing::PrintJobManager> print_job_manager_;
|
||||
std::unique_ptr<IconManager> icon_manager_;
|
||||
std::string locale_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserProcess);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue