OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/download/download_manager.h" | 5 #include "content/browser/download/download_manager.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "content/browser/browser_context.h" | 19 #include "content/browser/browser_context.h" |
20 #include "content/browser/download/download_create_info.h" | 20 #include "content/browser/download/download_create_info.h" |
21 #include "content/browser/download/download_file_manager.h" | 21 #include "content/browser/download/download_file_manager.h" |
22 #include "content/browser/download/download_id_factory.h" | 22 #include "content/browser/download/download_id_factory.h" |
23 #include "content/browser/download/download_item.h" | 23 #include "content/browser/download/download_item_impl.h" |
24 #include "content/browser/download/download_persistent_store_info.h" | 24 #include "content/browser/download/download_persistent_store_info.h" |
25 #include "content/browser/download/download_stats.h" | 25 #include "content/browser/download/download_stats.h" |
26 #include "content/browser/download/download_status_updater.h" | 26 #include "content/browser/download/download_status_updater.h" |
27 #include "content/browser/download/interrupt_reasons.h" | 27 #include "content/browser/download/interrupt_reasons.h" |
28 #include "content/browser/renderer_host/render_process_host.h" | 28 #include "content/browser/renderer_host/render_process_host.h" |
29 #include "content/browser/renderer_host/render_view_host.h" | 29 #include "content/browser/renderer_host/render_view_host.h" |
30 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 30 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
31 #include "content/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Go through all downloads in downloads_. Dangerous ones we need to | 121 // Go through all downloads in downloads_. Dangerous ones we need to |
122 // remove on disk, and in progress ones we need to cancel. | 122 // remove on disk, and in progress ones we need to cancel. |
123 for (DownloadSet::iterator it = downloads_.begin(); it != downloads_.end();) { | 123 for (DownloadSet::iterator it = downloads_.begin(); it != downloads_.end();) { |
124 DownloadItem* download = *it; | 124 DownloadItem* download = *it; |
125 | 125 |
126 // Save iterator from potential erases in this set done by called code. | 126 // Save iterator from potential erases in this set done by called code. |
127 // Iterators after an erasure point are still valid for lists and | 127 // Iterators after an erasure point are still valid for lists and |
128 // associative containers such as sets. | 128 // associative containers such as sets. |
129 it++; | 129 it++; |
130 | 130 |
131 if (download->safety_state() == DownloadItem::DANGEROUS && | 131 if (download->GetSafetyState() == DownloadItem::DANGEROUS && |
132 download->IsPartialDownload()) { | 132 download->IsPartialDownload()) { |
133 // The user hasn't accepted it, so we need to remove it | 133 // The user hasn't accepted it, so we need to remove it |
134 // from the disk. This may or may not result in it being | 134 // from the disk. This may or may not result in it being |
135 // removed from the DownloadManager queues and deleted | 135 // removed from the DownloadManager queues and deleted |
136 // (specifically, DownloadManager::RemoveDownload only | 136 // (specifically, DownloadManager::RemoveDownload only |
137 // removes and deletes it if it's known to the history service) | 137 // removes and deletes it if it's known to the history service) |
138 // so the only thing we know after calling this function is that | 138 // so the only thing we know after calling this function is that |
139 // the download was deleted if-and-only-if it was removed | 139 // the download was deleted if-and-only-if it was removed |
140 // from all queues. | 140 // from all queues. |
141 download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); | 141 download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); |
(...skipping 24 matching lines...) Expand all Loading... |
166 | 166 |
167 shutdown_needed_ = false; | 167 shutdown_needed_ = false; |
168 } | 168 } |
169 | 169 |
170 void DownloadManager::GetTemporaryDownloads( | 170 void DownloadManager::GetTemporaryDownloads( |
171 const FilePath& dir_path, DownloadVector* result) { | 171 const FilePath& dir_path, DownloadVector* result) { |
172 DCHECK(result); | 172 DCHECK(result); |
173 | 173 |
174 for (DownloadMap::iterator it = history_downloads_.begin(); | 174 for (DownloadMap::iterator it = history_downloads_.begin(); |
175 it != history_downloads_.end(); ++it) { | 175 it != history_downloads_.end(); ++it) { |
176 if (it->second->is_temporary() && | 176 if (it->second->IsTemporary() && |
177 it->second->full_path().DirName() == dir_path) | 177 it->second->GetFullPath().DirName() == dir_path) |
178 result->push_back(it->second); | 178 result->push_back(it->second); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void DownloadManager::GetAllDownloads( | 182 void DownloadManager::GetAllDownloads( |
183 const FilePath& dir_path, DownloadVector* result) { | 183 const FilePath& dir_path, DownloadVector* result) { |
184 DCHECK(result); | 184 DCHECK(result); |
185 | 185 |
186 for (DownloadMap::iterator it = history_downloads_.begin(); | 186 for (DownloadMap::iterator it = history_downloads_.begin(); |
187 it != history_downloads_.end(); ++it) { | 187 it != history_downloads_.end(); ++it) { |
188 if (!it->second->is_temporary() && | 188 if (!it->second->IsTemporary() && |
189 (dir_path.empty() || it->second->full_path().DirName() == dir_path)) | 189 (dir_path.empty() || it->second->GetFullPath().DirName() == dir_path)) |
190 result->push_back(it->second); | 190 result->push_back(it->second); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void DownloadManager::SearchDownloads(const string16& query, | 194 void DownloadManager::SearchDownloads(const string16& query, |
195 DownloadVector* result) { | 195 DownloadVector* result) { |
196 string16 query_lower(base::i18n::ToLower(query)); | 196 string16 query_lower(base::i18n::ToLower(query)); |
197 | 197 |
198 for (DownloadMap::iterator it = history_downloads_.begin(); | 198 for (DownloadMap::iterator it = history_downloads_.begin(); |
199 it != history_downloads_.end(); ++it) { | 199 it != history_downloads_.end(); ++it) { |
200 DownloadItem* download_item = it->second; | 200 DownloadItem* download_item = it->second; |
201 | 201 |
202 if (download_item->is_temporary()) | 202 if (download_item->IsTemporary()) |
203 continue; | 203 continue; |
204 | 204 |
205 // Display Incognito downloads only in Incognito window, and vice versa. | 205 // Display Incognito downloads only in Incognito window, and vice versa. |
206 // The Incognito Downloads page will get the list of non-Incognito downloads | 206 // The Incognito Downloads page will get the list of non-Incognito downloads |
207 // from its parent profile. | 207 // from its parent profile. |
208 if (browser_context_->IsOffTheRecord() != download_item->is_otr()) | 208 if (browser_context_->IsOffTheRecord() != download_item->IsOtr()) |
209 continue; | 209 continue; |
210 | 210 |
211 if (download_item->MatchesQuery(query_lower)) | 211 if (download_item->MatchesQuery(query_lower)) |
212 result->push_back(download_item); | 212 result->push_back(download_item); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 // Query the history service for information about all persisted downloads. | 216 // Query the history service for information about all persisted downloads. |
217 bool DownloadManager::Init(content::BrowserContext* browser_context) { | 217 bool DownloadManager::Init(content::BrowserContext* browser_context) { |
218 DCHECK(browser_context); | 218 DCHECK(browser_context); |
(...skipping 27 matching lines...) Expand all Loading... |
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
247 for (DownloadMap::iterator it = history_downloads_.begin(); | 247 for (DownloadMap::iterator it = history_downloads_.begin(); |
248 it != history_downloads_.end(); ++it) { | 248 it != history_downloads_.end(); ++it) { |
249 CheckForFileRemoval(it->second); | 249 CheckForFileRemoval(it->second); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) { | 253 void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) { |
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
255 if (download_item->IsComplete() && | 255 if (download_item->IsComplete() && |
256 !download_item->file_externally_removed()) { | 256 !download_item->GetFileExternallyRemoved()) { |
257 BrowserThread::PostTask( | 257 BrowserThread::PostTask( |
258 BrowserThread::FILE, FROM_HERE, | 258 BrowserThread::FILE, FROM_HERE, |
259 base::Bind(&DownloadManager::CheckForFileRemovalOnFileThread, | 259 base::Bind(&DownloadManager::CheckForFileRemovalOnFileThread, |
260 this, download_item->db_handle(), | 260 this, download_item->GetDbHandle(), |
261 download_item->GetTargetFilePath())); | 261 download_item->GetTargetFilePath())); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 void DownloadManager::CheckForFileRemovalOnFileThread( | 265 void DownloadManager::CheckForFileRemovalOnFileThread( |
266 int64 db_handle, const FilePath& path) { | 266 int64 db_handle, const FilePath& path) { |
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
268 if (!file_util::PathExists(path)) { | 268 if (!file_util::PathExists(path)) { |
269 BrowserThread::PostTask( | 269 BrowserThread::PostTask( |
270 BrowserThread::UI, FROM_HERE, | 270 BrowserThread::UI, FROM_HERE, |
(...skipping 14 matching lines...) Expand all Loading... |
285 int32 download_id) { | 285 int32 download_id) { |
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
287 | 287 |
288 DownloadItem* download = GetActiveDownloadItem(download_id); | 288 DownloadItem* download = GetActiveDownloadItem(download_id); |
289 if (!download) | 289 if (!download) |
290 return; | 290 return; |
291 | 291 |
292 VLOG(20) << __FUNCTION__ << "()" | 292 VLOG(20) << __FUNCTION__ << "()" |
293 << " download = " << download->DebugString(true); | 293 << " download = " << download->DebugString(true); |
294 | 294 |
295 FilePath suggested_path = download->suggested_path(); | 295 FilePath suggested_path = download->GetSuggestedPath(); |
296 | 296 |
297 if (download->prompt_user_for_save_location()) { | 297 if (download->PromptUserForSaveLocation()) { |
298 // We must ask the user for the place to put the download. | 298 // We must ask the user for the place to put the download. |
299 TabContents* contents = download->GetTabContents(); | 299 TabContents* contents = download->GetTabContents(); |
300 | 300 |
301 // |id_ptr| will be deleted in either FileSelected() or | 301 // |id_ptr| will be deleted in either FileSelected() or |
302 // FileSelectionCancelled(). | 302 // FileSelectionCancelled(). |
303 int32* id_ptr = new int32; | 303 int32* id_ptr = new int32; |
304 *id_ptr = download_id; | 304 *id_ptr = download_id; |
305 | 305 |
306 delegate_->ChooseDownloadPath( | 306 delegate_->ChooseDownloadPath( |
307 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); | 307 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); |
308 | 308 |
309 FOR_EACH_OBSERVER(Observer, observers_, | 309 FOR_EACH_OBSERVER(Observer, observers_, |
310 SelectFileDialogDisplayed(download_id)); | 310 SelectFileDialogDisplayed(download_id)); |
311 } else { | 311 } else { |
312 // No prompting for download, just continue with the suggested name. | 312 // No prompting for download, just continue with the suggested name. |
313 ContinueDownloadWithPath(download, suggested_path); | 313 ContinueDownloadWithPath(download, suggested_path); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 void DownloadManager::CreateDownloadItem( | 317 void DownloadManager::CreateDownloadItem( |
318 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { | 318 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
320 | 320 |
321 DownloadItem* download = new DownloadItem( | 321 DownloadItem* download = new DownloadItemImpl( |
322 this, *info, new DownloadRequestHandle(request_handle), | 322 this, *info, new DownloadRequestHandle(request_handle), |
323 browser_context_->IsOffTheRecord()); | 323 browser_context_->IsOffTheRecord()); |
324 int32 download_id = info->download_id.local(); | 324 int32 download_id = info->download_id.local(); |
325 DCHECK(!ContainsKey(in_progress_, download_id)); | 325 DCHECK(!ContainsKey(in_progress_, download_id)); |
326 | 326 |
327 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 327 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
328 CHECK(!ContainsKey(active_downloads_, download_id)); | 328 CHECK(!ContainsKey(active_downloads_, download_id)); |
329 downloads_.insert(download); | 329 downloads_.insert(download); |
330 active_downloads_[download_id] = download; | 330 active_downloads_[download_id] = download; |
331 } | 331 } |
332 | 332 |
333 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, | 333 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, |
334 const FilePath& chosen_file) { | 334 const FilePath& chosen_file) { |
335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
336 DCHECK(download); | 336 DCHECK(download); |
337 | 337 |
338 int32 download_id = download->id(); | 338 int32 download_id = download->GetId(); |
339 | 339 |
340 // NOTE(ahendrickson) Eventually |active_downloads_| will replace | 340 // NOTE(ahendrickson) Eventually |active_downloads_| will replace |
341 // |in_progress_|, but we don't want to change the semantics yet. | 341 // |in_progress_|, but we don't want to change the semantics yet. |
342 DCHECK(!ContainsKey(in_progress_, download_id)); | 342 DCHECK(!ContainsKey(in_progress_, download_id)); |
343 DCHECK(ContainsKey(downloads_, download)); | 343 DCHECK(ContainsKey(downloads_, download)); |
344 DCHECK(ContainsKey(active_downloads_, download_id)); | 344 DCHECK(ContainsKey(active_downloads_, download_id)); |
345 | 345 |
346 // Make sure the initial file name is set only once. | 346 // Make sure the initial file name is set only once. |
347 download->OnPathDetermined(chosen_file); | 347 download->OnPathDetermined(chosen_file); |
348 | 348 |
349 VLOG(20) << __FUNCTION__ << "()" | 349 VLOG(20) << __FUNCTION__ << "()" |
350 << " download = " << download->DebugString(true); | 350 << " download = " << download->DebugString(true); |
351 | 351 |
352 in_progress_[download_id] = download; | 352 in_progress_[download_id] = download; |
353 UpdateDownloadProgress(); // Reflect entry into in_progress_. | 353 UpdateDownloadProgress(); // Reflect entry into in_progress_. |
354 | 354 |
355 // Rename to intermediate name. | 355 // Rename to intermediate name. |
356 FilePath download_path; | 356 FilePath download_path; |
357 if (!delegate_->OverrideIntermediatePath(download, &download_path)) | 357 if (!delegate_->OverrideIntermediatePath(download, &download_path)) |
358 download_path = download->full_path(); | 358 download_path = download->GetFullPath(); |
359 | 359 |
360 BrowserThread::PostTask( | 360 BrowserThread::PostTask( |
361 BrowserThread::FILE, FROM_HERE, | 361 BrowserThread::FILE, FROM_HERE, |
362 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, | 362 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, |
363 file_manager_, download->global_id(), download_path)); | 363 file_manager_, download->GetGlobalId(), download_path)); |
364 | 364 |
365 download->Rename(download_path); | 365 download->Rename(download_path); |
366 | 366 |
367 delegate_->AddItemToPersistentStore(download); | 367 delegate_->AddItemToPersistentStore(download); |
368 } | 368 } |
369 | 369 |
370 void DownloadManager::UpdateDownload(int32 download_id, int64 size) { | 370 void DownloadManager::UpdateDownload(int32 download_id, int64 size) { |
371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
372 DownloadMap::iterator it = active_downloads_.find(download_id); | 372 DownloadMap::iterator it = active_downloads_.find(download_id); |
373 if (it != active_downloads_.end()) { | 373 if (it != active_downloads_.end()) { |
(...skipping 21 matching lines...) Expand all Loading... |
395 | 395 |
396 DownloadItem* download = active_downloads_[download_id]; | 396 DownloadItem* download = active_downloads_[download_id]; |
397 download->OnAllDataSaved(size, hash); | 397 download->OnAllDataSaved(size, hash); |
398 delegate_->OnResponseCompleted(download); | 398 delegate_->OnResponseCompleted(download); |
399 | 399 |
400 MaybeCompleteDownload(download); | 400 MaybeCompleteDownload(download); |
401 } | 401 } |
402 | 402 |
403 void DownloadManager::AssertQueueStateConsistent(DownloadItem* download) { | 403 void DownloadManager::AssertQueueStateConsistent(DownloadItem* download) { |
404 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 404 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
405 if (download->state() == DownloadItem::REMOVING) { | 405 if (download->GetState() == DownloadItem::REMOVING) { |
406 CHECK(!ContainsKey(downloads_, download)); | 406 CHECK(!ContainsKey(downloads_, download)); |
407 CHECK(!ContainsKey(active_downloads_, download->id())); | 407 CHECK(!ContainsKey(active_downloads_, download->GetId())); |
408 CHECK(!ContainsKey(in_progress_, download->id())); | 408 CHECK(!ContainsKey(in_progress_, download->GetId())); |
409 CHECK(!ContainsKey(history_downloads_, download->db_handle())); | 409 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); |
410 return; | 410 return; |
411 } | 411 } |
412 | 412 |
413 // Should be in downloads_ if we're not REMOVING. | 413 // Should be in downloads_ if we're not REMOVING. |
414 CHECK(ContainsKey(downloads_, download)); | 414 CHECK(ContainsKey(downloads_, download)); |
415 | 415 |
416 // Check history_downloads_ consistency. | 416 // Check history_downloads_ consistency. |
417 if (download->db_handle() != DownloadItem::kUninitializedHandle) { | 417 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { |
418 CHECK(ContainsKey(history_downloads_, download->db_handle())); | 418 CHECK(ContainsKey(history_downloads_, download->GetDbHandle())); |
419 } else { | 419 } else { |
420 // TODO(rdsmith): Somewhat painful; make sure to disable in | 420 // TODO(rdsmith): Somewhat painful; make sure to disable in |
421 // release builds after resolution of http://crbug.com/85408. | 421 // release builds after resolution of http://crbug.com/85408. |
422 for (DownloadMap::iterator it = history_downloads_.begin(); | 422 for (DownloadMap::iterator it = history_downloads_.begin(); |
423 it != history_downloads_.end(); ++it) { | 423 it != history_downloads_.end(); ++it) { |
424 CHECK(it->second != download); | 424 CHECK(it->second != download); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 int64 state = download->state(); | 428 int64 state = download->GetState(); |
429 base::debug::Alias(&state); | 429 base::debug::Alias(&state); |
430 if (ContainsKey(active_downloads_, download->id())) { | 430 if (ContainsKey(active_downloads_, download->GetId())) { |
431 if (download->db_handle() != DownloadItem::kUninitializedHandle) | 431 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) |
432 CHECK_EQ(DownloadItem::IN_PROGRESS, download->state()); | 432 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
433 if (DownloadItem::IN_PROGRESS != download->state()) | 433 if (DownloadItem::IN_PROGRESS != download->GetState()) |
434 CHECK_EQ(DownloadItem::kUninitializedHandle, download->db_handle()); | 434 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle()); |
435 } | 435 } |
436 if (DownloadItem::IN_PROGRESS == download->state()) | 436 if (DownloadItem::IN_PROGRESS == download->GetState()) |
437 CHECK(ContainsKey(active_downloads_, download->id())); | 437 CHECK(ContainsKey(active_downloads_, download->GetId())); |
438 } | 438 } |
439 | 439 |
440 bool DownloadManager::IsDownloadReadyForCompletion(DownloadItem* download) { | 440 bool DownloadManager::IsDownloadReadyForCompletion(DownloadItem* download) { |
441 // If we don't have all the data, the download is not ready for | 441 // If we don't have all the data, the download is not ready for |
442 // completion. | 442 // completion. |
443 if (!download->all_data_saved()) | 443 if (!download->AllDataSaved()) |
444 return false; | 444 return false; |
445 | 445 |
446 // If the download is dangerous, but not yet validated, it's not ready for | 446 // If the download is dangerous, but not yet validated, it's not ready for |
447 // completion. | 447 // completion. |
448 if (download->safety_state() == DownloadItem::DANGEROUS) | 448 if (download->GetSafetyState() == DownloadItem::DANGEROUS) |
449 return false; | 449 return false; |
450 | 450 |
451 // If the download isn't active (e.g. has been cancelled) it's not | 451 // If the download isn't active (e.g. has been cancelled) it's not |
452 // ready for completion. | 452 // ready for completion. |
453 if (active_downloads_.count(download->id()) == 0) | 453 if (active_downloads_.count(download->GetId()) == 0) |
454 return false; | 454 return false; |
455 | 455 |
456 // If the download hasn't been inserted into the history system | 456 // If the download hasn't been inserted into the history system |
457 // (which occurs strictly after file name determination, intermediate | 457 // (which occurs strictly after file name determination, intermediate |
458 // file rename, and UI display) then it's not ready for completion. | 458 // file rename, and UI display) then it's not ready for completion. |
459 if (download->db_handle() == DownloadItem::kUninitializedHandle) | 459 if (download->GetDbHandle() == DownloadItem::kUninitializedHandle) |
460 return false; | 460 return false; |
461 | 461 |
462 return true; | 462 return true; |
463 } | 463 } |
464 | 464 |
465 void DownloadManager::MaybeCompleteDownload(DownloadItem* download) { | 465 void DownloadManager::MaybeCompleteDownload(DownloadItem* download) { |
466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
467 VLOG(20) << __FUNCTION__ << "()" << " download = " | 467 VLOG(20) << __FUNCTION__ << "()" << " download = " |
468 << download->DebugString(false); | 468 << download->DebugString(false); |
469 | 469 |
470 if (!IsDownloadReadyForCompletion(download)) | 470 if (!IsDownloadReadyForCompletion(download)) |
471 return; | 471 return; |
472 | 472 |
473 // TODO(rdsmith): DCHECK that we only pass through this point | 473 // TODO(rdsmith): DCHECK that we only pass through this point |
474 // once per download. The natural way to do this is by a state | 474 // once per download. The natural way to do this is by a state |
475 // transition on the DownloadItem. | 475 // transition on the DownloadItem. |
476 | 476 |
477 // Confirm we're in the proper set of states to be here; | 477 // Confirm we're in the proper set of states to be here; |
478 // in in_progress_, have all data, have a history handle, (validated or safe). | 478 // in in_progress_, have all data, have a history handle, (validated or safe). |
479 DCHECK_NE(DownloadItem::DANGEROUS, download->safety_state()); | 479 DCHECK_NE(DownloadItem::DANGEROUS, download->GetSafetyState()); |
480 DCHECK_EQ(1u, in_progress_.count(download->id())); | 480 DCHECK_EQ(1u, in_progress_.count(download->GetId())); |
481 DCHECK(download->all_data_saved()); | 481 DCHECK(download->AllDataSaved()); |
482 DCHECK(download->db_handle() != DownloadItem::kUninitializedHandle); | 482 DCHECK(download->GetDbHandle() != DownloadItem::kUninitializedHandle); |
483 DCHECK_EQ(1u, history_downloads_.count(download->db_handle())); | 483 DCHECK_EQ(1u, history_downloads_.count(download->GetDbHandle())); |
484 | 484 |
485 // Give the delegate a chance to override. | 485 // Give the delegate a chance to override. |
486 if (!delegate_->ShouldCompleteDownload(download)) | 486 if (!delegate_->ShouldCompleteDownload(download)) |
487 return; | 487 return; |
488 | 488 |
489 VLOG(20) << __FUNCTION__ << "()" << " executing: download = " | 489 VLOG(20) << __FUNCTION__ << "()" << " executing: download = " |
490 << download->DebugString(false); | 490 << download->DebugString(false); |
491 | 491 |
492 // Remove the id from in_progress | 492 // Remove the id from in_progress |
493 in_progress_.erase(download->id()); | 493 in_progress_.erase(download->GetId()); |
494 UpdateDownloadProgress(); // Reflect removal from in_progress_. | 494 UpdateDownloadProgress(); // Reflect removal from in_progress_. |
495 | 495 |
496 delegate_->UpdateItemInPersistentStore(download); | 496 delegate_->UpdateItemInPersistentStore(download); |
497 | 497 |
498 // Finish the download. | 498 // Finish the download. |
499 download->OnDownloadCompleting(file_manager_); | 499 download->OnDownloadCompleting(file_manager_); |
500 } | 500 } |
501 | 501 |
502 void DownloadManager::DownloadCompleted(int32 download_id) { | 502 void DownloadManager::DownloadCompleted(int32 download_id) { |
503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
504 DownloadItem* download = GetDownloadItem(download_id); | 504 DownloadItem* download = GetDownloadItem(download_id); |
505 DCHECK(download); | 505 DCHECK(download); |
506 delegate_->UpdateItemInPersistentStore(download); | 506 delegate_->UpdateItemInPersistentStore(download); |
507 active_downloads_.erase(download_id); | 507 active_downloads_.erase(download_id); |
508 AssertQueueStateConsistent(download); | 508 AssertQueueStateConsistent(download); |
509 } | 509 } |
510 | 510 |
511 void DownloadManager::OnDownloadRenamedToFinalName(int download_id, | 511 void DownloadManager::OnDownloadRenamedToFinalName(int download_id, |
512 const FilePath& full_path, | 512 const FilePath& full_path, |
513 int uniquifier) { | 513 int uniquifier) { |
514 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id | 514 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id |
515 << " full_path = \"" << full_path.value() << "\"" | 515 << " full_path = \"" << full_path.value() << "\"" |
516 << " uniquifier = " << uniquifier; | 516 << " uniquifier = " << uniquifier; |
517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
518 | 518 |
519 DownloadItem* item = GetDownloadItem(download_id); | 519 DownloadItem* item = GetDownloadItem(download_id); |
520 if (!item) | 520 if (!item) |
521 return; | 521 return; |
522 | 522 |
523 if (item->safety_state() == DownloadItem::SAFE) { | 523 if (item->GetSafetyState() == DownloadItem::SAFE) { |
524 DCHECK_EQ(0, uniquifier) << "We should not uniquify SAFE downloads twice"; | 524 DCHECK_EQ(0, uniquifier) << "We should not uniquify SAFE downloads twice"; |
525 } | 525 } |
526 | 526 |
527 BrowserThread::PostTask( | 527 BrowserThread::PostTask( |
528 BrowserThread::FILE, FROM_HERE, | 528 BrowserThread::FILE, FROM_HERE, |
529 base::Bind(&DownloadFileManager::CompleteDownload, | 529 base::Bind(&DownloadFileManager::CompleteDownload, |
530 file_manager_, item->global_id())); | 530 file_manager_, item->GetGlobalId())); |
531 | 531 |
532 if (uniquifier) | 532 if (uniquifier) |
533 item->set_path_uniquifier(uniquifier); | 533 item->SetPathUniquifier(uniquifier); |
534 | 534 |
535 item->OnDownloadRenamedToFinalName(full_path); | 535 item->OnDownloadRenamedToFinalName(full_path); |
536 delegate_->UpdatePathForItemInPersistentStore(item, full_path); | 536 delegate_->UpdatePathForItemInPersistentStore(item, full_path); |
537 } | 537 } |
538 | 538 |
539 void DownloadManager::CancelDownload(int32 download_id) { | 539 void DownloadManager::CancelDownload(int32 download_id) { |
540 DownloadItem* download = GetActiveDownload(download_id); | 540 DownloadItem* download = GetActiveDownload(download_id); |
541 // A cancel at the right time could remove the download from the | 541 // A cancel at the right time could remove the download from the |
542 // |active_downloads_| map before we get here. | 542 // |active_downloads_| map before we get here. |
543 if (!download) | 543 if (!download) |
(...skipping 21 matching lines...) Expand all Loading... |
565 int64 size, | 565 int64 size, |
566 InterruptReason reason) { | 566 InterruptReason reason) { |
567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
568 | 568 |
569 DownloadItem* download = GetActiveDownload(download_id); | 569 DownloadItem* download = GetActiveDownload(download_id); |
570 if (!download) | 570 if (!download) |
571 return; | 571 return; |
572 | 572 |
573 VLOG(20) << __FUNCTION__ << "()" | 573 VLOG(20) << __FUNCTION__ << "()" |
574 << " reason " << InterruptReasonDebugString(reason) | 574 << " reason " << InterruptReasonDebugString(reason) |
575 << " at offset " << download->received_bytes() | 575 << " at offset " << download->GetReceivedBytes() |
576 << " size = " << size | 576 << " size = " << size |
577 << " download = " << download->DebugString(true); | 577 << " download = " << download->DebugString(true); |
578 | 578 |
579 RemoveFromActiveList(download); | 579 RemoveFromActiveList(download); |
580 download->Interrupted(size, reason); | 580 download->Interrupted(size, reason); |
581 download->OffThreadCancel(file_manager_); | 581 download->OffThreadCancel(file_manager_); |
582 } | 582 } |
583 | 583 |
584 DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) { | 584 DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) { |
585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
586 DownloadMap::iterator it = active_downloads_.find(download_id); | 586 DownloadMap::iterator it = active_downloads_.find(download_id); |
587 if (it == active_downloads_.end()) | 587 if (it == active_downloads_.end()) |
588 return NULL; | 588 return NULL; |
589 | 589 |
590 DownloadItem* download = it->second; | 590 DownloadItem* download = it->second; |
591 | 591 |
592 DCHECK(download); | 592 DCHECK(download); |
593 DCHECK_EQ(download_id, download->id()); | 593 DCHECK_EQ(download_id, download->GetId()); |
594 | 594 |
595 return download; | 595 return download; |
596 } | 596 } |
597 | 597 |
598 void DownloadManager::RemoveFromActiveList(DownloadItem* download) { | 598 void DownloadManager::RemoveFromActiveList(DownloadItem* download) { |
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
600 DCHECK(download); | 600 DCHECK(download); |
601 | 601 |
602 // Clean up will happen when the history system create callback runs if we | 602 // Clean up will happen when the history system create callback runs if we |
603 // don't have a valid db_handle yet. | 603 // don't have a valid db_handle yet. |
604 if (download->db_handle() != DownloadItem::kUninitializedHandle) { | 604 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { |
605 in_progress_.erase(download->id()); | 605 in_progress_.erase(download->GetId()); |
606 active_downloads_.erase(download->id()); | 606 active_downloads_.erase(download->GetId()); |
607 UpdateDownloadProgress(); // Reflect removal from in_progress_. | 607 UpdateDownloadProgress(); // Reflect removal from in_progress_. |
608 delegate_->UpdateItemInPersistentStore(download); | 608 delegate_->UpdateItemInPersistentStore(download); |
609 } | 609 } |
610 } | 610 } |
611 | 611 |
612 void DownloadManager::SetDownloadManagerDelegate( | 612 void DownloadManager::SetDownloadManagerDelegate( |
613 content::DownloadManagerDelegate* delegate) { | 613 content::DownloadManagerDelegate* delegate) { |
614 delegate_ = delegate; | 614 delegate_ = delegate; |
615 } | 615 } |
616 | 616 |
617 void DownloadManager::UpdateDownloadProgress() { | 617 void DownloadManager::UpdateDownloadProgress() { |
618 delegate_->DownloadProgressUpdated(); | 618 delegate_->DownloadProgressUpdated(); |
619 } | 619 } |
620 | 620 |
621 int DownloadManager::RemoveDownloadItems( | 621 int DownloadManager::RemoveDownloadItems( |
622 const DownloadVector& pending_deletes) { | 622 const DownloadVector& pending_deletes) { |
623 if (pending_deletes.empty()) | 623 if (pending_deletes.empty()) |
624 return 0; | 624 return 0; |
625 | 625 |
626 // Delete from internal maps. | 626 // Delete from internal maps. |
627 for (DownloadVector::const_iterator it = pending_deletes.begin(); | 627 for (DownloadVector::const_iterator it = pending_deletes.begin(); |
628 it != pending_deletes.end(); | 628 it != pending_deletes.end(); |
629 ++it) { | 629 ++it) { |
630 DownloadItem* download = *it; | 630 DownloadItem* download = *it; |
631 DCHECK(download); | 631 DCHECK(download); |
632 history_downloads_.erase(download->db_handle()); | 632 history_downloads_.erase(download->GetDbHandle()); |
633 save_page_downloads_.erase(download->id()); | 633 save_page_downloads_.erase(download->GetId()); |
634 downloads_.erase(download); | 634 downloads_.erase(download); |
635 } | 635 } |
636 | 636 |
637 // Tell observers to refresh their views. | 637 // Tell observers to refresh their views. |
638 NotifyModelChanged(); | 638 NotifyModelChanged(); |
639 | 639 |
640 // Delete the download items themselves. | 640 // Delete the download items themselves. |
641 const int num_deleted = static_cast<int>(pending_deletes.size()); | 641 const int num_deleted = static_cast<int>(pending_deletes.size()); |
642 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); | 642 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); |
643 return num_deleted; | 643 return num_deleted; |
(...skipping 17 matching lines...) Expand all Loading... |
661 const base::Time remove_end) { | 661 const base::Time remove_end) { |
662 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end); | 662 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end); |
663 | 663 |
664 // All downloads visible to the user will be in the history, | 664 // All downloads visible to the user will be in the history, |
665 // so scan that map. | 665 // so scan that map. |
666 DownloadVector pending_deletes; | 666 DownloadVector pending_deletes; |
667 for (DownloadMap::const_iterator it = history_downloads_.begin(); | 667 for (DownloadMap::const_iterator it = history_downloads_.begin(); |
668 it != history_downloads_.end(); | 668 it != history_downloads_.end(); |
669 ++it) { | 669 ++it) { |
670 DownloadItem* download = it->second; | 670 DownloadItem* download = it->second; |
671 if (download->start_time() >= remove_begin && | 671 if (download->GetStartTime() >= remove_begin && |
672 (remove_end.is_null() || download->start_time() < remove_end) && | 672 (remove_end.is_null() || download->GetStartTime() < remove_end) && |
673 (download->IsComplete() || download->IsCancelled())) { | 673 (download->IsComplete() || download->IsCancelled())) { |
674 AssertQueueStateConsistent(download); | 674 AssertQueueStateConsistent(download); |
675 pending_deletes.push_back(download); | 675 pending_deletes.push_back(download); |
676 } | 676 } |
677 } | 677 } |
678 return RemoveDownloadItems(pending_deletes); | 678 return RemoveDownloadItems(pending_deletes); |
679 } | 679 } |
680 | 680 |
681 int DownloadManager::RemoveDownloads(const base::Time remove_begin) { | 681 int DownloadManager::RemoveDownloads(const base::Time remove_begin) { |
682 return RemoveDownloadsBetween(remove_begin, base::Time()); | 682 return RemoveDownloadsBetween(remove_begin, base::Time()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 observer->ModelChanged(); | 724 observer->ModelChanged(); |
725 } | 725 } |
726 | 726 |
727 void DownloadManager::RemoveObserver(Observer* observer) { | 727 void DownloadManager::RemoveObserver(Observer* observer) { |
728 observers_.RemoveObserver(observer); | 728 observers_.RemoveObserver(observer); |
729 } | 729 } |
730 | 730 |
731 bool DownloadManager::IsDownloadProgressKnown() const { | 731 bool DownloadManager::IsDownloadProgressKnown() const { |
732 for (DownloadMap::const_iterator i = in_progress_.begin(); | 732 for (DownloadMap::const_iterator i = in_progress_.begin(); |
733 i != in_progress_.end(); ++i) { | 733 i != in_progress_.end(); ++i) { |
734 if (i->second->total_bytes() <= 0) | 734 if (i->second->GetTotalBytes() <= 0) |
735 return false; | 735 return false; |
736 } | 736 } |
737 | 737 |
738 return true; | 738 return true; |
739 } | 739 } |
740 | 740 |
741 int64 DownloadManager::GetInProgressDownloadCount() const { | 741 int64 DownloadManager::GetInProgressDownloadCount() const { |
742 return in_progress_.size(); | 742 return in_progress_.size(); |
743 } | 743 } |
744 | 744 |
745 int64 DownloadManager::GetReceivedDownloadBytes() const { | 745 int64 DownloadManager::GetReceivedDownloadBytes() const { |
746 DCHECK(IsDownloadProgressKnown()); | 746 DCHECK(IsDownloadProgressKnown()); |
747 int64 received_bytes = 0; | 747 int64 received_bytes = 0; |
748 for (DownloadMap::const_iterator i = in_progress_.begin(); | 748 for (DownloadMap::const_iterator i = in_progress_.begin(); |
749 i != in_progress_.end(); ++i) { | 749 i != in_progress_.end(); ++i) { |
750 received_bytes += i->second->received_bytes(); | 750 received_bytes += i->second->GetReceivedBytes(); |
751 } | 751 } |
752 return received_bytes; | 752 return received_bytes; |
753 } | 753 } |
754 | 754 |
755 int64 DownloadManager::GetTotalDownloadBytes() const { | 755 int64 DownloadManager::GetTotalDownloadBytes() const { |
756 DCHECK(IsDownloadProgressKnown()); | 756 DCHECK(IsDownloadProgressKnown()); |
757 int64 total_bytes = 0; | 757 int64 total_bytes = 0; |
758 for (DownloadMap::const_iterator i = in_progress_.begin(); | 758 for (DownloadMap::const_iterator i = in_progress_.begin(); |
759 i != in_progress_.end(); ++i) { | 759 i != in_progress_.end(); ++i) { |
760 total_bytes += i->second->total_bytes(); | 760 total_bytes += i->second->GetTotalBytes(); |
761 } | 761 } |
762 return total_bytes; | 762 return total_bytes; |
763 } | 763 } |
764 | 764 |
765 void DownloadManager::FileSelected(const FilePath& path, void* params) { | 765 void DownloadManager::FileSelected(const FilePath& path, void* params) { |
766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
767 | 767 |
768 int32* id_ptr = reinterpret_cast<int32*>(params); | 768 int32* id_ptr = reinterpret_cast<int32*>(params); |
769 DCHECK(id_ptr != NULL); | 769 DCHECK(id_ptr != NULL); |
770 int32 download_id = *id_ptr; | 770 int32 download_id = *id_ptr; |
771 delete id_ptr; | 771 delete id_ptr; |
772 | 772 |
773 DownloadItem* download = GetActiveDownloadItem(download_id); | 773 DownloadItem* download = GetActiveDownloadItem(download_id); |
774 if (!download) | 774 if (!download) |
775 return; | 775 return; |
776 VLOG(20) << __FUNCTION__ << "()" << " path = \"" << path.value() << "\"" | 776 VLOG(20) << __FUNCTION__ << "()" << " path = \"" << path.value() << "\"" |
777 << " download = " << download->DebugString(true); | 777 << " download = " << download->DebugString(true); |
778 | 778 |
779 if (download->prompt_user_for_save_location()) | 779 if (download->PromptUserForSaveLocation()) |
780 last_download_path_ = path.DirName(); | 780 last_download_path_ = path.DirName(); |
781 | 781 |
782 // Make sure the initial file name is set only once. | 782 // Make sure the initial file name is set only once. |
783 ContinueDownloadWithPath(download, path); | 783 ContinueDownloadWithPath(download, path); |
784 } | 784 } |
785 | 785 |
786 void DownloadManager::FileSelectionCanceled(void* params) { | 786 void DownloadManager::FileSelectionCanceled(void* params) { |
787 // The user didn't pick a place to save the file, so need to cancel the | 787 // The user didn't pick a place to save the file, so need to cancel the |
788 // download that's already in progress to the temporary location. | 788 // download that's already in progress to the temporary location. |
789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 21 matching lines...) Expand all Loading... |
811 | 811 |
812 // The history service has retrieved all download entries. 'entries' contains | 812 // The history service has retrieved all download entries. 'entries' contains |
813 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). | 813 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). |
814 void DownloadManager::OnPersistentStoreQueryComplete( | 814 void DownloadManager::OnPersistentStoreQueryComplete( |
815 std::vector<DownloadPersistentStoreInfo>* entries) { | 815 std::vector<DownloadPersistentStoreInfo>* entries) { |
816 // TODO(rdsmith): Remove this and related logic when | 816 // TODO(rdsmith): Remove this and related logic when |
817 // http://crbug.com/85408 is fixed. | 817 // http://crbug.com/85408 is fixed. |
818 largest_db_handle_in_history_ = 0; | 818 largest_db_handle_in_history_ = 0; |
819 | 819 |
820 for (size_t i = 0; i < entries->size(); ++i) { | 820 for (size_t i = 0; i < entries->size(); ++i) { |
821 DownloadItem* download = new DownloadItem(this, entries->at(i)); | 821 DownloadItem* download = new DownloadItemImpl(this, entries->at(i)); |
822 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 822 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
823 CHECK(!ContainsKey(history_downloads_, download->db_handle())); | 823 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); |
824 downloads_.insert(download); | 824 downloads_.insert(download); |
825 history_downloads_[download->db_handle()] = download; | 825 history_downloads_[download->GetDbHandle()] = download; |
826 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 826 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
827 << " download = " << download->DebugString(true); | 827 << " download = " << download->DebugString(true); |
828 | 828 |
829 if (download->db_handle() > largest_db_handle_in_history_) | 829 if (download->GetDbHandle() > largest_db_handle_in_history_) |
830 largest_db_handle_in_history_ = download->db_handle(); | 830 largest_db_handle_in_history_ = download->GetDbHandle(); |
831 } | 831 } |
832 NotifyModelChanged(); | 832 NotifyModelChanged(); |
833 CheckForHistoryFilesRemoval(); | 833 CheckForHistoryFilesRemoval(); |
834 } | 834 } |
835 | 835 |
836 void DownloadManager::AddDownloadItemToHistory(DownloadItem* download, | 836 void DownloadManager::AddDownloadItemToHistory(DownloadItem* download, |
837 int64 db_handle) { | 837 int64 db_handle) { |
838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
839 | 839 |
840 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408 | 840 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408 |
841 // is fixed. | 841 // is fixed. |
842 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle); | 842 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle); |
843 | 843 |
844 download_stats::RecordHistorySize(history_downloads_.size()); | 844 download_stats::RecordHistorySize(history_downloads_.size()); |
845 | 845 |
846 DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle); | 846 DCHECK(download->GetDbHandle() == DownloadItem::kUninitializedHandle); |
847 download->set_db_handle(db_handle); | 847 download->SetDbHandle(db_handle); |
848 | 848 |
849 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408 | 849 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408 |
850 // is fixed. | 850 // is fixed. |
851 CHECK(!ContainsKey(history_downloads_, download->db_handle())); | 851 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); |
852 history_downloads_[download->db_handle()] = download; | 852 history_downloads_[download->GetDbHandle()] = download; |
853 | 853 |
854 // Show in the appropriate browser UI. | 854 // Show in the appropriate browser UI. |
855 // This includes buttons to save or cancel, for a dangerous download. | 855 // This includes buttons to save or cancel, for a dangerous download. |
856 ShowDownloadInBrowser(download); | 856 ShowDownloadInBrowser(download); |
857 | 857 |
858 // Inform interested objects about the new download. | 858 // Inform interested objects about the new download. |
859 NotifyModelChanged(); | 859 NotifyModelChanged(); |
860 } | 860 } |
861 | 861 |
862 | 862 |
(...skipping 19 matching lines...) Expand all Loading... |
882 | 882 |
883 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle | 883 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle |
884 << " download_id = " << download_id | 884 << " download_id = " << download_id |
885 << " download = " << download->DebugString(true); | 885 << " download = " << download->DebugString(true); |
886 | 886 |
887 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 887 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
888 int64 largest_handle = largest_db_handle_in_history_; | 888 int64 largest_handle = largest_db_handle_in_history_; |
889 base::debug::Alias(&largest_handle); | 889 base::debug::Alias(&largest_handle); |
890 int32 matching_item_download_id | 890 int32 matching_item_download_id |
891 = (ContainsKey(history_downloads_, db_handle) ? | 891 = (ContainsKey(history_downloads_, db_handle) ? |
892 history_downloads_[db_handle]->id() : 0); | 892 history_downloads_[db_handle]->GetId() : 0); |
893 base::debug::Alias(&matching_item_download_id); | 893 base::debug::Alias(&matching_item_download_id); |
894 | 894 |
895 CHECK(!ContainsKey(history_downloads_, db_handle)); | 895 CHECK(!ContainsKey(history_downloads_, db_handle)); |
896 | 896 |
897 AddDownloadItemToHistory(download, db_handle); | 897 AddDownloadItemToHistory(download, db_handle); |
898 | 898 |
899 // If the download is still in progress, try to complete it. | 899 // If the download is still in progress, try to complete it. |
900 // | 900 // |
901 // Otherwise, download has been cancelled or interrupted before we've | 901 // Otherwise, download has been cancelled or interrupted before we've |
902 // received the DB handle. We post one final message to the history | 902 // received the DB handle. We post one final message to the history |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 void DownloadManager::NotifyModelChanged() { | 939 void DownloadManager::NotifyModelChanged() { |
940 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); | 940 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); |
941 } | 941 } |
942 | 942 |
943 DownloadItem* DownloadManager::GetDownloadItem(int download_id) { | 943 DownloadItem* DownloadManager::GetDownloadItem(int download_id) { |
944 // The |history_downloads_| map is indexed by the download's db_handle, | 944 // The |history_downloads_| map is indexed by the download's db_handle, |
945 // not its id, so we have to iterate. | 945 // not its id, so we have to iterate. |
946 for (DownloadMap::iterator it = history_downloads_.begin(); | 946 for (DownloadMap::iterator it = history_downloads_.begin(); |
947 it != history_downloads_.end(); ++it) { | 947 it != history_downloads_.end(); ++it) { |
948 DownloadItem* item = it->second; | 948 DownloadItem* item = it->second; |
949 if (item->id() == download_id) | 949 if (item->GetId() == download_id) |
950 return item; | 950 return item; |
951 } | 951 } |
952 return NULL; | 952 return NULL; |
953 } | 953 } |
954 | 954 |
955 DownloadItem* DownloadManager::GetActiveDownloadItem(int download_id) { | 955 DownloadItem* DownloadManager::GetActiveDownloadItem(int download_id) { |
956 DCHECK(ContainsKey(active_downloads_, download_id)); | 956 DCHECK(ContainsKey(active_downloads_, download_id)); |
957 DownloadItem* download = active_downloads_[download_id]; | 957 DownloadItem* download = active_downloads_[download_id]; |
958 DCHECK(download != NULL); | 958 DCHECK(download != NULL); |
959 return download; | 959 return download; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 std::insert_iterator<DownloadSet> | 998 std::insert_iterator<DownloadSet> |
999 insert_remainder(remainder, remainder.begin()); | 999 insert_remainder(remainder, remainder.begin()); |
1000 std::set_difference(downloads_.begin(), downloads_.end(), | 1000 std::set_difference(downloads_.begin(), downloads_.end(), |
1001 downloads_union.begin(), downloads_union.end(), | 1001 downloads_union.begin(), downloads_union.end(), |
1002 insert_remainder); | 1002 insert_remainder); |
1003 DCHECK(remainder.empty()); | 1003 DCHECK(remainder.empty()); |
1004 #endif | 1004 #endif |
1005 } | 1005 } |
1006 | 1006 |
1007 void DownloadManager::SavePageDownloadStarted(DownloadItem* download) { | 1007 void DownloadManager::SavePageDownloadStarted(DownloadItem* download) { |
1008 DCHECK(!ContainsKey(save_page_downloads_, download->id())); | 1008 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); |
1009 downloads_.insert(download); | 1009 downloads_.insert(download); |
1010 save_page_downloads_[download->id()] = download; | 1010 save_page_downloads_[download->GetId()] = download; |
1011 | 1011 |
1012 // Add this entry to the history service. | 1012 // Add this entry to the history service. |
1013 // Additionally, the UI is notified in the callback. | 1013 // Additionally, the UI is notified in the callback. |
1014 delegate_->AddItemToPersistentStore(download); | 1014 delegate_->AddItemToPersistentStore(download); |
1015 } | 1015 } |
1016 | 1016 |
1017 // SavePackage will call SavePageDownloadFinished upon completion/cancellation. | 1017 // SavePackage will call SavePageDownloadFinished upon completion/cancellation. |
1018 // The history callback will call OnSavePageItemAddedToPersistentStore. | 1018 // The history callback will call OnSavePageItemAddedToPersistentStore. |
1019 // If the download finishes before the history callback, | 1019 // If the download finishes before the history callback, |
1020 // OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring | 1020 // OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring |
(...skipping 29 matching lines...) Expand all Loading... |
1050 CHECK(!ContainsKey(history_downloads_, db_handle)); | 1050 CHECK(!ContainsKey(history_downloads_, db_handle)); |
1051 | 1051 |
1052 AddDownloadItemToHistory(download, db_handle); | 1052 AddDownloadItemToHistory(download, db_handle); |
1053 | 1053 |
1054 // Finalize this download if it finished before the history callback. | 1054 // Finalize this download if it finished before the history callback. |
1055 if (!download->IsInProgress()) | 1055 if (!download->IsInProgress()) |
1056 SavePageDownloadFinished(download); | 1056 SavePageDownloadFinished(download); |
1057 } | 1057 } |
1058 | 1058 |
1059 void DownloadManager::SavePageDownloadFinished(DownloadItem* download) { | 1059 void DownloadManager::SavePageDownloadFinished(DownloadItem* download) { |
1060 if (download->db_handle() != DownloadItem::kUninitializedHandle) { | 1060 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { |
1061 delegate_->UpdateItemInPersistentStore(download); | 1061 delegate_->UpdateItemInPersistentStore(download); |
1062 DCHECK(ContainsKey(save_page_downloads_, download->id())); | 1062 DCHECK(ContainsKey(save_page_downloads_, download->GetId())); |
1063 save_page_downloads_.erase(download->id()); | 1063 save_page_downloads_.erase(download->GetId()); |
1064 | 1064 |
1065 if (download->IsComplete()) | 1065 if (download->IsComplete()) |
1066 content::NotificationService::current()->Notify( | 1066 content::NotificationService::current()->Notify( |
1067 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 1067 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
1068 content::Source<DownloadManager>(this), | 1068 content::Source<DownloadManager>(this), |
1069 content::Details<DownloadItem>(download)); | 1069 content::Details<DownloadItem>(download)); |
1070 } | 1070 } |
1071 } | 1071 } |
1072 | 1072 |
1073 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { | 1073 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { |
1074 delegate_->UpdateItemInPersistentStore(download); | 1074 delegate_->UpdateItemInPersistentStore(download); |
1075 int num_unopened = 0; | 1075 int num_unopened = 0; |
1076 for (DownloadMap::iterator it = history_downloads_.begin(); | 1076 for (DownloadMap::iterator it = history_downloads_.begin(); |
1077 it != history_downloads_.end(); ++it) { | 1077 it != history_downloads_.end(); ++it) { |
1078 if (it->second->IsComplete() && !it->second->opened()) | 1078 if (it->second->IsComplete() && !it->second->GetOpened()) |
1079 ++num_unopened; | 1079 ++num_unopened; |
1080 } | 1080 } |
1081 download_stats::RecordOpensOutstanding(num_unopened); | 1081 download_stats::RecordOpensOutstanding(num_unopened); |
1082 } | 1082 } |
OLD | NEW |