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

Side by Side Diff: content/browser/background_fetch/background_fetch_job_controller.cc

Issue 2774343002: Hook up BackgroundFetchServiceImpl::Fetch() to start a fetch (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/background_fetch/background_fetch_job_controller.h" 5 #include "content/browser/background_fetch/background_fetch_job_controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/guid.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "content/browser/background_fetch/background_fetch_data_manager.h" 12 #include "content/browser/background_fetch/background_fetch_data_manager.h"
12 #include "content/browser/background_fetch/background_fetch_request_info.h" 13 #include "content/browser/background_fetch/background_fetch_request_info.h"
13 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/download_manager.h" 16 #include "content/public/browser/download_manager.h"
16 #include "content/public/browser/storage_partition.h" 17 #include "content/public/browser/storage_partition.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 BackgroundFetchJobController::BackgroundFetchJobController( 21 BackgroundFetchJobController::BackgroundFetchJobController(
21 const std::string& job_guid, 22 const BackgroundFetchRegistrationId& registration_id,
22 BrowserContext* browser_context, 23 BrowserContext* browser_context,
23 StoragePartition* storage_partition, 24 StoragePartition* storage_partition,
24 BackgroundFetchDataManager* data_manager, 25 BackgroundFetchDataManager* data_manager,
25 base::OnceClosure completed_closure) 26 CompletedCallback completed_callback)
26 : job_guid_(job_guid), 27 : registration_id_(registration_id),
28 job_guid_(base::GenerateGUID()),
27 browser_context_(browser_context), 29 browser_context_(browser_context),
28 storage_partition_(storage_partition), 30 storage_partition_(storage_partition),
29 data_manager_(data_manager), 31 data_manager_(data_manager),
30 completed_closure_(std::move(completed_closure)), 32 completed_callback_(std::move(completed_callback)),
31 weak_ptr_factory_(this) {} 33 weak_ptr_factory_(this) {}
32 34
33 BackgroundFetchJobController::~BackgroundFetchJobController() = default; 35 BackgroundFetchJobController::~BackgroundFetchJobController() = default;
34 36
35 void BackgroundFetchJobController::Shutdown() { 37 void BackgroundFetchJobController::Shutdown() {
36 DownloadManager* manager = 38 DownloadManager* manager =
37 BrowserContext::GetDownloadManager(browser_context_); 39 BrowserContext::GetDownloadManager(browser_context_);
38 // For any downloads in progress, remove the observer. 40 // For any downloads in progress, remove the observer.
39 for (auto& guid_map_entry : download_guid_map_) { 41 for (auto& guid_map_entry : download_guid_map_) {
40 DownloadItem* item = manager->GetDownloadByGuid(guid_map_entry.first); 42 DownloadItem* item = manager->GetDownloadByGuid(guid_map_entry.first);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 item->GetReceivedBytes()); 94 item->GetReceivedBytes());
93 // Fall through. 95 // Fall through.
94 case DownloadItem::DownloadState::CANCELLED: 96 case DownloadItem::DownloadState::CANCELLED:
95 // TODO(harkness): Tell the notification service to update the download 97 // TODO(harkness): Tell the notification service to update the download
96 // notification. 98 // notification.
97 99
98 if (requests_remaining) { 100 if (requests_remaining) {
99 ProcessRequest( 101 ProcessRequest(
100 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_)); 102 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_));
101 } else if (data_manager_->IsComplete(job_guid_)) { 103 } else if (data_manager_->IsComplete(job_guid_)) {
102 std::move(completed_closure_).Run(); 104 std::move(completed_callback_).Run(registration_id_);
103 } 105 }
104 break; 106 break;
105 case DownloadItem::DownloadState::INTERRUPTED: 107 case DownloadItem::DownloadState::INTERRUPTED:
106 // TODO(harkness): Just update the notification that it is paused. 108 // TODO(harkness): Just update the notification that it is paused.
107 break; 109 break;
108 case DownloadItem::DownloadState::IN_PROGRESS: 110 case DownloadItem::DownloadState::IN_PROGRESS:
109 // TODO(harkness): If the download was previously paused, this should now 111 // TODO(harkness): If the download was previously paused, this should now
110 // unpause the notification. 112 // unpause the notification.
111 break; 113 break;
112 case DownloadItem::DownloadState::MAX_DOWNLOAD_STATE: 114 case DownloadItem::DownloadState::MAX_DOWNLOAD_STATE:
(...skipping 18 matching lines...) Expand all
131 fetch_request.url(), storage_partition_->GetURLRequestContext())); 133 fetch_request.url(), storage_partition_->GetURLRequestContext()));
132 params->set_callback( 134 params->set_callback(
133 base::Bind(&BackgroundFetchJobController::DownloadStarted, 135 base::Bind(&BackgroundFetchJobController::DownloadStarted,
134 weak_ptr_factory_.GetWeakPtr(), fetch_request.guid())); 136 weak_ptr_factory_.GetWeakPtr(), fetch_request.guid()));
135 137
136 BrowserContext::GetDownloadManager(browser_context_) 138 BrowserContext::GetDownloadManager(browser_context_)
137 ->DownloadUrl(std::move(params)); 139 ->DownloadUrl(std::move(params));
138 } 140 }
139 141
140 } // namespace content 142 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698