blob: da0fff79694ae89e2c8f62f8f06f85dc8fb0524c [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_OFFLINE_CONTENT_PROVIDER_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_OFFLINE_CONTENT_PROVIDER_H_
#include <memory>
#include <set>
#include "base/macros.h"
#include "components/download/public/common/download_item.h"
#include "components/offline_items_collection/core/offline_content_aggregator.h"
#include "components/offline_items_collection/core/offline_content_provider.h"
#include "content/public/browser/download_manager.h"
using DownloadItem = download::DownloadItem;
using DownloadManager = content::DownloadManager;
using ContentId = offline_items_collection::ContentId;
using OfflineItem = offline_items_collection::OfflineItem;
using OfflineContentProvider = offline_items_collection::OfflineContentProvider;
using OfflineContentAggregator =
offline_items_collection::OfflineContentAggregator;
using LaunchLocation = offline_items_collection::LaunchLocation;
class SkBitmap;
// This class handles the task of observing the downloads associated with a
// single DownloadManager (or in-progress download manager in service manager
// only mode) and notifies UI about updates about various downloads.
class DownloadOfflineContentProvider : public OfflineContentProvider,
public download::DownloadItem::Observer,
public DownloadManager::Observer {
public:
explicit DownloadOfflineContentProvider(OfflineContentAggregator* aggregator,
const std::string& name_space);
~DownloadOfflineContentProvider() override;
// Should be called when a DownloadManager is available.
void SetDownloadManager(DownloadManager* manager);
// OfflineContentProvider implmentation.
void OpenItem(LaunchLocation location, const ContentId& id) override;
void RemoveItem(const ContentId& id) override;
void CancelDownload(const ContentId& id) override;
void PauseDownload(const ContentId& id) override;
void ResumeDownload(const ContentId& id, bool has_user_gesture) override;
void GetItemById(
const ContentId& id,
OfflineContentProvider::SingleItemCallback callback) override;
void GetAllItems(
OfflineContentProvider::MultipleItemCallback callback) override;
void GetVisualsForItem(
const ContentId& id,
OfflineContentProvider::VisualsCallback callback) override;
void GetShareInfoForItem(const ContentId& id,
ShareCallback callback) override;
void RenameItem(const ContentId& id,
const std::string& name,
RenameCallback callback) override;
void AddObserver(OfflineContentProvider::Observer* observer) override;
void RemoveObserver(OfflineContentProvider::Observer* observer) override;
// Entry point for associating this class with a download item. Must be called
// for all new and in-progress downloads, after which this class will start
// observing the given download.
void OnDownloadStarted(DownloadItem* download_item);
private:
// DownloadItem::Observer overrides
void OnDownloadUpdated(DownloadItem* item) override;
void OnDownloadRemoved(DownloadItem* item) override;
// DownloadManager::Observer overrides
void ManagerGoingDown(DownloadManager* manager) override;
void GetAllDownloads(DownloadManager::DownloadVector* all_items);
DownloadItem* GetDownload(const std::string& download_guid);
void OnThumbnailRetrieved(const ContentId& id,
VisualsCallback callback,
const SkBitmap& bitmap);
void AddCompletedDownload(DownloadItem* item);
void AddCompletedDownloadDone(DownloadItem* item,
int64_t system_download_id,
bool can_resolve);
void UpdateObservers(DownloadItem* item);
base::ObserverList<OfflineContentProvider::Observer>::Unchecked observers_;
OfflineContentAggregator* aggregator_;
std::string name_space_;
DownloadManager* manager_;
std::set<std::string> completed_downloads_;
base::WeakPtrFactory<DownloadOfflineContentProvider> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DownloadOfflineContentProvider);
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_OFFLINE_CONTENT_PROVIDER_H_