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

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

Issue 2763613004: Use std::unique_ptr for access to BackgroundFetchJobInfo (Closed)
Patch Set: Missed one 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_context.h" 5 #include "content/browser/background_fetch/background_fetch_context.h"
6 6
7 #include "content/browser/background_fetch/background_fetch_job_info.h" 7 #include "content/browser/background_fetch/background_fetch_job_info.h"
8 #include "content/browser/background_fetch/background_fetch_request_info.h" 8 #include "content/browser/background_fetch/background_fetch_request_info.h"
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" 9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // Call Shutdown on all pending job controllers to give them a chance to flush 49 // Call Shutdown on all pending job controllers to give them a chance to flush
50 // any status to the DataManager. 50 // any status to the DataManager.
51 for (auto& job : job_map_) 51 for (auto& job : job_map_)
52 job.second->Shutdown(); 52 job.second->Shutdown();
53 53
54 job_map_.clear(); 54 job_map_.clear();
55 } 55 }
56 56
57 void BackgroundFetchContext::CreateRequest( 57 void BackgroundFetchContext::CreateRequest(
58 const BackgroundFetchJobInfo& job_info, 58 std::unique_ptr<BackgroundFetchJobInfo> job_info,
59 std::vector<BackgroundFetchRequestInfo>& request_infos) { 59 std::vector<BackgroundFetchRequestInfo>& request_infos) {
60 DCHECK_CURRENTLY_ON(BrowserThread::IO); 60 DCHECK_CURRENTLY_ON(BrowserThread::IO);
61 DCHECK_GE(1U, request_infos.size()); 61 DCHECK_GE(1U, request_infos.size());
62 62
63 // Inform the data manager about the new download. 63 // Inform the data manager about the new download.
64 const std::string job_guid = job_info->guid();
64 std::unique_ptr<BackgroundFetchJobData> job_data = 65 std::unique_ptr<BackgroundFetchJobData> job_data =
65 background_fetch_data_manager_.CreateRequest(job_info, request_infos); 66 background_fetch_data_manager_.CreateRequest(std::move(job_info),
67 request_infos);
66 68
67 // If job_data is null, the DataManager will have logged an error. 69 // If job_data is null, the DataManager will have logged an error.
68 if (job_data) { 70 if (job_data) {
69 // Create a controller which drives the processing of the job. It will use 71 // Create a controller which drives the processing of the job. It will use
70 // the JobData to get information about individual requests for the job. 72 // the JobData to get information about individual requests for the job.
71 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>( 73 job_map_[job_guid] = base::MakeUnique<BackgroundFetchJobController>(
72 job_info.guid(), browser_context_, storage_partition_, 74 job_guid, browser_context_, storage_partition_, std::move(job_data),
73 std::move(job_data),
74 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this, 75 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this,
75 job_info.guid())); 76 job_guid));
76 } 77 }
77 } 78 }
78 79
79 void BackgroundFetchContext::DidCompleteJob(const std::string& job_guid) { 80 void BackgroundFetchContext::DidCompleteJob(const std::string& job_guid) {
80 DCHECK(job_map_.find(job_guid) != job_map_.end()); 81 DCHECK(job_map_.find(job_guid) != job_map_.end());
81 82
82 job_map_.erase(job_guid); 83 job_map_.erase(job_guid);
83 84
84 // TODO(harkness): Once the caller receives the message, inform the 85 // TODO(harkness): Once the caller receives the message, inform the
85 // DataManager that it can clean up the pending job. 86 // DataManager that it can clean up the pending job.
86 } 87 }
87 88
88 } // namespace content 89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698