Commit 7b33aa1b authored by Taiju Tsuiki's avatar Taiju Tsuiki Committed by Commit Bot

Revert "More OfflineItemModel implementation"

This reverts commit 16355cba.

Reason for revert:
This seems to cause an ASAN failure on the CI. The error logs are:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%281%29/29069
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8934902171469785040/+/steps/interactive_ui_tests/0/logs/DownloadNotificationTest.IncognitoDownloadFile/0

Original change's description:
> More OfflineItemModel implementation
> 
> This CL makes OfflineItemModel inherit from DownloadUIModel
> 
> Bug: 881499
> Change-Id: I63270a79917bae87fdb4ae3531f9088f7900509e
> Reviewed-on: https://chromium-review.googlesource.com/1225888
> Commit-Queue: Min Qin <qinmin@chromium.org>
> Reviewed-by: Shakti Sahu <shaktisahu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#592645}

TBR=qinmin@chromium.org,shaktisahu@chromium.org

Change-Id: Ifdae8934bae3cf137fd2e4729f076f8df577241d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 881499
Reviewed-on: https://chromium-review.googlesource.com/1234099Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592691}
parent 99d36903
...@@ -303,14 +303,9 @@ base::string16 InterruptReasonMessage( ...@@ -303,14 +303,9 @@ base::string16 InterruptReasonMessage(
// DownloadItemModel // DownloadItemModel
DownloadItemModel::DownloadItemModel(DownloadItem* download) DownloadItemModel::DownloadItemModel(DownloadItem* download)
: download_(download) { : download_(download) {}
download_->AddObserver(this);
}
DownloadItemModel::~DownloadItemModel() { DownloadItemModel::~DownloadItemModel() {}
if (download_)
download_->RemoveObserver(this);
}
ContentId DownloadItemModel::GetContentId() const { ContentId DownloadItemModel::GetContentId() const {
bool off_the_record = content::DownloadItemUtils::GetBrowserContext(download_) bool off_the_record = content::DownloadItemUtils::GetBrowserContext(download_)
...@@ -319,6 +314,16 @@ ContentId DownloadItemModel::GetContentId() const { ...@@ -319,6 +314,16 @@ ContentId DownloadItemModel::GetContentId() const {
download_->GetGuid()); download_->GetGuid());
} }
void DownloadItemModel::AddObserver(DownloadUIModel::Observer* observer) {
DownloadUIModel::AddObserver(observer);
download_->AddObserver(this);
}
void DownloadItemModel::RemoveObserver(DownloadUIModel::Observer* observer) {
DownloadUIModel::RemoveObserver(observer);
download_->RemoveObserver(this);
}
base::string16 DownloadItemModel::GetInterruptReasonText() const { base::string16 DownloadItemModel::GetInterruptReasonText() const {
if (download_->GetState() != DownloadItem::INTERRUPTED || if (download_->GetState() != DownloadItem::INTERRUPTED ||
download_->GetLastReason() == download_->GetLastReason() ==
...@@ -827,7 +832,6 @@ void DownloadItemModel::OnDownloadOpened(DownloadItem* download) { ...@@ -827,7 +832,6 @@ void DownloadItemModel::OnDownloadOpened(DownloadItem* download) {
void DownloadItemModel::OnDownloadDestroyed(DownloadItem* download) { void DownloadItemModel::OnDownloadDestroyed(DownloadItem* download) {
for (auto& obs : observers_) for (auto& obs : observers_)
obs.OnDownloadDestroyed(); obs.OnDownloadDestroyed();
download_ = nullptr;
} }
base::string16 DownloadItemModel::GetInProgressStatusString() const { base::string16 DownloadItemModel::GetInProgressStatusString() const {
......
...@@ -31,6 +31,8 @@ class DownloadItemModel : public DownloadUIModel, ...@@ -31,6 +31,8 @@ class DownloadItemModel : public DownloadUIModel,
~DownloadItemModel() override; ~DownloadItemModel() override;
// DownloadUIModel implementation. // DownloadUIModel implementation.
void AddObserver(DownloadUIModel::Observer* observer) override;
void RemoveObserver(DownloadUIModel::Observer* observer) override;
ContentId GetContentId() const override; ContentId GetContentId() const override;
base::string16 GetInterruptReasonText() const override; base::string16 GetInterruptReasonText() const override;
base::string16 GetStatusText() const override; base::string16 GetStatusText() const override;
......
...@@ -40,8 +40,8 @@ class DownloadUIModel { ...@@ -40,8 +40,8 @@ class DownloadUIModel {
virtual ~Observer() {} virtual ~Observer() {}
}; };
void AddObserver(Observer* observer); virtual void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); virtual void RemoveObserver(Observer* observer);
// Returns the content id associated with this download. // Returns the content id associated with this download.
virtual ContentId GetContentId() const; virtual ContentId GetContentId() const;
......
...@@ -5,38 +5,21 @@ ...@@ -5,38 +5,21 @@
#include "chrome/browser/download/offline_item_model.h" #include "chrome/browser/download/offline_item_model.h"
#include "chrome/browser/download/offline_item_model_manager.h" #include "chrome/browser/download/offline_item_model_manager.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
#include "components/offline_items_collection/core/offline_content_aggregator.h"
using offline_items_collection::ContentId; OfflineItemModel::OfflineItemModel(
using offline_items_collection::OfflineItem; OfflineItemModelManager* manager,
const offline_items_collection::OfflineItem& offline_item)
: manager_(manager), offline_item_(offline_item) {}
OfflineItemModel::OfflineItemModel(OfflineItemModelManager* manager, OfflineItemModel::~OfflineItemModel() = default;
const OfflineItem& offline_item)
: manager_(manager),
offline_item_(std::make_unique<OfflineItem>(offline_item)) {
offline_items_collection::OfflineContentAggregator* aggregator =
OfflineContentAggregatorFactory::GetForBrowserContext(
manager_->browser_context());
offline_item_observer_ =
std::make_unique<FilteredOfflineItemObserver>(aggregator);
offline_item_observer_->AddObserver(offline_item_->id, this);
}
OfflineItemModel::~OfflineItemModel() {
if (offline_item_)
offline_item_observer_->RemoveObserver(offline_item_->id, this);
}
int64_t OfflineItemModel::GetCompletedBytes() const { int64_t OfflineItemModel::GetCompletedBytes() const {
return offline_item_ ? offline_item_->received_bytes : 0; return offline_item_.received_bytes;
} }
int64_t OfflineItemModel::GetTotalBytes() const { int64_t OfflineItemModel::GetTotalBytes() const {
if (!offline_item_) return offline_item_.total_size_bytes > 0 ? offline_item_.total_size_bytes
return 0; : 0;
return offline_item_->total_size_bytes > 0 ? offline_item_->total_size_bytes
: 0;
} }
int OfflineItemModel::PercentComplete() const { int OfflineItemModel::PercentComplete() const {
...@@ -48,24 +31,12 @@ int OfflineItemModel::PercentComplete() const { ...@@ -48,24 +31,12 @@ int OfflineItemModel::PercentComplete() const {
bool OfflineItemModel::WasUINotified() const { bool OfflineItemModel::WasUINotified() const {
const OfflineItemModelData* data = const OfflineItemModelData* data =
manager_->GetOrCreateOfflineItemModelData(offline_item_->id); manager_->GetOrCreateOfflineItemModelData(offline_item_.id);
return data->was_ui_notified_; return data->was_ui_notified_;
} }
void OfflineItemModel::SetWasUINotified(bool was_ui_notified) { void OfflineItemModel::SetWasUINotified(bool was_ui_notified) {
OfflineItemModelData* data = OfflineItemModelData* data =
manager_->GetOrCreateOfflineItemModelData(offline_item_->id); manager_->GetOrCreateOfflineItemModelData(offline_item_.id);
data->was_ui_notified_ = was_ui_notified; data->was_ui_notified_ = was_ui_notified;
} }
void OfflineItemModel::OnItemRemoved(const ContentId& id) {
for (auto& obs : observers_)
obs.OnDownloadDestroyed();
offline_item_.reset();
}
void OfflineItemModel::OnItemUpdated(const OfflineItem& item) {
offline_item_ = std::make_unique<OfflineItem>(item);
for (auto& obs : observers_)
obs.OnDownloadUpdated();
}
...@@ -5,19 +5,13 @@ ...@@ -5,19 +5,13 @@
#ifndef CHROME_BROWSER_DOWNLOAD_OFFLINE_ITEM_MODEL_H_ #ifndef CHROME_BROWSER_DOWNLOAD_OFFLINE_ITEM_MODEL_H_
#define CHROME_BROWSER_DOWNLOAD_OFFLINE_ITEM_MODEL_H_ #define CHROME_BROWSER_DOWNLOAD_OFFLINE_ITEM_MODEL_H_
#include <memory>
#include "chrome/browser/download/download_ui_model.h" #include "chrome/browser/download/download_ui_model.h"
#include "components/offline_items_collection/core/filtered_offline_item_observer.h"
#include "components/offline_items_collection/core/offline_item.h" #include "components/offline_items_collection/core/offline_item.h"
class OfflineItemModelManager; class OfflineItemModelManager;
using offline_items_collection::FilteredOfflineItemObserver;
// Implementation of DownloadUIModel that wrappers around a |OfflineItem|. // Implementation of DownloadUIModel that wrappers around a |OfflineItem|.
class OfflineItemModel : public DownloadUIModel, class OfflineItemModel : public DownloadUIModel {
public FilteredOfflineItemObserver::Observer {
public: public:
// Constructs a OfflineItemModel. // Constructs a OfflineItemModel.
OfflineItemModel(OfflineItemModelManager* manager, OfflineItemModel(OfflineItemModelManager* manager,
...@@ -32,15 +26,9 @@ class OfflineItemModel : public DownloadUIModel, ...@@ -32,15 +26,9 @@ class OfflineItemModel : public DownloadUIModel,
void SetWasUINotified(bool should_notify) override; void SetWasUINotified(bool should_notify) override;
private: private:
// FilteredOfflineItemObserver::Observer overrides.
void OnItemRemoved(const offline_items_collection::ContentId& id) override;
void OnItemUpdated(
const offline_items_collection::OfflineItem& item) override;
OfflineItemModelManager* manager_; OfflineItemModelManager* manager_;
std::unique_ptr<FilteredOfflineItemObserver> offline_item_observer_; offline_items_collection::OfflineItem offline_item_;
std::unique_ptr<offline_items_collection::OfflineItem> offline_item_;
DISALLOW_COPY_AND_ASSIGN(OfflineItemModel); DISALLOW_COPY_AND_ASSIGN(OfflineItemModel);
}; };
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
#include "chrome/browser/download/offline_item_model_manager.h" #include "chrome/browser/download/offline_item_model_manager.h"
OfflineItemModelManager::OfflineItemModelManager( OfflineItemModelManager::OfflineItemModelManager() = default;
content::BrowserContext* browser_context)
: browser_context_(browser_context) {}
OfflineItemModelManager::~OfflineItemModelManager() = default; OfflineItemModelManager::~OfflineItemModelManager() = default;
......
...@@ -11,17 +11,13 @@ ...@@ -11,17 +11,13 @@
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/offline_items_collection/core/offline_item.h" #include "components/offline_items_collection/core/offline_item.h"
namespace content {
class BrowserContext;
} // namespace content
using ContentId = offline_items_collection::ContentId; using ContentId = offline_items_collection::ContentId;
// Class for managing all the OfflineModels for a profile. // Class for managing all the OfflineModels for a profile.
class OfflineItemModelManager : public KeyedService { class OfflineItemModelManager : public KeyedService {
public: public:
// Constructs a OfflineItemModelManager. // Constructs a OfflineItemModelManager.
explicit OfflineItemModelManager(content::BrowserContext* browser_context); OfflineItemModelManager();
~OfflineItemModelManager() override; ~OfflineItemModelManager() override;
// Returns the OfflineItemModel for the ContentId, if not found, an empty // Returns the OfflineItemModel for the ContentId, if not found, an empty
...@@ -30,10 +26,7 @@ class OfflineItemModelManager : public KeyedService { ...@@ -30,10 +26,7 @@ class OfflineItemModelManager : public KeyedService {
void RemoveOfflineItemModelData(const ContentId& id); void RemoveOfflineItemModelData(const ContentId& id);
content::BrowserContext* browser_context() { return browser_context_; }
private: private:
content::BrowserContext* browser_context_;
std::map<ContentId, std::unique_ptr<OfflineItemModelData>> std::map<ContentId, std::unique_ptr<OfflineItemModelData>>
offline_item_model_data_; offline_item_model_data_;
......
...@@ -30,5 +30,5 @@ OfflineItemModelManagerFactory::~OfflineItemModelManagerFactory() = default; ...@@ -30,5 +30,5 @@ OfflineItemModelManagerFactory::~OfflineItemModelManagerFactory() = default;
KeyedService* OfflineItemModelManagerFactory::BuildServiceInstanceFor( KeyedService* OfflineItemModelManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new OfflineItemModelManager(context); return new OfflineItemModelManager();
} }
...@@ -179,7 +179,6 @@ DownloadItemView::DownloadItemView(std::unique_ptr<DownloadUIModel> download, ...@@ -179,7 +179,6 @@ DownloadItemView::DownloadItemView(std::unique_ptr<DownloadUIModel> download,
DownloadItemView::~DownloadItemView() { DownloadItemView::~DownloadItemView() {
StopDownloadProgress(); StopDownloadProgress();
model_->RemoveObserver(this); model_->RemoveObserver(this);
base::ThreadTaskRunnerHandle ::Get()->DeleteSoon(FROM_HERE, model_.release());
} }
// Progress animation handlers. // Progress animation handlers.
......
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