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

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

Issue 2777183002: Hook up the other Background Fetch Mojo methods with the system (Closed)
Patch Set: Hook up the other Background Fetch Mojo methods with the system 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/guid.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "content/browser/background_fetch/background_fetch_data_manager.h" 12 #include "content/browser/background_fetch/background_fetch_data_manager.h"
13 #include "content/browser/background_fetch/background_fetch_request_info.h" 13 #include "content/browser/background_fetch/background_fetch_request_info.h"
14 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/download_manager.h" 16 #include "content/public/browser/download_manager.h"
17 #include "content/public/browser/storage_partition.h" 17 #include "content/public/browser/storage_partition.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 BackgroundFetchJobController::BackgroundFetchJobController( 21 BackgroundFetchJobController::BackgroundFetchJobController(
22 const BackgroundFetchRegistrationId& registration_id, 22 const BackgroundFetchRegistrationId& registration_id,
23 const BackgroundFetchOptions& options,
23 BrowserContext* browser_context, 24 BrowserContext* browser_context,
24 StoragePartition* storage_partition, 25 StoragePartition* storage_partition,
25 BackgroundFetchDataManager* data_manager, 26 BackgroundFetchDataManager* data_manager,
26 CompletedCallback completed_callback) 27 CompletedCallback completed_callback)
27 : registration_id_(registration_id), 28 : registration_id_(registration_id),
29 options_(options),
28 job_guid_(base::GenerateGUID()), 30 job_guid_(base::GenerateGUID()),
29 browser_context_(browser_context), 31 browser_context_(browser_context),
30 storage_partition_(storage_partition), 32 storage_partition_(storage_partition),
31 data_manager_(data_manager), 33 data_manager_(data_manager),
32 completed_callback_(std::move(completed_callback)), 34 completed_callback_(std::move(completed_callback)),
33 weak_ptr_factory_(this) {} 35 weak_ptr_factory_(this) {}
34 36
35 BackgroundFetchJobController::~BackgroundFetchJobController() = default; 37 BackgroundFetchJobController::~BackgroundFetchJobController() = default;
36 38
37 void BackgroundFetchJobController::Shutdown() { 39 void BackgroundFetchJobController::Shutdown() {
(...skipping 17 matching lines...) Expand all
55 void BackgroundFetchJobController::StartProcessing() { 57 void BackgroundFetchJobController::StartProcessing() {
56 DCHECK(data_manager_); 58 DCHECK(data_manager_);
57 59
58 const BackgroundFetchRequestInfo& fetch_request = 60 const BackgroundFetchRequestInfo& fetch_request =
59 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_); 61 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_);
60 ProcessRequest(fetch_request); 62 ProcessRequest(fetch_request);
61 63
62 // Currently, this processes a single request at a time. 64 // Currently, this processes a single request at a time.
63 } 65 }
64 66
67 void BackgroundFetchJobController::UpdateUI(const std::string& title) {
68 // TODO(harkness): Update the user interface with |title|.
69 }
70
71 void BackgroundFetchJobController::Abort() {
72 // TODO(harkness): Abort all in-progress downloads.
73
74 std::move(completed_callback_)
75 .Run(registration_id_, true /* aborted_by_developer */);
76 }
77
65 void BackgroundFetchJobController::DownloadStarted( 78 void BackgroundFetchJobController::DownloadStarted(
66 const std::string& request_guid, 79 const std::string& request_guid,
67 DownloadItem* item, 80 DownloadItem* item,
68 DownloadInterruptReason reason) { 81 DownloadInterruptReason reason) {
69 // Start observing the DownloadItem. No need to store the pointer because it 82 // Start observing the DownloadItem. No need to store the pointer because it
70 // can be retrieved from the DownloadManager. 83 // can be retrieved from the DownloadManager.
71 item->AddObserver(this); 84 item->AddObserver(this);
72 download_guid_map_[item->GetGuid()] = request_guid; 85 download_guid_map_[item->GetGuid()] = request_guid;
73 data_manager_->UpdateRequestDownloadGuid(job_guid_, request_guid, 86 data_manager_->UpdateRequestDownloadGuid(job_guid_, request_guid,
74 item->GetGuid()); 87 item->GetGuid());
(...skipping 19 matching lines...) Expand all
94 item->GetReceivedBytes()); 107 item->GetReceivedBytes());
95 // Fall through. 108 // Fall through.
96 case DownloadItem::DownloadState::CANCELLED: 109 case DownloadItem::DownloadState::CANCELLED:
97 // TODO(harkness): Tell the notification service to update the download 110 // TODO(harkness): Tell the notification service to update the download
98 // notification. 111 // notification.
99 112
100 if (requests_remaining) { 113 if (requests_remaining) {
101 ProcessRequest( 114 ProcessRequest(
102 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_)); 115 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_));
103 } else if (data_manager_->IsComplete(job_guid_)) { 116 } else if (data_manager_->IsComplete(job_guid_)) {
104 std::move(completed_callback_).Run(registration_id_); 117 std::move(completed_callback_)
118 .Run(registration_id_, false /* aborted_by_developer */);
105 } 119 }
106 break; 120 break;
107 case DownloadItem::DownloadState::INTERRUPTED: 121 case DownloadItem::DownloadState::INTERRUPTED:
108 // TODO(harkness): Just update the notification that it is paused. 122 // TODO(harkness): Just update the notification that it is paused.
109 break; 123 break;
110 case DownloadItem::DownloadState::IN_PROGRESS: 124 case DownloadItem::DownloadState::IN_PROGRESS:
111 // TODO(harkness): If the download was previously paused, this should now 125 // TODO(harkness): If the download was previously paused, this should now
112 // unpause the notification. 126 // unpause the notification.
113 break; 127 break;
114 case DownloadItem::DownloadState::MAX_DOWNLOAD_STATE: 128 case DownloadItem::DownloadState::MAX_DOWNLOAD_STATE:
(...skipping 18 matching lines...) Expand all
133 fetch_request.GetURL(), storage_partition_->GetURLRequestContext())); 147 fetch_request.GetURL(), storage_partition_->GetURLRequestContext()));
134 params->set_callback( 148 params->set_callback(
135 base::Bind(&BackgroundFetchJobController::DownloadStarted, 149 base::Bind(&BackgroundFetchJobController::DownloadStarted,
136 weak_ptr_factory_.GetWeakPtr(), fetch_request.guid())); 150 weak_ptr_factory_.GetWeakPtr(), fetch_request.guid()));
137 151
138 BrowserContext::GetDownloadManager(browser_context_) 152 BrowserContext::GetDownloadManager(browser_context_)
139 ->DownloadUrl(std::move(params)); 153 ->DownloadUrl(std::move(params));
140 } 154 }
141 155
142 } // namespace content 156 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698