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

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

Issue 2724783002: Make the BackgroundFetchJobController a per-job object (Closed)
Patch Set: ACTUALLY fix the compile error Created 3 years, 9 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_info.h"
10 #include "content/browser/background_fetch/background_fetch_request_info.h" 9 #include "content/browser/background_fetch/background_fetch_request_info.h"
11 10
12 namespace content { 11 namespace content {
13 12
14 BackgroundFetchDataManager::BackgroundFetchDataManager( 13 BackgroundFetchDataManager::BackgroundFetchDataManager(
15 BackgroundFetchContext* background_fetch_context) 14 BackgroundFetchContext* background_fetch_context)
16 : background_fetch_context_(background_fetch_context) { 15 : background_fetch_context_(background_fetch_context) {
17 DCHECK(background_fetch_context_); 16 DCHECK(background_fetch_context_);
18 // TODO(harkness) Read from persistent storage and recreate requests. 17 // TODO(harkness) Read from persistent storage and recreate requests.
19 } 18 }
20 19
21 BackgroundFetchDataManager::~BackgroundFetchDataManager() = default; 20 BackgroundFetchDataManager::~BackgroundFetchDataManager() = default;
22 21
23 BackgroundFetchJobData* BackgroundFetchDataManager::CreateRequest( 22 std::unique_ptr<BackgroundFetchJobData>
23 BackgroundFetchDataManager::CreateRequest(
24 const BackgroundFetchJobInfo& job_info, 24 const BackgroundFetchJobInfo& job_info,
25 BackgroundFetchRequestInfos request_infos) { 25 BackgroundFetchRequestInfos request_infos) {
26 JobIdentifier id(job_info.service_worker_registration_id(), job_info.tag()); 26 JobIdentifier id(job_info.service_worker_registration_id(), job_info.tag());
27 // Ensure that this is not a duplicate request. 27 // Ensure that this is not a duplicate request.
28 if (service_worker_tag_map_.find(id) != service_worker_tag_map_.end()) { 28 if (service_worker_tag_map_.find(id) != service_worker_tag_map_.end()) {
29 DVLOG(1) << "Origin " << job_info.origin() 29 DVLOG(1) << "Origin " << job_info.origin()
30 << " has already created a batch request with tag " 30 << " has already created a batch request with tag "
31 << job_info.tag(); 31 << job_info.tag();
32 // TODO(harkness) Figure out how to return errors like this. 32 // TODO(harkness) Figure out how to return errors like this.
33 return nullptr; 33 return nullptr;
34 } 34 }
35 if (batch_map_.find(job_info.guid()) != batch_map_.end()) {
36 DVLOG(1) << "Job with UID " << job_info.guid() << " already exists.";
37 // TODO(harkness) Figure out how to return errors like this.
38 return nullptr;
39 }
40 35
41 // Add the request to our maps and return a JobData to track the individual 36 // Add the request to our maps and return a JobData to track the individual
42 // files in the request. 37 // files in the request.
43 service_worker_tag_map_[id] = job_info.guid(); 38 service_worker_tag_map_[id] = job_info.guid();
44 // TODO(harkness): When a job is complete, remove the JobData from the map. 39 WriteJobToStorage(job_info, std::move(request_infos));
45 batch_map_[job_info.guid()] = 40 // TODO(harkness): Remove data when the job is complete.
46 base::MakeUnique<BackgroundFetchJobData>(std::move(request_infos)); 41
47 return batch_map_[job_info.guid()].get(); 42 return base::MakeUnique<BackgroundFetchJobData>(
43 ReadRequestsFromStorage(job_info.guid()));
44 }
45
46 void BackgroundFetchDataManager::WriteJobToStorage(
47 const BackgroundFetchJobInfo& job_info,
48 BackgroundFetchRequestInfos request_infos) {
49 // TODO(harkness): Replace these maps with actually writing to storage.
50 // TODO(harkness): Check for job_guid clash.
51 job_map_[job_info.guid()] = job_info;
52 request_map_[job_info.guid()] = std::move(request_infos);
53 }
54
55 // TODO(harkness): This should be changed to read (and cache) small numbers of
56 // the RequestInfos instead of returning all of them.
57 BackgroundFetchRequestInfos&
58 BackgroundFetchDataManager::ReadRequestsFromStorage(
59 const std::string& job_guid) {
60 return request_map_[job_guid];
48 } 61 }
49 62
50 } // namespace content 63 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698