Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Unified Diff: content/browser/background_fetch/background_fetch_job_controller.h

Issue 2782553007: Implement the new polling system in the BackgroundFetchJobController (Closed)
Patch Set: Implement the new polling system in the BFJobController Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/background_fetch/background_fetch_job_controller.h
diff --git a/content/browser/background_fetch/background_fetch_job_controller.h b/content/browser/background_fetch/background_fetch_job_controller.h
index eac97eff46b74f0a2de7a7463b1ba2169c1741b6..94c6426112172452c249a2bbd7189d17b2415db3 100644
--- a/content/browser/background_fetch/background_fetch_job_controller.h
+++ b/content/browser/background_fetch/background_fetch_job_controller.h
@@ -12,7 +12,9 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "base/optional.h"
#include "content/browser/background_fetch/background_fetch_registration_id.h"
+#include "content/browser/background_fetch/background_fetch_request_info.h"
#include "content/common/background_fetch/background_fetch_types.h"
#include "content/common/content_export.h"
#include "content/public/browser/download_item.h"
@@ -20,7 +22,6 @@
namespace content {
class BackgroundFetchDataManager;
-class BackgroundFetchRequestInfo;
class BrowserContext;
class StoragePartition;
@@ -44,9 +45,9 @@ class CONTENT_EXPORT BackgroundFetchJobController
CompletedCallback completed_callback);
~BackgroundFetchJobController() override;
- // Start processing on a batch of requests. Some of these may already be in
- // progress or completed from a previous chromium instance.
- void StartProcessing();
+ // Starts fetching the |initial_fetches|. The controller will continue to
+ // fetch new content until all requests have been handled.
+ void Start(std::vector<BackgroundFetchRequestInfo> initial_requests);
// Updates the representation of this Background Fetch in the user interface
// to match the given |title|.
@@ -55,9 +56,6 @@ class CONTENT_EXPORT BackgroundFetchJobController
// Immediately aborts this Background Fetch by request of the developer.
void Abort();
- // Called by the BackgroundFetchContext when the system is shutting down.
- void Shutdown();
-
// Returns the current state of this Job Controller.
State state() const { return state_; }
@@ -69,18 +67,25 @@ class CONTENT_EXPORT BackgroundFetchJobController
// Returns the options with which this job is fetching data.
const BackgroundFetchOptions& options() const { return options_; }
- private:
// DownloadItem::Observer methods.
void OnDownloadUpdated(DownloadItem* item) override;
void OnDownloadDestroyed(DownloadItem* item) override;
- // Callback passed to the DownloadManager which will be invoked once the
- // download starts.
- void DownloadStarted(const std::string& request_guid,
- DownloadItem* item,
- DownloadInterruptReason reason);
+ private:
+ // Requests the download manager to start fetching |request|.
+ void StartRequest(const BackgroundFetchRequestInfo& request);
+
+ // Called when the request identified by |request_index| has been started.
+ // The |download_item| continues to be owned by the download system. The
+ // |interrupt_reason| will indicate when a request could not be started.
+ void DidStartRequest(const BackgroundFetchRequestInfo& request,
+ DownloadItem* download_item,
+ DownloadInterruptReason interrupt_reason);
- void ProcessRequest(const BackgroundFetchRequestInfo& request);
+ // Called when a completed download has been marked as such in the DataManager
+ // and the next request, if any, has been read from storage.
+ void DidGetNextRequest(
+ const base::Optional<BackgroundFetchRequestInfo>& request);
// The registration id on behalf of which this controller is fetching data.
BackgroundFetchRegistrationId registration_id_;
@@ -91,13 +96,14 @@ class CONTENT_EXPORT BackgroundFetchJobController
// The current state of this Job Controller.
State state_ = State::INITIALIZED;
- // TODO(peter): Deprecated, remove in favor of |registration_id|.
- std::string job_guid_;
+ // Map from DownloadItem* to the request info for the in-progress downloads.
+ std::unordered_map<DownloadItem*, BackgroundFetchRequestInfo> downloads_;
+
+ // Number of outstanding acknowledgements we expect to get from the
+ // DataManager about
+ int pending_completed_file_acknowledgements_ = 0;
- // Pointer to the browser context. The BackgroundFetchJobController is owned
- // by the BrowserContext via the StoragePartition.
- // TODO(harkness): Currently this is only used to lookup the DownloadManager.
- // Investigate whether the DownloadManager should be passed instead.
+ // The BrowserContext that indirectly owns us.
BrowserContext* browser_context_;
// Pointer to the storage partition. This object is owned by the partition
@@ -111,9 +117,6 @@ class CONTENT_EXPORT BackgroundFetchJobController
// Callback for when all fetches have been completed.
CompletedCallback completed_callback_;
- // Map from the GUID assigned by the DownloadManager to the request_guid.
- std::unordered_map<std::string, std::string> download_guid_map_;
-
base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);

Powered by Google App Engine
This is Rietveld 408576698