Commit 13e14812 authored by James Cook's avatar James Cook Committed by Commit Bot

lacros: Fix threading mistake when opening file manager

Attempting to open a downloaded file from the download shelf would
trigger a DCHECK because I was using the file manager mojo remote on
the wrong thread.

The code is asynchronous already, so post a task to the UI thread
to do the work.

Bug: none
Change-Id: Ib43969c51b479ab4bbfecc7198eea7d1a193a1cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2553082
Auto-Submit: James Cook <jamescook@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829926}
parent 1ba2afb7
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "chrome/browser/platform_util_internal.h" #include "chrome/browser/platform_util_internal.h"
#include "chromeos/crosapi/mojom/file_manager.mojom.h" #include "chromeos/crosapi/mojom/file_manager.mojom.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h" #include "chromeos/lacros/lacros_chrome_service_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
namespace platform_util { namespace platform_util {
namespace { namespace {
...@@ -24,11 +26,9 @@ void OnOpenResult(const base::FilePath& path, ...@@ -24,11 +26,9 @@ void OnOpenResult(const base::FilePath& path,
LOG(ERROR) << "Unable to open " << path.AsUTF8Unsafe() << " " << result; LOG(ERROR) << "Unable to open " << path.AsUTF8Unsafe() << " " << result;
} }
} // namespace // File manager remote can only be accessed on UI thread.
void OpenItemOnUiThread(const base::FilePath& path, OpenItemType type) {
namespace internal { DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) {
auto* service = chromeos::LacrosChromeServiceImpl::Get(); auto* service = chromeos::LacrosChromeServiceImpl::Get();
if (service->GetInterfaceVersion(crosapi::mojom::FileManager::Uuid_) < 1) { if (service->GetInterfaceVersion(crosapi::mojom::FileManager::Uuid_) < 1) {
LOG(ERROR) << "Unsupported ash version."; LOG(ERROR) << "Unsupported ash version.";
...@@ -46,9 +46,20 @@ void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) { ...@@ -46,9 +46,20 @@ void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) {
} }
} }
} // namespace
namespace internal {
void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) {
// This function is called on a blocking thread, so open on the UI thread.
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&OpenItemOnUiThread, path, type));
}
} // namespace internal } // namespace internal
void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto* service = chromeos::LacrosChromeServiceImpl::Get(); auto* service = chromeos::LacrosChromeServiceImpl::Get();
int interface_version = int interface_version =
service->GetInterfaceVersion(crosapi::mojom::FileManager::Uuid_); service->GetInterfaceVersion(crosapi::mojom::FileManager::Uuid_);
......
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