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

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

Issue 2774263003: Added ServiceWorkerResponses to GetJobResponse callback (Closed)
Patch Set: Move PostTask to correct thread 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_data_manager.h" 5 #include "content/browser/background_fetch/background_fetch_data_manager.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/browser/background_fetch/background_fetch_context.h" 8 #include "content/browser/background_fetch/background_fetch_context.h"
9 #include "content/browser/background_fetch/background_fetch_job_response_data.h" 9 #include "content/browser/background_fetch/background_fetch_job_response_data.h"
10 #include "content/browser/background_fetch/background_fetch_request_info.h" 10 #include "content/browser/background_fetch/background_fetch_request_info.h"
11 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
11 #include "content/public/browser/blob_handle.h" 12 #include "content/public/browser/blob_handle.h"
12 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/download_interrupt_reasons.h" 14 #include "content/public/browser/download_interrupt_reasons.h"
14 #include "content/public/browser/download_item.h" 15 #include "content/public/browser/download_item.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 BackgroundFetchDataManager::BackgroundFetchDataManager( 19 BackgroundFetchDataManager::BackgroundFetchDataManager(
19 BrowserContext* browser_context) 20 BrowserContext* browser_context)
20 : browser_context_(browser_context), weak_ptr_factory_(this) { 21 : browser_context_(browser_context), weak_ptr_factory_(this) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 const std::vector<BackgroundFetchRequestInfo>& request_infos = iter->second; 91 const std::vector<BackgroundFetchRequestInfo>& request_infos = iter->second;
91 92
92 DCHECK(request_index <= request_infos.size()); 93 DCHECK(request_index <= request_infos.size());
93 return base::MakeUnique<BackgroundFetchRequestInfo>( 94 return base::MakeUnique<BackgroundFetchRequestInfo>(
94 request_infos[request_index]); 95 request_infos[request_index]);
95 } 96 }
96 97
97 void BackgroundFetchDataManager::GetJobResponse( 98 void BackgroundFetchDataManager::GetJobResponse(
98 const std::string& job_guid, 99 const std::string& job_guid,
99 const BackgroundFetchResponseCompleteCallback& callback) { 100 const BackgroundFetchResponseCompleteCallback& callback) {
101 BrowserThread::PostTaskAndReplyWithResult(
102 BrowserThread::UI, FROM_HERE,
103 base::Bind(&ChromeBlobStorageContext::GetFor, browser_context_),
104 base::Bind(&BackgroundFetchDataManager::DidGetBlobStorageContext,
105 weak_ptr_factory_.GetWeakPtr(), job_guid, callback));
106 }
107
108 void BackgroundFetchDataManager::DidGetBlobStorageContext(
109 const std::string& job_guid,
110 const BackgroundFetchResponseCompleteCallback& callback,
111 ChromeBlobStorageContext* blob_context) {
112 DCHECK(blob_context);
100 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get(); 113 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get();
101 DCHECK(job_info); 114 DCHECK(job_info);
102 115
103 // Create a BackgroundFetchJobResponseData object which will aggregate 116 // Create a BackgroundFetchJobResponseData object which will aggregate
104 // together the response blobs. 117 // together the response blobs.
105 job_info->set_job_response_data( 118 job_info->set_job_response_data(
106 base::MakeUnique<BackgroundFetchJobResponseData>(job_info->num_requests(), 119 base::MakeUnique<BackgroundFetchJobResponseData>(job_info->num_requests(),
107 callback)); 120 callback));
121 BackgroundFetchJobResponseData* job_response_data =
122 job_info->job_response_data();
123 DCHECK(job_response_data);
108 124
109 // Iterate over the requests and create blobs for each response. 125 // Iterate over the requests and create blobs for each response.
110 for (size_t request_index = 0; request_index < job_info->num_requests(); 126 for (size_t request_index = 0; request_index < job_info->num_requests();
111 request_index++) { 127 request_index++) {
112 // TODO(harkness): This will need to be asynchronous. 128 // TODO(harkness): This will need to be asynchronous.
113 std::unique_ptr<BackgroundFetchRequestInfo> request_info = 129 std::unique_ptr<BackgroundFetchRequestInfo> request_info =
114 GetRequestInfo(job_guid, request_index); 130 GetRequestInfo(job_guid, request_index);
115 131
116 // TODO(harkness): Only create a blob response if the request was 132 // TODO(harkness): Only create a blob response if the request was
117 // successful. Otherwise create an error response. 133 // successful. Otherwise create an error response.
118 content::BrowserContext::CreateFileBackedBlob( 134 std::unique_ptr<BlobHandle> blob_handle =
119 browser_context_, request_info->file_path(), 0 /* offset */, 135 blob_context->CreateFileBackedBlob(
120 request_info->received_bytes(), 136 request_info->file_path(), 0 /* offset */,
121 base::Time() /* expected_modification_time */, 137 request_info->received_bytes(),
122 base::Bind(&BackgroundFetchDataManager::DidGetRequestResponse, 138 base::Time() /* expected_modification_time */);
123 weak_ptr_factory_.GetWeakPtr(), job_guid, request_index)); 139
140 job_response_data->AddResponse(*request_info.get(), std::move(blob_handle));
124 } 141 }
125 } 142 }
126 143
127 void BackgroundFetchDataManager::DidGetRequestResponse(
128 const std::string& job_guid,
129 int request_sequence_number,
130 std::unique_ptr<BlobHandle> blob_handle) {
131 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get();
132 DCHECK(job_info);
133
134 BackgroundFetchJobResponseData* job_response_data =
135 job_info->job_response_data();
136 DCHECK(job_response_data);
137
138 job_response_data->AddResponse(request_sequence_number,
139 std::move(blob_handle));
140 }
141
142 bool BackgroundFetchDataManager::UpdateRequestState( 144 bool BackgroundFetchDataManager::UpdateRequestState(
143 const std::string& job_guid, 145 const std::string& job_guid,
144 const std::string& request_guid, 146 const std::string& request_guid,
145 DownloadItem::DownloadState state, 147 DownloadItem::DownloadState state,
146 DownloadInterruptReason interrupt_reason) { 148 DownloadInterruptReason interrupt_reason) {
147 // Find the request and set the state and the interrupt reason. 149 // Find the request and set the state and the interrupt reason.
148 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get(); 150 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get();
149 DCHECK(job_info); 151 DCHECK(job_info);
150 BackgroundFetchRequestInfo* request = 152 BackgroundFetchRequestInfo* request =
151 job_info->GetActiveRequest(request_guid); 153 job_info->GetActiveRequest(request_guid);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 const std::string& download_guid) { 220 const std::string& download_guid) {
219 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get(); 221 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get();
220 DCHECK(job_info); 222 DCHECK(job_info);
221 BackgroundFetchRequestInfo* request = 223 BackgroundFetchRequestInfo* request =
222 job_info->GetActiveRequest(request_guid); 224 job_info->GetActiveRequest(request_guid);
223 DCHECK(request); 225 DCHECK(request);
224 request->set_download_guid(download_guid); 226 request->set_download_guid(download_guid);
225 } 227 }
226 228
227 } // namespace content 229 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698