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

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

Powered by Google App Engine
This is Rietveld 408576698