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

Side by Side Diff: components/update_client/background_downloader_win.cc

Issue 2870263002: Rename ScopedComPtr::Receive to ScopedComPtr::GetAddressOf (Closed)
Patch Set: Rebase to 2a6f440 Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/update_client/background_downloader_win.h" 5 #include "components/update_client/background_downloader_win.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 #include <objbase.h> 9 #include <objbase.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 bool is_valid = HIWORD(error) == 0x8019 && 162 bool is_valid = HIWORD(error) == 0x8019 &&
163 LOWORD(error) >= kHttpStatusFirst && 163 LOWORD(error) >= kHttpStatusFirst &&
164 LOWORD(error) <= kHttpStatusLast; 164 LOWORD(error) <= kHttpStatusLast;
165 return is_valid ? LOWORD(error) : 0; 165 return is_valid ? LOWORD(error) : 0;
166 } 166 }
167 167
168 // Returns the files in a BITS job. 168 // Returns the files in a BITS job.
169 HRESULT GetFilesInJob(IBackgroundCopyJob* job, 169 HRESULT GetFilesInJob(IBackgroundCopyJob* job,
170 std::vector<ScopedComPtr<IBackgroundCopyFile>>* files) { 170 std::vector<ScopedComPtr<IBackgroundCopyFile>>* files) {
171 ScopedComPtr<IEnumBackgroundCopyFiles> enum_files; 171 ScopedComPtr<IEnumBackgroundCopyFiles> enum_files;
172 HRESULT hr = job->EnumFiles(enum_files.Receive()); 172 HRESULT hr = job->EnumFiles(enum_files.GetAddressOf());
173 if (FAILED(hr)) 173 if (FAILED(hr))
174 return hr; 174 return hr;
175 175
176 ULONG num_files = 0; 176 ULONG num_files = 0;
177 hr = enum_files->GetCount(&num_files); 177 hr = enum_files->GetCount(&num_files);
178 if (FAILED(hr)) 178 if (FAILED(hr))
179 return hr; 179 return hr;
180 180
181 for (ULONG i = 0; i != num_files; ++i) { 181 for (ULONG i = 0; i != num_files; ++i) {
182 ScopedComPtr<IBackgroundCopyFile> file; 182 ScopedComPtr<IBackgroundCopyFile> file;
183 if (enum_files->Next(1, file.Receive(), NULL) == S_OK && file.Get()) 183 if (enum_files->Next(1, file.GetAddressOf(), NULL) == S_OK && file.Get())
184 files->push_back(file); 184 files->push_back(file);
185 } 185 }
186 186
187 return S_OK; 187 return S_OK;
188 } 188 }
189 189
190 // Returns the file name, the url, and some per-file progress information. 190 // Returns the file name, the url, and some per-file progress information.
191 // The function out parameters can be NULL if that data is not requested. 191 // The function out parameters can be NULL if that data is not requested.
192 HRESULT GetJobFileProperties(IBackgroundCopyFile* file, 192 HRESULT GetJobFileProperties(IBackgroundCopyFile* file,
193 base::string16* local_name, 193 base::string16* local_name,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 ScopedCoMem<base::char16> description; 258 ScopedCoMem<base::char16> description;
259 return job->GetDescription(&description); 259 return job->GetDescription(&description);
260 } 260 }
261 261
262 // Returns the job error code in |error_code| if the job is in the transient 262 // Returns the job error code in |error_code| if the job is in the transient
263 // or the final error state. Otherwise, the job error is not available and 263 // or the final error state. Otherwise, the job error is not available and
264 // the function fails. 264 // the function fails.
265 HRESULT GetJobError(IBackgroundCopyJob* job, HRESULT* error_code_out) { 265 HRESULT GetJobError(IBackgroundCopyJob* job, HRESULT* error_code_out) {
266 *error_code_out = S_OK; 266 *error_code_out = S_OK;
267 ScopedComPtr<IBackgroundCopyError> copy_error; 267 ScopedComPtr<IBackgroundCopyError> copy_error;
268 HRESULT hr = job->GetError(copy_error.Receive()); 268 HRESULT hr = job->GetError(copy_error.GetAddressOf());
269 if (FAILED(hr)) 269 if (FAILED(hr))
270 return hr; 270 return hr;
271 271
272 BG_ERROR_CONTEXT error_context = BG_ERROR_CONTEXT_NONE; 272 BG_ERROR_CONTEXT error_context = BG_ERROR_CONTEXT_NONE;
273 HRESULT error_code = S_OK; 273 HRESULT error_code = S_OK;
274 hr = copy_error->GetError(&error_context, &error_code); 274 hr = copy_error->GetError(&error_context, &error_code);
275 if (FAILED(hr)) 275 if (FAILED(hr))
276 return hr; 276 return hr;
277 277
278 *error_code_out = FAILED(error_code) ? error_code : E_FAIL; 278 *error_code_out = FAILED(error_code) ? error_code : E_FAIL;
279 return S_OK; 279 return S_OK;
280 } 280 }
281 281
282 // Finds the component updater jobs matching the given predicate. 282 // Finds the component updater jobs matching the given predicate.
283 // Returns S_OK if the function has found at least one job, returns S_FALSE if 283 // Returns S_OK if the function has found at least one job, returns S_FALSE if
284 // no job was found, and it returns an error otherwise. 284 // no job was found, and it returns an error otherwise.
285 template <class Predicate> 285 template <class Predicate>
286 HRESULT FindBitsJobIf(Predicate pred, 286 HRESULT FindBitsJobIf(Predicate pred,
287 IBackgroundCopyManager* bits_manager, 287 IBackgroundCopyManager* bits_manager,
288 std::vector<ScopedComPtr<IBackgroundCopyJob>>* jobs) { 288 std::vector<ScopedComPtr<IBackgroundCopyJob>>* jobs) {
289 ScopedComPtr<IEnumBackgroundCopyJobs> enum_jobs; 289 ScopedComPtr<IEnumBackgroundCopyJobs> enum_jobs;
290 HRESULT hr = bits_manager->EnumJobs(0, enum_jobs.Receive()); 290 HRESULT hr = bits_manager->EnumJobs(0, enum_jobs.GetAddressOf());
291 if (FAILED(hr)) 291 if (FAILED(hr))
292 return hr; 292 return hr;
293 293
294 ULONG job_count = 0; 294 ULONG job_count = 0;
295 hr = enum_jobs->GetCount(&job_count); 295 hr = enum_jobs->GetCount(&job_count);
296 if (FAILED(hr)) 296 if (FAILED(hr))
297 return hr; 297 return hr;
298 298
299 // Iterate over jobs, run the predicate, and select the job only if 299 // Iterate over jobs, run the predicate, and select the job only if
300 // the job description matches the component updater jobs. 300 // the job description matches the component updater jobs.
301 for (ULONG i = 0; i != job_count; ++i) { 301 for (ULONG i = 0; i != job_count; ++i) {
302 ScopedComPtr<IBackgroundCopyJob> current_job; 302 ScopedComPtr<IBackgroundCopyJob> current_job;
303 if (enum_jobs->Next(1, current_job.Receive(), NULL) == S_OK && 303 if (enum_jobs->Next(1, current_job.GetAddressOf(), NULL) == S_OK &&
304 pred(current_job.Get())) { 304 pred(current_job.Get())) {
305 base::string16 job_description; 305 base::string16 job_description;
306 hr = GetJobDescription(current_job.Get(), &job_description); 306 hr = GetJobDescription(current_job.Get(), &job_description);
307 if (job_description.compare(kJobDescription) == 0) 307 if (job_description.compare(kJobDescription) == 0)
308 jobs->push_back(current_job); 308 jobs->push_back(current_job);
309 } 309 }
310 } 310 }
311 311
312 return jobs->empty() ? S_FALSE : S_OK; 312 return jobs->empty() ? S_FALSE : S_OK;
313 } 313 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 478
479 // Creates or opens an existing bits job, and handles the marshalling of 479 // Creates or opens an existing bits job, and handles the marshalling of
480 // the interfaces in GIT. 480 // the interfaces in GIT.
481 HRESULT BackgroundDownloader::BeginDownloadHelper(const GURL& url) { 481 HRESULT BackgroundDownloader::BeginDownloadHelper(const GURL& url) {
482 ScopedComPtr<IGlobalInterfaceTable> git; 482 ScopedComPtr<IGlobalInterfaceTable> git;
483 HRESULT hr = GetGit(&git); 483 HRESULT hr = GetGit(&git);
484 if (FAILED(hr)) 484 if (FAILED(hr))
485 return hr; 485 return hr;
486 486
487 hr = CreateBitsManager(bits_manager_.Receive()); 487 hr = CreateBitsManager(bits_manager_.GetAddressOf());
488 if (FAILED(hr)) 488 if (FAILED(hr))
489 return hr; 489 return hr;
490 490
491 hr = RegisterInterfaceInGit(git, bits_manager_, &git_cookie_bits_manager_); 491 hr = RegisterInterfaceInGit(git, bits_manager_, &git_cookie_bits_manager_);
492 if (FAILED(hr)) 492 if (FAILED(hr))
493 return hr; 493 return hr;
494 494
495 hr = QueueBitsJob(url, job_.Receive()); 495 hr = QueueBitsJob(url, job_.GetAddressOf());
496 if (FAILED(hr)) 496 if (FAILED(hr))
497 return hr; 497 return hr;
498 498
499 hr = RegisterInterfaceInGit(git, job_, &git_cookie_job_); 499 hr = RegisterInterfaceInGit(git, job_, &git_cookie_job_);
500 if (FAILED(hr)) 500 if (FAILED(hr))
501 return hr; 501 return hr;
502 502
503 return S_OK; 503 return S_OK;
504 } 504 }
505 505
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 return false; 710 return false;
711 } 711 }
712 712
713 // Creates or opens a job for the given url and queues it up. Tries to 713 // Creates or opens a job for the given url and queues it up. Tries to
714 // install a job observer but continues on if an observer can't be set up. 714 // install a job observer but continues on if an observer can't be set up.
715 HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url, 715 HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url,
716 IBackgroundCopyJob** job) { 716 IBackgroundCopyJob** job) {
717 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 717 DCHECK(task_runner()->RunsTasksOnCurrentThread());
718 718
719 ScopedComPtr<IBackgroundCopyJob> p; 719 ScopedComPtr<IBackgroundCopyJob> p;
720 HRESULT hr = CreateOrOpenJob(url, p.Receive()); 720 HRESULT hr = CreateOrOpenJob(url, p.GetAddressOf());
721 if (FAILED(hr)) 721 if (FAILED(hr))
722 return hr; 722 return hr;
723 723
724 if (hr == S_OK) { 724 if (hr == S_OK) {
725 // This is a new job and it needs initialization. 725 // This is a new job and it needs initialization.
726 hr = InitializeNewJob(p, url); 726 hr = InitializeNewJob(p, url);
727 if (FAILED(hr)) 727 if (FAILED(hr))
728 return hr; 728 return hr;
729 } 729 }
730 730
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 877
878 for (auto cookie : cookies) { 878 for (auto cookie : cookies) {
879 // TODO(sorin): check the result of the call, see crbug.com/644857. 879 // TODO(sorin): check the result of the call, see crbug.com/644857.
880 git->RevokeInterfaceFromGlobal(cookie); 880 git->RevokeInterfaceFromGlobal(cookie);
881 } 881 }
882 882
883 return S_OK; 883 return S_OK;
884 } 884 }
885 885
886 } // namespace update_client 886 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698