Commit b520619b authored by fdoray's avatar fdoray Committed by Commit bot

Use TaskScheduler instead of WorkerPool in fake_cros_disks_client.cc.

The following traits are used:

Priority:
  BACKGROUND
    User won't notice if this task takes an arbitrarily long time
    to complete.

  and

  Inherited (default)
    The priority is inherited from the calling context (i.e. TaskTraits
    are initialized with the priority of the current task).

Shutdown behavior: CONTINUE_ON_SHUTDOWN
  Tasks posted with this mode which have not started executing before
  shutdown is initiated will never run. Tasks with this mode running at
  shutdown will be ignored (the worker will not be joined).

  Note: Tasks that were previously posted to base::WorkerPool should
  use this shutdown behavior because this is how base::WorkerPool
  handles all its tasks.

May Block:
  Tasks posted with MayBlock() may block. This includes but is not
  limited to tasks that wait on synchronous file I/O operations:
  read or write a file from disk, interact with a pipe or a socket,
  rename or delete a file, enumerate files in a directory, etc. This
  trait isn't required for the mere use of locks.

BUG=659191

Review-Url: https://codereview.chromium.org/2601413002
Cr-Commit-Position: refs/heads/master@{#442074}
parent d9d2b1f6
...@@ -9,9 +9,8 @@ ...@@ -9,9 +9,8 @@
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/task_runner_util.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
namespace chromeos { namespace chromeos {
...@@ -104,16 +103,14 @@ void FakeCrosDisksClient::Mount(const std::string& source_path, ...@@ -104,16 +103,14 @@ void FakeCrosDisksClient::Mount(const std::string& source_path,
} }
mounted_paths_.insert(mounted_path); mounted_paths_.insert(mounted_path);
base::PostTaskAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
base::WorkerPool::GetTaskRunner(true /* task_is_slow */).get(), FROM_HERE, base::TaskTraits()
FROM_HERE, .WithShutdownBehavior(
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
.MayBlock(),
base::Bind(&PerformFakeMount, source_path, mounted_path), base::Bind(&PerformFakeMount, source_path, mounted_path),
base::Bind(&DidMount, base::Bind(&DidMount, mount_completed_handler_, source_path, type,
mount_completed_handler_, callback, mounted_path));
source_path,
type,
callback,
mounted_path));
} }
void FakeCrosDisksClient::Unmount(const std::string& device_path, void FakeCrosDisksClient::Unmount(const std::string& device_path,
...@@ -126,13 +123,16 @@ void FakeCrosDisksClient::Unmount(const std::string& device_path, ...@@ -126,13 +123,16 @@ void FakeCrosDisksClient::Unmount(const std::string& device_path,
// Remove the dummy mounted directory if it exists. // Remove the dummy mounted directory if it exists.
if (mounted_paths_.count(base::FilePath::FromUTF8Unsafe(device_path)) > 0) { if (mounted_paths_.count(base::FilePath::FromUTF8Unsafe(device_path)) > 0) {
mounted_paths_.erase(base::FilePath::FromUTF8Unsafe(device_path)); mounted_paths_.erase(base::FilePath::FromUTF8Unsafe(device_path));
base::WorkerPool::PostTaskAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, FROM_HERE, base::TaskTraits()
.WithShutdownBehavior(
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
.WithPriority(base::TaskPriority::BACKGROUND)
.MayBlock(),
base::Bind(base::IgnoreResult(&base::DeleteFile), base::Bind(base::IgnoreResult(&base::DeleteFile),
base::FilePath::FromUTF8Unsafe(device_path), base::FilePath::FromUTF8Unsafe(device_path),
true /* recursive */), true /* recursive */),
callback, callback);
true /* task_is_slow */);
} }
unmount_call_count_++; unmount_call_count_++;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/scoped_task_scheduler.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cros_disks_client.h" #include "chromeos/dbus/fake_cros_disks_client.h"
#include "chromeos/disks/disk_mount_manager.h" #include "chromeos/disks/disk_mount_manager.h"
...@@ -405,7 +406,7 @@ std::ostream& operator<<(std::ostream& stream, ...@@ -405,7 +406,7 @@ std::ostream& operator<<(std::ostream& stream,
class DiskMountManagerTest : public testing::Test { class DiskMountManagerTest : public testing::Test {
public: public:
DiskMountManagerTest() {} DiskMountManagerTest() : scoped_task_scheduler_(&message_loop_) {}
~DiskMountManagerTest() override {} ~DiskMountManagerTest() override {}
// Sets up test dbus tread manager and disks mount manager. // Sets up test dbus tread manager and disks mount manager.
...@@ -480,7 +481,10 @@ class DiskMountManagerTest : public testing::Test { ...@@ -480,7 +481,10 @@ class DiskMountManagerTest : public testing::Test {
protected: protected:
chromeos::FakeCrosDisksClient* fake_cros_disks_client_; chromeos::FakeCrosDisksClient* fake_cros_disks_client_;
std::unique_ptr<MockDiskMountManagerObserver> observer_; std::unique_ptr<MockDiskMountManagerObserver> observer_;
private:
base::MessageLoopForUI message_loop_; base::MessageLoopForUI message_loop_;
base::test::ScopedTaskScheduler scoped_task_scheduler_;
}; };
// Tests that the observer gets notified on attempt to format non existent mount // Tests that the observer gets notified on attempt to format non existent mount
......
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