Commit 43ea8e9e authored by David Trainor's avatar David Trainor Committed by Commit Bot

Add recovery pipeline for DownloadDriver

Add the infrastructure for a DownloadDriver recovery flow.  This CL
doesn't actually perform any cleanup or recovery of a DownloadDriver,
but it just returns success.  Implementing the actual recovery code will
be included in a follow up, but this allows us to implement the
DownloadService comprehensive recovery code without blocking on the
implementation of this component in particular.

BUG=736222

Change-Id: Ibbbb8d64b5114593404339d514bafb8b7d984a9b
Reviewed-on: https://chromium-review.googlesource.com/569073
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486654}
parent 5e247c8a
......@@ -35,6 +35,7 @@ source_set("unit_tests") {
deps = [
":internal",
"//base/test:test_support",
"//content/test:test_support",
"//testing/gmock",
"//testing/gtest",
......
......@@ -108,6 +108,13 @@ void DownloadDriverImpl::Initialize(DownloadDriver::Client* client) {
client_->OnDriverReady(true);
}
void DownloadDriverImpl::HardRecover() {
// TODO(dtrainor, xingliu): Implement recovery for the DownloadManager.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&DownloadDriverImpl::OnHardRecoverComplete,
weak_ptr_factory_.GetWeakPtr(), true));
}
bool DownloadDriverImpl::IsReady() const {
return client_ && download_manager_ &&
download_manager_->IsManagerInitialized();
......@@ -259,4 +266,8 @@ void DownloadDriverImpl::ManagerGoingDown(content::DownloadManager* manager) {
download_manager_ = nullptr;
}
void DownloadDriverImpl::OnHardRecoverComplete(bool success) {
client_->OnDriverHardRecoverComplete(success);
}
} // namespace download
......@@ -35,6 +35,7 @@ class DownloadDriverImpl : public DownloadDriver,
// DownloadDriver implementation.
void Initialize(DownloadDriver::Client* client) override;
void HardRecover() override;
bool IsReady() const override;
void Start(
const RequestParams& request_params,
......@@ -58,6 +59,8 @@ class DownloadDriverImpl : public DownloadDriver,
void OnManagerInitialized() override;
void ManagerGoingDown(content::DownloadManager* manager) override;
void OnHardRecoverComplete(bool success);
// Remove the download, used to be posted to the task queue.
void DoRemoveDownload(const std::string& guid);
......
......@@ -9,6 +9,8 @@
#include "base/guid.h"
#include "base/memory/ptr_util.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/test/fake_download_item.h"
#include "content/public/test/mock_download_manager.h"
#include "net/http/http_response_headers.h"
......@@ -44,6 +46,7 @@ MATCHER_P(DriverEntryEqual, entry, "") {
class MockDriverClient : public DownloadDriver::Client {
public:
MOCK_METHOD1(OnDriverReady, void(bool));
MOCK_METHOD1(OnDriverHardRecoverComplete, void(bool));
MOCK_METHOD1(OnDownloadCreated, void(const DriverEntry&));
MOCK_METHOD2(OnDownloadFailed, void(const DriverEntry&, FailureType));
MOCK_METHOD1(OnDownloadSucceeded, void(const DriverEntry&));
......@@ -52,7 +55,9 @@ class MockDriverClient : public DownloadDriver::Client {
class DownloadDriverImplTest : public testing::Test {
public:
DownloadDriverImplTest() = default;
DownloadDriverImplTest()
: task_runner_(new base::TestSimpleTaskRunner), handle_(task_runner_) {}
~DownloadDriverImplTest() override = default;
void SetUp() override {
......@@ -64,6 +69,10 @@ class DownloadDriverImplTest : public testing::Test {
MockDriverClient mock_client_;
std::unique_ptr<DownloadDriverImpl> driver_;
protected:
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::ThreadTaskRunnerHandle handle_;
private:
DISALLOW_COPY_AND_ASSIGN(DownloadDriverImplTest);
};
......@@ -80,6 +89,17 @@ TEST_F(DownloadDriverImplTest, ManagerLateInitialization) {
->OnManagerInitialized();
}
TEST_F(DownloadDriverImplTest, TestHardRecover) {
EXPECT_CALL(mock_manager_, IsManagerInitialized())
.Times(1)
.WillOnce(Return(false));
driver_->Initialize(&mock_client_);
EXPECT_CALL(mock_client_, OnDriverHardRecoverComplete(true)).Times(1);
driver_->HardRecover();
task_runner_->RunUntilIdle();
}
// Ensures download updates from download items are propagated correctly.
TEST_F(DownloadDriverImplTest, DownloadItemUpdateEvents) {
using DownloadState = content::DownloadItem::DownloadState;
......
......@@ -308,6 +308,8 @@ void ControllerImpl::OnDriverReady(bool success) {
AttemptToFinalizeSetup();
}
void ControllerImpl::OnDriverHardRecoverComplete(bool success) {}
void ControllerImpl::OnDownloadCreated(const DriverEntry& download) {
if (initializing_internals_)
return;
......
......@@ -71,6 +71,7 @@ class ControllerImpl : public Controller,
private:
// DownloadDriver::Client implementation.
void OnDriverReady(bool success) override;
void OnDriverHardRecoverComplete(bool success) override;
void OnDownloadCreated(const DriverEntry& download) override;
void OnDownloadFailed(const DriverEntry& download,
FailureType failure_type) override;
......
......@@ -42,6 +42,10 @@ class DownloadDriver {
// when the low level download library is ready.
virtual void OnDriverReady(bool success) = 0;
// Called asynchronously in response to a DownloadDriver::HardRecover call.
// If |success| is |false|, recovery of the DownloadDriver failed.
virtual void OnDriverHardRecoverComplete(bool success) = 0;
// Called when any download is created.
virtual void OnDownloadCreated(const DriverEntry& download) = 0;
......@@ -62,6 +66,10 @@ class DownloadDriver {
// Initialize the driver to receive download updates.
virtual void Initialize(Client* client) = 0;
// Attempts to clean up and reset the DownloadDriver. It should remove all
// state relevant to the DownloadService.
virtual void HardRecover() = 0;
// Returns if the driver is ready after the low level library has loaded all
// the data. Returns false when the driver is not initialized by the client,
// or low level download library has been shut down.
......
......@@ -22,6 +22,11 @@ void TestDownloadDriver::MakeReady() {
client_->OnDriverReady(is_ready_);
}
void TestDownloadDriver::TriggerHardRecoverComplete(bool success) {
if (client_)
client_->OnDriverHardRecoverComplete(success);
}
void TestDownloadDriver::AddTestData(const std::vector<DriverEntry>& entries) {
for (const auto& entry : entries) {
DCHECK(entries_.find(entry.guid) == entries_.end()) << "Existing guid.";
......@@ -56,6 +61,8 @@ void TestDownloadDriver::Initialize(DownloadDriver::Client* client) {
client_ = client;
}
void TestDownloadDriver::HardRecover() {}
bool TestDownloadDriver::IsReady() const {
return is_ready_;
}
......
......@@ -24,6 +24,7 @@ class TestDownloadDriver : public DownloadDriver {
// Marks download driver as ready, used to test logic that depends on
// data initialization.
void MakeReady();
void TriggerHardRecoverComplete(bool success);
// Adds driver entries data that will be returned
void AddTestData(const std::vector<DriverEntry>& entries);
......@@ -35,6 +36,7 @@ class TestDownloadDriver : public DownloadDriver {
// DownloadDriver implementation.
void Initialize(DownloadDriver::Client* client) override;
void HardRecover() override;
bool IsReady() const override;
void Start(
const RequestParams& params,
......
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