Commit 385e3940 authored by tommycli's avatar tommycli Committed by Commit bot

Hotlist Slow: Remove extra thread pool created by VolumeMountWatcherWin.

BUG=458541

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

Cr-Commit-Position: refs/heads/master@{#318936}
parent 3611ddb2
...@@ -97,7 +97,6 @@ void StorageMonitorWinTest::SetUp() { ...@@ -97,7 +97,6 @@ void StorageMonitorWinTest::SetUp() {
void StorageMonitorWinTest::TearDown() { void StorageMonitorWinTest::TearDown() {
RunUntilIdle(); RunUntilIdle();
monitor_->RemoveObserver(&observer_); monitor_->RemoveObserver(&observer_);
volume_mount_watcher_->ShutdownWorkerPool();
// Windows storage monitor must be destroyed on the same thread // Windows storage monitor must be destroyed on the same thread
// as construction. // as construction.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/storage_monitor/storage_info.h" #include "components/storage_monitor/storage_info.h"
#include "content/public/browser/browser_thread.h"
namespace storage_monitor { namespace storage_monitor {
...@@ -108,7 +109,7 @@ void TestVolumeMountWatcherWin::SetAttachedDevicesFake() { ...@@ -108,7 +109,7 @@ void TestVolumeMountWatcherWin::SetAttachedDevicesFake() {
} }
void TestVolumeMountWatcherWin::FlushWorkerPoolForTesting() { void TestVolumeMountWatcherWin::FlushWorkerPoolForTesting() {
device_info_worker_pool_->FlushForTesting(); content::BrowserThread::GetBlockingPool()->FlushForTesting();
} }
void TestVolumeMountWatcherWin::DeviceCheckComplete( void TestVolumeMountWatcherWin::DeviceCheckComplete(
...@@ -150,8 +151,4 @@ VolumeMountWatcherWin::GetAttachedDevicesCallbackType ...@@ -150,8 +151,4 @@ VolumeMountWatcherWin::GetAttachedDevicesCallbackType
return base::Bind(&FakeGetSingleAttachedDevice); return base::Bind(&FakeGetSingleAttachedDevice);
} }
void TestVolumeMountWatcherWin::ShutdownWorkerPool() {
device_info_worker_pool_->Shutdown();
}
} // namespace storage_monitor } // namespace storage_monitor
...@@ -53,10 +53,6 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin { ...@@ -53,10 +53,6 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
virtual GetDeviceDetailsCallbackType virtual GetDeviceDetailsCallbackType
GetDeviceDetailsCallback() const override; GetDeviceDetailsCallback() const override;
// Should be used by unit tests to make sure the worker pool doesn't survive
// into other test runs.
void ShutdownWorkerPool();
private: private:
std::vector<base::FilePath> devices_checked_; std::vector<base::FilePath> devices_checked_;
scoped_ptr<base::WaitableEvent> device_check_complete_event_; scoped_ptr<base::WaitableEvent> device_check_complete_event_;
......
...@@ -34,6 +34,8 @@ namespace { ...@@ -34,6 +34,8 @@ namespace {
const DWORD kMaxPathBufLen = MAX_PATH + 1; const DWORD kMaxPathBufLen = MAX_PATH + 1;
const char kDeviceInfoTaskRunnerName[] = "device-info-task-runner";
enum DeviceType { enum DeviceType {
FLOPPY, FLOPPY,
REMOVABLE, REMOVABLE,
...@@ -324,18 +326,12 @@ void EjectDeviceInThreadPool( ...@@ -324,18 +326,12 @@ void EjectDeviceInThreadPool(
} // namespace } // namespace
const int kWorkerPoolNumThreads = 3;
const char* kWorkerPoolNamePrefix = "DeviceInfoPool";
VolumeMountWatcherWin::VolumeMountWatcherWin() VolumeMountWatcherWin::VolumeMountWatcherWin()
: device_info_worker_pool_(new base::SequencedWorkerPool( : notifications_(NULL), weak_factory_(this) {
kWorkerPoolNumThreads, kWorkerPoolNamePrefix)), base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
notifications_(NULL), device_info_task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
weak_factory_(this) { pool->GetNamedSequenceToken(kDeviceInfoTaskRunnerName),
task_runner_ = base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
device_info_worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior(
device_info_worker_pool_->GetSequenceToken(),
base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
} }
// static // static
...@@ -361,7 +357,7 @@ void VolumeMountWatcherWin::Init() { ...@@ -361,7 +357,7 @@ void VolumeMountWatcherWin::Init() {
// so a posted task from the constructor would never run. Therefore, do all // so a posted task from the constructor would never run. Therefore, do all
// the initializations here. // the initializations here.
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE, GetAttachedDevicesCallback(), device_info_task_runner_.get(), FROM_HERE, GetAttachedDevicesCallback(),
base::Bind(&VolumeMountWatcherWin::AddDevicesOnUIThread, base::Bind(&VolumeMountWatcherWin::AddDevicesOnUIThread,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -374,7 +370,7 @@ void VolumeMountWatcherWin::AddDevicesOnUIThread( ...@@ -374,7 +370,7 @@ void VolumeMountWatcherWin::AddDevicesOnUIThread(
if (ContainsKey(pending_device_checks_, removable_devices[i])) if (ContainsKey(pending_device_checks_, removable_devices[i]))
continue; continue;
pending_device_checks_.insert(removable_devices[i]); pending_device_checks_.insert(removable_devices[i]);
task_runner_->PostTask( device_info_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd, base::Bind(&VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd,
removable_devices[i], GetDeviceDetailsCallback(), removable_devices[i], GetDeviceDetailsCallback(),
...@@ -503,7 +499,6 @@ void VolumeMountWatcherWin::SetNotifications( ...@@ -503,7 +499,6 @@ void VolumeMountWatcherWin::SetNotifications(
VolumeMountWatcherWin::~VolumeMountWatcherWin() { VolumeMountWatcherWin::~VolumeMountWatcherWin() {
weak_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
device_info_worker_pool_->Shutdown();
} }
void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread(
...@@ -548,9 +543,9 @@ void VolumeMountWatcherWin::EjectDevice( ...@@ -548,9 +543,9 @@ void VolumeMountWatcherWin::EjectDevice(
return; return;
} }
task_runner_->PostTask( device_info_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::Bind(&EjectDeviceInThreadPool, device, callback,
base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); device_info_task_runner_, 0));
} }
} // namespace storage_monitor } // namespace storage_monitor
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/threading/sequenced_worker_pool.h"
#include "components/storage_monitor/storage_info.h" #include "components/storage_monitor/storage_info.h"
#include "components/storage_monitor/storage_monitor.h" #include "components/storage_monitor/storage_monitor.h"
...@@ -90,11 +89,8 @@ class VolumeMountWatcherWin { ...@@ -90,11 +89,8 @@ class VolumeMountWatcherWin {
virtual GetAttachedDevicesCallbackType GetAttachedDevicesCallback() const; virtual GetAttachedDevicesCallbackType GetAttachedDevicesCallback() const;
virtual GetDeviceDetailsCallbackType GetDeviceDetailsCallback() const; virtual GetDeviceDetailsCallbackType GetDeviceDetailsCallback() const;
// Worker pool used to collect device information. Used because some // Used for device info calls that may take a long time.
// devices freeze workers trying to get device info, resulting in scoped_refptr<base::SequencedTaskRunner> device_info_task_runner_;
// shutdown hangs.
scoped_refptr<base::SequencedWorkerPool> device_info_worker_pool_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
private: private:
friend class TestVolumeMountWatcherWin; friend class TestVolumeMountWatcherWin;
......
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