| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 content::DownloadId download_id, | 170 content::DownloadId download_id, |
| 171 const content::DownloadPersistentStoreInfo& info, | 171 const content::DownloadPersistentStoreInfo& info, |
| 172 const net::BoundNetLog& bound_net_log) OVERRIDE { | 172 const net::BoundNetLog& bound_net_log) OVERRIDE { |
| 173 return new DownloadItemImpl(delegate, download_id, info, bound_net_log); | 173 return new DownloadItemImpl(delegate, download_id, info, bound_net_log); |
| 174 } | 174 } |
| 175 | 175 |
| 176 virtual DownloadItemImpl* CreateActiveItem( | 176 virtual DownloadItemImpl* CreateActiveItem( |
| 177 DownloadItemImplDelegate* delegate, | 177 DownloadItemImplDelegate* delegate, |
| 178 const DownloadCreateInfo& info, | 178 const DownloadCreateInfo& info, |
| 179 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 179 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 180 bool is_otr, | |
| 181 const net::BoundNetLog& bound_net_log) OVERRIDE { | 180 const net::BoundNetLog& bound_net_log) OVERRIDE { |
| 182 return new DownloadItemImpl(delegate, info, request_handle.Pass(), | 181 return new DownloadItemImpl(delegate, info, request_handle.Pass(), |
| 183 is_otr, bound_net_log); | 182 bound_net_log); |
| 184 } | 183 } |
| 185 | 184 |
| 186 virtual DownloadItemImpl* CreateSavePageItem( | 185 virtual DownloadItemImpl* CreateSavePageItem( |
| 187 DownloadItemImplDelegate* delegate, | 186 DownloadItemImplDelegate* delegate, |
| 188 const FilePath& path, | 187 const FilePath& path, |
| 189 const GURL& url, | 188 const GURL& url, |
| 190 bool is_otr, | |
| 191 content::DownloadId download_id, | 189 content::DownloadId download_id, |
| 192 const std::string& mime_type, | 190 const std::string& mime_type, |
| 193 const net::BoundNetLog& bound_net_log) OVERRIDE { | 191 const net::BoundNetLog& bound_net_log) OVERRIDE { |
| 194 return new DownloadItemImpl(delegate, path, url, is_otr, download_id, | 192 return new DownloadItemImpl(delegate, path, url, download_id, |
| 195 mime_type, bound_net_log); | 193 mime_type, bound_net_log); |
| 196 } | 194 } |
| 197 }; | 195 }; |
| 198 | 196 |
| 199 } // namespace | 197 } // namespace |
| 200 | 198 |
| 201 namespace content { | 199 namespace content { |
| 202 | 200 |
| 203 bool DownloadManager::EnsureNoPendingDownloadsForTesting() { | 201 bool DownloadManager::EnsureNoPendingDownloadsForTesting() { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 368 } |
| 371 } | 369 } |
| 372 | 370 |
| 373 void DownloadManagerImpl::SearchDownloads(const string16& query, | 371 void DownloadManagerImpl::SearchDownloads(const string16& query, |
| 374 DownloadVector* result) { | 372 DownloadVector* result) { |
| 375 string16 query_lower(base::i18n::ToLower(query)); | 373 string16 query_lower(base::i18n::ToLower(query)); |
| 376 | 374 |
| 377 for (DownloadMap::iterator it = downloads_.begin(); | 375 for (DownloadMap::iterator it = downloads_.begin(); |
| 378 it != downloads_.end(); ++it) { | 376 it != downloads_.end(); ++it) { |
| 379 DownloadItemImpl* download_item = it->second; | 377 DownloadItemImpl* download_item = it->second; |
| 380 // Display Incognito downloads only in Incognito window, and vice versa. | |
| 381 // The Incognito Downloads page will get the list of non-Incognito downloads | |
| 382 // from its parent profile. | |
| 383 // TODO(benjhayden): Don't check IsPersisted(). | 378 // TODO(benjhayden): Don't check IsPersisted(). |
| 384 if (!download_item->IsTemporary() && | 379 if (!download_item->IsTemporary() && |
| 385 download_item->IsPersisted() && | 380 download_item->IsPersisted() && |
| 386 (browser_context_->IsOffTheRecord() == download_item->IsOtr()) && | |
| 387 download_item->MatchesQuery(query_lower)) { | 381 download_item->MatchesQuery(query_lower)) { |
| 388 result->push_back(download_item); | 382 result->push_back(download_item); |
| 389 } | 383 } |
| 390 } | 384 } |
| 391 } | 385 } |
| 392 | 386 |
| 393 bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) { | 387 bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) { |
| 394 DCHECK(browser_context); | 388 DCHECK(browser_context); |
| 395 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; | 389 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; |
| 396 shutdown_needed_ = true; | 390 shutdown_needed_ = true; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 528 | 522 |
| 529 net::BoundNetLog bound_net_log = | 523 net::BoundNetLog bound_net_log = |
| 530 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 524 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
| 531 if (!info->download_id.IsValid()) | 525 if (!info->download_id.IsValid()) |
| 532 info->download_id = GetNextId(); | 526 info->download_id = GetNextId(); |
| 533 DownloadItemImpl* download = factory_->CreateActiveItem( | 527 DownloadItemImpl* download = factory_->CreateActiveItem( |
| 534 this, *info, | 528 this, *info, |
| 535 scoped_ptr<DownloadRequestHandleInterface>( | 529 scoped_ptr<DownloadRequestHandleInterface>( |
| 536 new DownloadRequestHandle(info->request_handle)).Pass(), | 530 new DownloadRequestHandle(info->request_handle)).Pass(), |
| 537 browser_context_->IsOffTheRecord(), bound_net_log); | 531 bound_net_log); |
| 538 | 532 |
| 539 DCHECK(!ContainsKey(downloads_, download->GetId())); | 533 DCHECK(!ContainsKey(downloads_, download->GetId())); |
| 540 downloads_[download->GetId()] = download; | 534 downloads_[download->GetId()] = download; |
| 541 DCHECK(!ContainsKey(active_downloads_, download->GetId())); | 535 DCHECK(!ContainsKey(active_downloads_, download->GetId())); |
| 542 active_downloads_[download->GetId()] = download; | 536 active_downloads_[download->GetId()] = download; |
| 543 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); | 537 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
| 544 | 538 |
| 545 return bound_net_log; | 539 return bound_net_log; |
| 546 } | 540 } |
| 547 | 541 |
| 548 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( | 542 DownloadItemImpl* DownloadManagerImpl::CreateSavePackageDownloadItem( |
| 549 const FilePath& main_file_path, | 543 const FilePath& main_file_path, |
| 550 const GURL& page_url, | 544 const GURL& page_url, |
| 551 bool is_otr, | |
| 552 const std::string& mime_type, | 545 const std::string& mime_type, |
| 553 DownloadItem::Observer* observer) { | 546 DownloadItem::Observer* observer) { |
| 554 net::BoundNetLog bound_net_log = | 547 net::BoundNetLog bound_net_log = |
| 555 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 548 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
| 556 DownloadItemImpl* download = factory_->CreateSavePageItem( | 549 DownloadItemImpl* download = factory_->CreateSavePageItem( |
| 557 this, | 550 this, |
| 558 main_file_path, | 551 main_file_path, |
| 559 page_url, | 552 page_url, |
| 560 is_otr, | |
| 561 GetNextId(), | 553 GetNextId(), |
| 562 mime_type, | 554 mime_type, |
| 563 bound_net_log); | 555 bound_net_log); |
| 564 | 556 |
| 565 download->AddObserver(observer); | 557 download->AddObserver(observer); |
| 566 | 558 |
| 567 DCHECK(!ContainsKey(downloads_, download->GetId())); | 559 DCHECK(!ContainsKey(downloads_, download->GetId())); |
| 568 downloads_[download->GetId()] = download; | 560 downloads_[download->GetId()] = download; |
| 569 DCHECK(!SavePageExternalData::Get(download)); | 561 DCHECK(!SavePageExternalData::Get(download)); |
| 570 new SavePageExternalData(download); | 562 new SavePageExternalData(download); |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1107 void DownloadManagerImpl::DownloadRenamedToFinalName( |
| 1116 DownloadItemImpl* download) { | 1108 DownloadItemImpl* download) { |
| 1117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1118 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1110 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1119 // receive the DownloadRenamedToFinalName() call. | 1111 // receive the DownloadRenamedToFinalName() call. |
| 1120 if (delegate_) { | 1112 if (delegate_) { |
| 1121 delegate_->UpdatePathForItemInPersistentStore( | 1113 delegate_->UpdatePathForItemInPersistentStore( |
| 1122 download, download->GetFullPath()); | 1114 download, download->GetFullPath()); |
| 1123 } | 1115 } |
| 1124 } | 1116 } |
| OLD | NEW |