| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/component_updater/background_downloader_win.h" | 5 #include "chrome/browser/component_updater/background_downloader_win.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 | 9 |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // of the code to move on to trying other urls or trying other components. | 89 // of the code to move on to trying other urls or trying other components. |
| 90 // Last, after completing a job, irrespective of the outcome, the jobs older | 90 // Last, after completing a job, irrespective of the outcome, the jobs older |
| 91 // than a week are proactively cleaned up. | 91 // than a week are proactively cleaned up. |
| 92 | 92 |
| 93 namespace component_updater { | 93 namespace component_updater { |
| 94 | 94 |
| 95 namespace { | 95 namespace { |
| 96 | 96 |
| 97 // All jobs created by this module have a specific description so they can | 97 // All jobs created by this module have a specific description so they can |
| 98 // be found at run-time or by using system administration tools. | 98 // be found at run-time or by using system administration tools. |
| 99 const char16 kJobDescription[] = L"Chrome Component Updater"; | 99 const base::char16 kJobDescription[] = L"Chrome Component Updater"; |
| 100 | 100 |
| 101 // How often the code looks for changes in the BITS job state. | 101 // How often the code looks for changes in the BITS job state. |
| 102 const int kJobPollingIntervalSec = 10; | 102 const int kJobPollingIntervalSec = 10; |
| 103 | 103 |
| 104 // How long BITS waits before retrying a job after the job encountered | 104 // How long BITS waits before retrying a job after the job encountered |
| 105 // a transient error. If this value is not set, the BITS default is 10 minutes. | 105 // a transient error. If this value is not set, the BITS default is 10 minutes. |
| 106 const int kMinimumRetryDelayMin = 1; | 106 const int kMinimumRetryDelayMin = 1; |
| 107 | 107 |
| 108 // How long to wait for stuck jobs. Stuck jobs could be queued for too long, | 108 // How long to wait for stuck jobs. Stuck jobs could be queued for too long, |
| 109 // have trouble connecting, could be suspended for any reason, or they have | 109 // have trouble connecting, could be suspended for any reason, or they have |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 // Returns the file name, the url, and some per-file progress information. | 161 // Returns the file name, the url, and some per-file progress information. |
| 162 // The function out parameters can be NULL if that data is not requested. | 162 // The function out parameters can be NULL if that data is not requested. |
| 163 HRESULT GetJobFileProperties(IBackgroundCopyFile* file, | 163 HRESULT GetJobFileProperties(IBackgroundCopyFile* file, |
| 164 base::string16* local_name, | 164 base::string16* local_name, |
| 165 base::string16* remote_name, | 165 base::string16* remote_name, |
| 166 BG_FILE_PROGRESS* progress) { | 166 BG_FILE_PROGRESS* progress) { |
| 167 HRESULT hr = S_OK; | 167 HRESULT hr = S_OK; |
| 168 | 168 |
| 169 if (local_name) { | 169 if (local_name) { |
| 170 ScopedCoMem<char16> name; | 170 ScopedCoMem<base::char16> name; |
| 171 hr = file->GetLocalName(&name); | 171 hr = file->GetLocalName(&name); |
| 172 if (FAILED(hr)) | 172 if (FAILED(hr)) |
| 173 return hr; | 173 return hr; |
| 174 local_name->assign(name); | 174 local_name->assign(name); |
| 175 } | 175 } |
| 176 | 176 |
| 177 if (remote_name) { | 177 if (remote_name) { |
| 178 ScopedCoMem<char16> name; | 178 ScopedCoMem<base::char16> name; |
| 179 hr = file->GetRemoteName(&name); | 179 hr = file->GetRemoteName(&name); |
| 180 if (FAILED(hr)) | 180 if (FAILED(hr)) |
| 181 return hr; | 181 return hr; |
| 182 remote_name->assign(name); | 182 remote_name->assign(name); |
| 183 } | 183 } |
| 184 | 184 |
| 185 if (progress) { | 185 if (progress) { |
| 186 BG_FILE_PROGRESS bg_file_progress = {}; | 186 BG_FILE_PROGRESS bg_file_progress = {}; |
| 187 hr = file->GetProgress(&bg_file_progress); | 187 hr = file->GetProgress(&bg_file_progress); |
| 188 if (FAILED(hr)) | 188 if (FAILED(hr)) |
| 189 return hr; | 189 return hr; |
| 190 *progress = bg_file_progress; | 190 *progress = bg_file_progress; |
| 191 } | 191 } |
| 192 | 192 |
| 193 return hr; | 193 return hr; |
| 194 } | 194 } |
| 195 | 195 |
| 196 HRESULT GetJobDescription(IBackgroundCopyJob* job, const base::string16* name) { | 196 HRESULT GetJobDescription(IBackgroundCopyJob* job, const base::string16* name) { |
| 197 ScopedCoMem<char16> description; | 197 ScopedCoMem<base::char16> description; |
| 198 return job->GetDescription(&description); | 198 return job->GetDescription(&description); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Returns the job error code in |error_code| if the job is in the transient | 201 // Returns the job error code in |error_code| if the job is in the transient |
| 202 // or the final error state. Otherwise, the job error is not available and | 202 // or the final error state. Otherwise, the job error is not available and |
| 203 // the function fails. | 203 // the function fails. |
| 204 HRESULT GetJobError(IBackgroundCopyJob* job, HRESULT* error_code_out) { | 204 HRESULT GetJobError(IBackgroundCopyJob* job, HRESULT* error_code_out) { |
| 205 *error_code_out = S_OK; | 205 *error_code_out = S_OK; |
| 206 ScopedComPtr<IBackgroundCopyError> copy_error; | 206 ScopedComPtr<IBackgroundCopyError> copy_error; |
| 207 HRESULT hr = job->GetError(copy_error.Receive()); | 207 HRESULT hr = job->GetError(copy_error.Receive()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 bool JobFileUrlEqual::operator()(IBackgroundCopyJob* job, | 283 bool JobFileUrlEqual::operator()(IBackgroundCopyJob* job, |
| 284 const base::string16& remote_name) const { | 284 const base::string16& remote_name) const { |
| 285 std::vector<ScopedComPtr<IBackgroundCopyFile> > files; | 285 std::vector<ScopedComPtr<IBackgroundCopyFile> > files; |
| 286 HRESULT hr = GetFilesInJob(job, &files); | 286 HRESULT hr = GetFilesInJob(job, &files); |
| 287 if (FAILED(hr)) | 287 if (FAILED(hr)) |
| 288 return false; | 288 return false; |
| 289 | 289 |
| 290 for (size_t i = 0; i != files.size(); ++i) { | 290 for (size_t i = 0; i != files.size(); ++i) { |
| 291 ScopedCoMem<char16> name; | 291 ScopedCoMem<base::char16> name; |
| 292 if (SUCCEEDED(files[i]->GetRemoteName(&name)) && | 292 if (SUCCEEDED(files[i]->GetRemoteName(&name)) && |
| 293 remote_name.compare(name) == 0) | 293 remote_name.compare(name) == 0) |
| 294 return true; | 294 return true; |
| 295 } | 295 } |
| 296 | 296 |
| 297 return false; | 297 return false; |
| 298 } | 298 } |
| 299 | 299 |
| 300 // Creates an instance of the BITS manager. | 300 // Creates an instance of the BITS manager. |
| 301 HRESULT GetBitsManager(IBackgroundCopyManager** bits_manager) { | 301 HRESULT GetBitsManager(IBackgroundCopyManager** bits_manager) { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 } | 694 } |
| 695 | 695 |
| 696 bool BackgroundDownloader::IsStuck() { | 696 bool BackgroundDownloader::IsStuck() { |
| 697 const base::TimeDelta job_stuck_timeout( | 697 const base::TimeDelta job_stuck_timeout( |
| 698 base::TimeDelta::FromMinutes(kJobStuckTimeoutMin)); | 698 base::TimeDelta::FromMinutes(kJobStuckTimeoutMin)); |
| 699 return job_stuck_begin_time_ + job_stuck_timeout < base::Time::Now(); | 699 return job_stuck_begin_time_ + job_stuck_timeout < base::Time::Now(); |
| 700 } | 700 } |
| 701 | 701 |
| 702 } // namespace component_updater | 702 } // namespace component_updater |
| 703 | 703 |
| OLD | NEW |