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

Side by Side Diff: content/browser/background_fetch/background_fetch_data_manager.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_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/public/browser/blob_handle.h" 11 #include "content/public/browser/blob_handle.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/download_interrupt_reasons.h" 13 #include "content/public/browser/download_interrupt_reasons.h"
14 #include "content/public/browser/download_item.h" 14 #include "content/public/browser/download_item.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 BackgroundFetchDataManager::BackgroundFetchDataManager( 18 BackgroundFetchDataManager::BackgroundFetchDataManager(
19 BrowserContext* browser_context) 19 BrowserContext* browser_context)
20 : browser_context_(browser_context), weak_ptr_factory_(this) { 20 : browser_context_(browser_context), weak_ptr_factory_(this) {
21 DCHECK(browser_context_); 21 DCHECK(browser_context_);
22 // TODO(harkness) Read from persistent storage and recreate requests. 22 // TODO(harkness) Read from persistent storage and recreate requests.
23 } 23 }
24 24
25 BackgroundFetchDataManager::~BackgroundFetchDataManager() = default; 25 BackgroundFetchDataManager::~BackgroundFetchDataManager() = default;
26 26
27 void BackgroundFetchDataManager::CreateRequest( 27 void BackgroundFetchDataManager::CreateRegistration(
28 std::unique_ptr<BackgroundFetchJobInfo> job_info, 28 const BackgroundFetchRegistrationId& registration_id,
29 BackgroundFetchRequestInfos request_infos) { 29 const std::vector<ServiceWorkerFetchRequest>& requests,
30 BackgroundFetchRegistrationId registration_id( 30 const BackgroundFetchOptions& options,
31 job_info->service_worker_registration_id(), job_info->origin(), 31 CreateRegistrationCallback callback) {
32 job_info->tag()); 32 if (registrations_.find(registration_id) != registrations_.end()) {
33 33 std::move(callback).Run(blink::mojom::BackgroundFetchError::DUPLICATED_TAG);
34 // Ensure that this is not a duplicate request.
35 if (known_registrations_.find(registration_id) !=
36 known_registrations_.end()) {
37 DVLOG(1) << "Origin " << job_info->origin()
38 << " has already created a batch request with tag "
39 << job_info->tag();
40 // TODO(harkness) Figure out how to return errors like this.
41 return; 34 return;
42 } 35 }
43 36
44 // Add the JobInfo to the in-memory map, and write the individual requests out 37 registrations_.insert(registration_id);
45 // to storage. 38
harkness 2017/03/27 15:35:12 Can you put a TODO here for one of us to put the r
Peter Beverloo 2017/03/27 15:42:55 Done.
46 job_info->set_num_requests(request_infos.size()); 39 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE);
47 const std::string job_guid = job_info->guid(); 40 }
48 known_registrations_.insert(std::move(registration_id)); 41
49 WriteJobToStorage(std::move(job_info), std::move(request_infos)); 42 void BackgroundFetchDataManager::DeleteRegistration(
43 const BackgroundFetchRegistrationId& registration_id,
44 DeleteRegistrationCallback callback) {
45 auto iter = registrations_.find(registration_id);
46 if (iter == registrations_.end()) {
47 std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_TAG);
48 return;
49 }
50
51 registrations_.erase(iter);
52
53 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE);
50 } 54 }
51 55
52 void BackgroundFetchDataManager::WriteJobToStorage( 56 void BackgroundFetchDataManager::WriteJobToStorage(
53 std::unique_ptr<BackgroundFetchJobInfo> job_info, 57 std::unique_ptr<BackgroundFetchJobInfo> job_info,
54 BackgroundFetchRequestInfos request_infos) { 58 BackgroundFetchRequestInfos request_infos) {
55 // TODO(harkness): Check for job_guid clash. 59 // TODO(harkness): Check for job_guid clash.
56 const std::string job_guid = job_info->guid(); 60 const std::string job_guid = job_info->guid();
57 job_map_[job_guid] = std::move(job_info); 61 job_map_[job_guid] = std::move(job_info);
58 62
59 // Make an explicit copy of the original requests 63 // Make an explicit copy of the original requests
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 const std::string& download_guid) { 222 const std::string& download_guid) {
219 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get(); 223 BackgroundFetchJobInfo* job_info = job_map_[job_guid].get();
220 DCHECK(job_info); 224 DCHECK(job_info);
221 BackgroundFetchRequestInfo* request = 225 BackgroundFetchRequestInfo* request =
222 job_info->GetActiveRequest(request_guid); 226 job_info->GetActiveRequest(request_guid);
223 DCHECK(request); 227 DCHECK(request);
224 request->set_download_guid(download_guid); 228 request->set_download_guid(download_guid);
225 } 229 }
226 230
227 } // namespace content 231 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698