| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 upload_data->set_identifier(params->post_id()); | 101 upload_data->set_identifier(params->post_id()); |
| 102 request->set_upload(upload_data); | 102 request->set_upload(upload_data); |
| 103 } | 103 } |
| 104 for (content::DownloadUrlParameters::RequestHeadersType::const_iterator iter | 104 for (content::DownloadUrlParameters::RequestHeadersType::const_iterator iter |
| 105 = params->request_headers_begin(); | 105 = params->request_headers_begin(); |
| 106 iter != params->request_headers_end(); | 106 iter != params->request_headers_end(); |
| 107 ++iter) { | 107 ++iter) { |
| 108 request->SetExtraRequestHeaderByName( | 108 request->SetExtraRequestHeaderByName( |
| 109 iter->first, iter->second, false/*overwrite*/); | 109 iter->first, iter->second, false/*overwrite*/); |
| 110 } | 110 } |
| 111 LOG(INFO) << "occam " << __FUNCTION__; |
| 111 params->resource_dispatcher_host()->BeginDownload( | 112 params->resource_dispatcher_host()->BeginDownload( |
| 112 request.Pass(), | 113 request.Pass(), |
| 113 params->content_initiated(), | 114 params->content_initiated(), |
| 114 params->resource_context(), | 115 params->resource_context(), |
| 115 params->render_process_host_id(), | 116 params->render_process_host_id(), |
| 116 params->render_view_host_routing_id(), | 117 params->render_view_host_routing_id(), |
| 117 params->prefer_cache(), | 118 params->prefer_cache(), |
| 118 params->save_info(), | 119 params->save_info(), |
| 119 params->callback()); | 120 params->callback()); |
| 120 } | 121 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 browser_context_ = browser_context; | 394 browser_context_ = browser_context; |
| 394 | 395 |
| 395 return true; | 396 return true; |
| 396 } | 397 } |
| 397 | 398 |
| 398 // We have received a message from DownloadFileManager about a new download. | 399 // We have received a message from DownloadFileManager about a new download. |
| 399 content::DownloadId DownloadManagerImpl::StartDownload( | 400 content::DownloadId DownloadManagerImpl::StartDownload( |
| 400 scoped_ptr<DownloadCreateInfo> info, | 401 scoped_ptr<DownloadCreateInfo> info, |
| 401 scoped_ptr<content::ByteStreamReader> stream) { | 402 scoped_ptr<content::ByteStreamReader> stream) { |
| 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 404 LOG(INFO) << "occam " << __FUNCTION__; |
| 403 | 405 |
| 404 // |bound_net_log| will be used for logging both the download item's and | 406 // |bound_net_log| will be used for logging both the download item's and |
| 405 // the download file's events. | 407 // the download file's events. |
| 406 net::BoundNetLog bound_net_log = CreateDownloadItem(info.get()); | 408 net::BoundNetLog bound_net_log = CreateDownloadItem(info.get()); |
| 407 | 409 |
| 408 // If info->download_id was unknown on entry to this function, it was | 410 // If info->download_id was unknown on entry to this function, it was |
| 409 // assigned in CreateDownloadItem. | 411 // assigned in CreateDownloadItem. |
| 410 DownloadId download_id = info->download_id; | 412 DownloadId download_id = info->download_id; |
| 411 | 413 |
| 412 DownloadFileManager::CreateDownloadFileCallback callback( | 414 DownloadFileManager::CreateDownloadFileCallback callback( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 519 } |
| 518 | 520 |
| 519 net::BoundNetLog DownloadManagerImpl::CreateDownloadItem( | 521 net::BoundNetLog DownloadManagerImpl::CreateDownloadItem( |
| 520 DownloadCreateInfo* info) { | 522 DownloadCreateInfo* info) { |
| 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 522 | 524 |
| 523 net::BoundNetLog bound_net_log = | 525 net::BoundNetLog bound_net_log = |
| 524 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 526 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
| 525 if (!info->download_id.IsValid()) | 527 if (!info->download_id.IsValid()) |
| 526 info->download_id = GetNextId(); | 528 info->download_id = GetNextId(); |
| 529 LOG(INFO) << "occam " << __FUNCTION__ << " " << info->download_id; |
| 527 DownloadItemImpl* download = factory_->CreateActiveItem( | 530 DownloadItemImpl* download = factory_->CreateActiveItem( |
| 528 this, *info, | 531 this, *info, |
| 529 scoped_ptr<DownloadRequestHandleInterface>( | 532 scoped_ptr<DownloadRequestHandleInterface>( |
| 530 new DownloadRequestHandle(info->request_handle)).Pass(), | 533 new DownloadRequestHandle(info->request_handle)).Pass(), |
| 531 browser_context_->IsOffTheRecord(), bound_net_log); | 534 browser_context_->IsOffTheRecord(), bound_net_log); |
| 532 | 535 |
| 533 DCHECK(!ContainsKey(downloads_, download->GetId())); | 536 DCHECK(!ContainsKey(downloads_, download->GetId())); |
| 534 downloads_[download->GetId()] = download; | 537 downloads_[download->GetId()] = download; |
| 535 DCHECK(!ContainsKey(active_downloads_, download->GetId())); | 538 DCHECK(!ContainsKey(active_downloads_, download->GetId())); |
| 536 active_downloads_[download->GetId()] = download; | 539 active_downloads_[download->GetId()] = download; |
| 540 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
| 537 | 541 |
| 538 return bound_net_log; | 542 return bound_net_log; |
| 539 } | 543 } |
| 540 | 544 |
| 541 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( | 545 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( |
| 542 const FilePath& main_file_path, | 546 const FilePath& main_file_path, |
| 543 const GURL& page_url, | 547 const GURL& page_url, |
| 544 bool is_otr, | 548 bool is_otr, |
| 545 const std::string& mime_type, | 549 const std::string& mime_type, |
| 546 DownloadItem::Observer* observer) { | 550 DownloadItem::Observer* observer) { |
| 547 net::BoundNetLog bound_net_log = | 551 net::BoundNetLog bound_net_log = |
| 548 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 552 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
| 549 DownloadItemImpl* download = factory_->CreateSavePageItem( | 553 DownloadItemImpl* download = factory_->CreateSavePageItem( |
| 550 this, | 554 this, |
| 551 main_file_path, | 555 main_file_path, |
| 552 page_url, | 556 page_url, |
| 553 is_otr, | 557 is_otr, |
| 554 GetNextId(), | 558 GetNextId(), |
| 555 mime_type, | 559 mime_type, |
| 556 bound_net_log); | 560 bound_net_log); |
| 557 | 561 |
| 558 download->AddObserver(observer); | 562 download->AddObserver(observer); |
| 559 | 563 |
| 560 DCHECK(!ContainsKey(downloads_, download->GetId())); | 564 DCHECK(!ContainsKey(downloads_, download->GetId())); |
| 561 downloads_[download->GetId()] = download; | 565 downloads_[download->GetId()] = download; |
| 562 DCHECK(!SavePageExternalData::Get(download)); | 566 DCHECK(!SavePageExternalData::Get(download)); |
| 563 new SavePageExternalData(download); | 567 new SavePageExternalData(download); |
| 564 DCHECK(SavePageExternalData::Get(download)); | 568 DCHECK(SavePageExternalData::Get(download)); |
| 565 | 569 |
| 570 // TODO(benjhayden): Fire OnDownloadCreated for SavePackage downloads when |
| 571 // we're comfortable with the user interacting with them. |
| 572 // FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
| 573 |
| 566 // Will notify the observer in the callback. | 574 // Will notify the observer in the callback. |
| 567 if (delegate_) | 575 if (delegate_) |
| 568 delegate_->AddItemToPersistentStore(download); | 576 delegate_->AddItemToPersistentStore(download); |
| 569 | 577 |
| 570 return download; | 578 return download; |
| 571 } | 579 } |
| 572 | 580 |
| 573 // The target path for the download item is now valid. We proceed with the | 581 // The target path for the download item is now valid. We proceed with the |
| 574 // determination of an intermediate path. | 582 // determination of an intermediate path. |
| 575 void DownloadManagerImpl::OnTargetPathAvailable(DownloadItemImpl* download) { | 583 void DownloadManagerImpl::OnTargetPathAvailable(DownloadItemImpl* download) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 for (size_t i = 0; i < entries->size(); ++i) { | 948 for (size_t i = 0; i < entries->size(); ++i) { |
| 941 int64 db_handle = entries->at(i).db_handle; | 949 int64 db_handle = entries->at(i).db_handle; |
| 942 base::debug::Alias(&db_handle); | 950 base::debug::Alias(&db_handle); |
| 943 | 951 |
| 944 net::BoundNetLog bound_net_log = | 952 net::BoundNetLog bound_net_log = |
| 945 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 953 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
| 946 DownloadItemImpl* download = factory_->CreatePersistedItem( | 954 DownloadItemImpl* download = factory_->CreatePersistedItem( |
| 947 this, GetNextId(), entries->at(i), bound_net_log); | 955 this, GetNextId(), entries->at(i), bound_net_log); |
| 948 DCHECK(!ContainsKey(downloads_, download->GetId())); | 956 DCHECK(!ContainsKey(downloads_, download->GetId())); |
| 949 downloads_[download->GetId()] = download; | 957 downloads_[download->GetId()] = download; |
| 958 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
| 950 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 959 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
| 951 << " download = " << download->DebugString(true); | 960 << " download = " << download->DebugString(true); |
| 952 } | 961 } |
| 953 NotifyModelChanged(); | 962 NotifyModelChanged(); |
| 954 CheckForHistoryFilesRemoval(); | 963 CheckForHistoryFilesRemoval(); |
| 955 } | 964 } |
| 956 | 965 |
| 957 void DownloadManagerImpl::AddDownloadItemToHistory(DownloadItemImpl* download, | 966 void DownloadManagerImpl::AddDownloadItemToHistory(DownloadItemImpl* download, |
| 958 int64 db_handle) { | 967 int64 db_handle) { |
| 959 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1178 void DownloadManagerImpl::DownloadRenamedToFinalName( |
| 1170 DownloadItemImpl* download) { | 1179 DownloadItemImpl* download) { |
| 1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1172 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1181 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1173 // receive the DownloadRenamedToFinalName() call. | 1182 // receive the DownloadRenamedToFinalName() call. |
| 1174 if (delegate_) { | 1183 if (delegate_) { |
| 1175 delegate_->UpdatePathForItemInPersistentStore( | 1184 delegate_->UpdatePathForItemInPersistentStore( |
| 1176 download, download->GetFullPath()); | 1185 download, download->GetFullPath()); |
| 1177 } | 1186 } |
| 1178 } | 1187 } |
| OLD | NEW |