| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "content/browser/download/download_manager_impl.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" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Allow copy and assign. | 109 // Allow copy and assign. |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 namespace content { | 114 namespace content { |
| 115 | 115 |
| 116 // static | 116 // static |
| 117 DownloadManager* DownloadManager::Create( | 117 DownloadManager* DownloadManager::Create( |
| 118 content::DownloadManagerDelegate* delegate, | 118 content::DownloadManagerDelegate* delegate, |
| 119 DownloadStatusUpdater* status_updater) { | 119 DownloadStatusUpdater* status_updater, |
| 120 return new DownloadManagerImpl(delegate, status_updater); | 120 net::NetLog* net_log) { |
| 121 return new DownloadManagerImpl(delegate, status_updater, net_log); |
| 121 } | 122 } |
| 122 | 123 |
| 123 } // namespace content | 124 } // namespace content |
| 124 | 125 |
| 125 DownloadManagerImpl::DownloadManagerImpl( | 126 DownloadManagerImpl::DownloadManagerImpl( |
| 126 content::DownloadManagerDelegate* delegate, | 127 content::DownloadManagerDelegate* delegate, |
| 127 DownloadStatusUpdater* status_updater) | 128 DownloadStatusUpdater* status_updater, |
| 129 net::NetLog* net_log) |
| 128 : shutdown_needed_(false), | 130 : shutdown_needed_(false), |
| 129 browser_context_(NULL), | 131 browser_context_(NULL), |
| 130 file_manager_(NULL), | 132 file_manager_(NULL), |
| 131 status_updater_((status_updater != NULL) | 133 status_updater_((status_updater != NULL) |
| 132 ? status_updater->AsWeakPtr() | 134 ? status_updater->AsWeakPtr() |
| 133 : base::WeakPtr<DownloadStatusUpdater>()), | 135 : base::WeakPtr<DownloadStatusUpdater>()), |
| 134 delegate_(delegate), | 136 delegate_(delegate), |
| 135 largest_db_handle_in_history_(DownloadItem::kUninitializedHandle) { | 137 largest_db_handle_in_history_(DownloadItem::kUninitializedHandle), |
| 138 net_log_(net_log) { |
| 136 // NOTE(benjhayden): status_updater may be NULL when using | 139 // NOTE(benjhayden): status_updater may be NULL when using |
| 137 // TestingBrowserProcess. | 140 // TestingBrowserProcess. |
| 138 if (status_updater_.get() != NULL) | 141 if (status_updater_.get() != NULL) |
| 139 status_updater_->AddDelegate(this); | 142 status_updater_->AddDelegate(this); |
| 140 } | 143 } |
| 141 | 144 |
| 142 DownloadManagerImpl::~DownloadManagerImpl() { | 145 DownloadManagerImpl::~DownloadManagerImpl() { |
| 143 DCHECK(!shutdown_needed_); | 146 DCHECK(!shutdown_needed_); |
| 144 } | 147 } |
| 145 | 148 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 downloads_.insert(download); | 407 downloads_.insert(download); |
| 405 active_downloads_[download_id] = download; | 408 active_downloads_[download_id] = download; |
| 406 } | 409 } |
| 407 | 410 |
| 408 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem( | 411 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem( |
| 409 const FilePath& main_file_path, | 412 const FilePath& main_file_path, |
| 410 const GURL& page_url, | 413 const GURL& page_url, |
| 411 bool is_otr, | 414 bool is_otr, |
| 412 DownloadItem::Observer* observer) { | 415 DownloadItem::Observer* observer) { |
| 413 DownloadItem* download = new DownloadItemImpl( | 416 DownloadItem* download = new DownloadItemImpl( |
| 414 this, main_file_path, page_url, is_otr, GetNextId(), NULL); | 417 this, main_file_path, page_url, is_otr, GetNextId(), GetNetLog()); |
| 415 | 418 |
| 416 download->AddObserver(observer); | 419 download->AddObserver(observer); |
| 417 | 420 |
| 418 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); | 421 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); |
| 419 downloads_.insert(download); | 422 downloads_.insert(download); |
| 420 save_page_downloads_[download->GetId()] = download; | 423 save_page_downloads_[download->GetId()] = download; |
| 421 | 424 |
| 422 // Will notify the observer in the callback. | 425 // Will notify the observer in the callback. |
| 423 delegate_->AddItemToPersistentStore(download); | 426 delegate_->AddItemToPersistentStore(download); |
| 424 | 427 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 // The history service has retrieved all download entries. 'entries' contains | 945 // The history service has retrieved all download entries. 'entries' contains |
| 943 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). | 946 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). |
| 944 void DownloadManagerImpl::OnPersistentStoreQueryComplete( | 947 void DownloadManagerImpl::OnPersistentStoreQueryComplete( |
| 945 std::vector<DownloadPersistentStoreInfo>* entries) { | 948 std::vector<DownloadPersistentStoreInfo>* entries) { |
| 946 // TODO(rdsmith): Remove this and related logic when | 949 // TODO(rdsmith): Remove this and related logic when |
| 947 // http://crbug.com/96627 is fixed. | 950 // http://crbug.com/96627 is fixed. |
| 948 largest_db_handle_in_history_ = 0; | 951 largest_db_handle_in_history_ = 0; |
| 949 | 952 |
| 950 for (size_t i = 0; i < entries->size(); ++i) { | 953 for (size_t i = 0; i < entries->size(); ++i) { |
| 951 DownloadItem* download = new DownloadItemImpl( | 954 DownloadItem* download = new DownloadItemImpl( |
| 952 this, GetNextId(), entries->at(i), NULL); | 955 this, GetNextId(), entries->at(i), GetNetLog()); |
| 953 CHECK_96627(!ContainsKey(history_downloads_, download->GetDbHandle())); | 956 CHECK_96627(!ContainsKey(history_downloads_, download->GetDbHandle())); |
| 954 downloads_.insert(download); | 957 downloads_.insert(download); |
| 955 history_downloads_[download->GetDbHandle()] = download; | 958 history_downloads_[download->GetDbHandle()] = download; |
| 956 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 959 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
| 957 << " download = " << download->DebugString(true); | 960 << " download = " << download->DebugString(true); |
| 958 | 961 |
| 959 if (download->GetDbHandle() > largest_db_handle_in_history_) | 962 if (download->GetDbHandle() > largest_db_handle_in_history_) |
| 960 largest_db_handle_in_history_ = download->GetDbHandle(); | 963 largest_db_handle_in_history_ = download->GetDbHandle(); |
| 961 } | 964 } |
| 962 NotifyModelChanged(); | 965 NotifyModelChanged(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 it != history_downloads_.end(); ++it) { | 1203 it != history_downloads_.end(); ++it) { |
| 1201 if (it->second->IsComplete() && !it->second->GetOpened()) | 1204 if (it->second->IsComplete() && !it->second->GetOpened()) |
| 1202 ++num_unopened; | 1205 ++num_unopened; |
| 1203 } | 1206 } |
| 1204 download_stats::RecordOpensOutstanding(num_unopened); | 1207 download_stats::RecordOpensOutstanding(num_unopened); |
| 1205 } | 1208 } |
| 1206 | 1209 |
| 1207 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1210 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
| 1208 file_manager_ = file_manager; | 1211 file_manager_ = file_manager; |
| 1209 } | 1212 } |
| 1213 |
| 1214 net::NetLog* DownloadManagerImpl::GetNetLog() { |
| 1215 return net_log_; |
| 1216 } |
| OLD | NEW |