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

Side by Side Diff: content/browser/download/download_manager.cc

Issue 7787002: New checks for observer crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 CHECK(ContainsKey(history_downloads_, download->db_handle())); 401 CHECK(ContainsKey(history_downloads_, download->db_handle()));
402 } else { 402 } else {
403 // TODO(rdsmith): Somewhat painful; make sure to disable in 403 // TODO(rdsmith): Somewhat painful; make sure to disable in
404 // release builds after resolution of http://crbug.com/85408. 404 // release builds after resolution of http://crbug.com/85408.
405 for (DownloadMap::iterator it = history_downloads_.begin(); 405 for (DownloadMap::iterator it = history_downloads_.begin();
406 it != history_downloads_.end(); ++it) { 406 it != history_downloads_.end(); ++it) {
407 CHECK(it->second != download); 407 CHECK(it->second != download);
408 } 408 }
409 } 409 }
410 410
411 int64 state = download->state();
412 base::debug::Alias(&state);
411 if (ContainsKey(active_downloads_, download->id())) 413 if (ContainsKey(active_downloads_, download->id()))
412 CHECK_EQ(DownloadItem::IN_PROGRESS, download->state()); 414 CHECK_EQ(DownloadItem::IN_PROGRESS, download->state());
413 if (DownloadItem::IN_PROGRESS == download->state()) 415 if (DownloadItem::IN_PROGRESS == download->state())
414 CHECK(ContainsKey(active_downloads_, download->id())); 416 CHECK(ContainsKey(active_downloads_, download->id()));
415 } 417 }
416 418
417 bool DownloadManager::IsDownloadReadyForCompletion(DownloadItem* download) { 419 bool DownloadManager::IsDownloadReadyForCompletion(DownloadItem* download) {
418 // If we don't have all the data, the download is not ready for 420 // If we don't have all the data, the download is not ready for
419 // completion. 421 // completion.
420 if (!download->all_data_saved()) 422 if (!download->all_data_saved())
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
836 DownloadItem* download = GetActiveDownloadItem(download_id); 838 DownloadItem* download = GetActiveDownloadItem(download_id);
837 if (!download) 839 if (!download)
838 return; 840 return;
839 841
840 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle 842 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle
841 << " download_id = " << download_id 843 << " download_id = " << download_id
842 << " download = " << download->DebugString(true); 844 << " download = " << download->DebugString(true);
843 845
844 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. 846 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
845 CHECK(!ContainsKey(history_downloads_, download->db_handle()));
846 int64 largest_handle = largest_db_handle_in_history_; 847 int64 largest_handle = largest_db_handle_in_history_;
847 base::debug::Alias(&largest_handle); 848 base::debug::Alias(&largest_handle);
849 CHECK(!ContainsKey(history_downloads_, db_handle));
848 850
849 AddDownloadItemToHistory(download, db_handle); 851 AddDownloadItemToHistory(download, db_handle);
850 852
851 // If the download is still in progress, try to complete it. 853 // If the download is still in progress, try to complete it.
852 // 854 //
853 // Otherwise, download has been cancelled or interrupted before we've 855 // Otherwise, download has been cancelled or interrupted before we've
854 // received the DB handle. We post one final message to the history 856 // received the DB handle. We post one final message to the history
855 // service so that it can be properly in sync with the DownloadItem's 857 // service so that it can be properly in sync with the DownloadItem's
856 // completion status, and also inform any observers so that they get 858 // completion status, and also inform any observers so that they get
857 // more than just the start notification. 859 // more than just the start notification.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 if (it == save_page_downloads_.end()) 993 if (it == save_page_downloads_.end())
992 return; 994 return;
993 995
994 DownloadItem* download = it->second; 996 DownloadItem* download = it->second;
995 if (!download) { 997 if (!download) {
996 NOTREACHED(); 998 NOTREACHED();
997 return; 999 return;
998 } 1000 }
999 1001
1000 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. 1002 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
1001 CHECK(!ContainsKey(history_downloads_, download->db_handle()));
1002 int64 largest_handle = largest_db_handle_in_history_; 1003 int64 largest_handle = largest_db_handle_in_history_;
1003 base::debug::Alias(&largest_handle); 1004 base::debug::Alias(&largest_handle);
1005 CHECK(!ContainsKey(history_downloads_, db_handle));
1004 1006
1005 AddDownloadItemToHistory(download, db_handle); 1007 AddDownloadItemToHistory(download, db_handle);
1006 1008
1007 // Finalize this download if it finished before the history callback. 1009 // Finalize this download if it finished before the history callback.
1008 if (!download->IsInProgress()) 1010 if (!download->IsInProgress())
1009 SavePageDownloadFinished(download); 1011 SavePageDownloadFinished(download);
1010 } 1012 }
1011 1013
1012 void DownloadManager::SavePageDownloadFinished(DownloadItem* download) { 1014 void DownloadManager::SavePageDownloadFinished(DownloadItem* download) {
1013 if (download->db_handle() != DownloadItem::kUninitializedHandle) { 1015 if (download->db_handle() != DownloadItem::kUninitializedHandle) {
1014 delegate_->UpdateItemInPersistentStore(download); 1016 delegate_->UpdateItemInPersistentStore(download);
1015 DCHECK(ContainsKey(save_page_downloads_, download->id())); 1017 DCHECK(ContainsKey(save_page_downloads_, download->id()));
1016 save_page_downloads_.erase(download->id()); 1018 save_page_downloads_.erase(download->id());
1017 1019
1018 if (download->IsComplete()) 1020 if (download->IsComplete())
1019 NotificationService::current()->Notify( 1021 NotificationService::current()->Notify(
1020 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 1022 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
1021 Source<DownloadManager>(this), 1023 Source<DownloadManager>(this),
1022 Details<DownloadItem>(download)); 1024 Details<DownloadItem>(download));
1023 } 1025 }
1024 } 1026 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698