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

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

Issue 11363222: Persist download interrupt reason, both target and current paths, and url_chain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed ordering of target_path and current_path everywhere to match that of DownloadItemImpl. Created 8 years 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
OLDNEW
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 137
138 class DownloadItemFactoryImpl : public DownloadItemFactory { 138 class DownloadItemFactoryImpl : public DownloadItemFactory {
139 public: 139 public:
140 DownloadItemFactoryImpl() {} 140 DownloadItemFactoryImpl() {}
141 virtual ~DownloadItemFactoryImpl() {} 141 virtual ~DownloadItemFactoryImpl() {}
142 142
143 virtual DownloadItemImpl* CreatePersistedItem( 143 virtual DownloadItemImpl* CreatePersistedItem(
144 DownloadItemImplDelegate* delegate, 144 DownloadItemImplDelegate* delegate,
145 DownloadId download_id, 145 DownloadId download_id,
146 const FilePath& path, 146 const FilePath& current_path,
147 const GURL& url, 147 const FilePath& target_path,
148 const std::vector<GURL>& url_chain,
148 const GURL& referrer_url, 149 const GURL& referrer_url,
149 const base::Time& start_time, 150 const base::Time& start_time,
150 const base::Time& end_time, 151 const base::Time& end_time,
151 int64 received_bytes, 152 int64 received_bytes,
152 int64 total_bytes, 153 int64 total_bytes,
153 DownloadItem::DownloadState state, 154 DownloadItem::DownloadState state,
155 DownloadInterruptReason interrupt_reason,
154 bool opened, 156 bool opened,
155 const net::BoundNetLog& bound_net_log) OVERRIDE { 157 const net::BoundNetLog& bound_net_log) OVERRIDE {
156 return new DownloadItemImpl( 158 return new DownloadItemImpl(
157 delegate, 159 delegate,
158 download_id, 160 download_id,
159 path, 161 current_path,
160 url, 162 target_path,
163 url_chain,
161 referrer_url, 164 referrer_url,
162 start_time, 165 start_time,
163 end_time, 166 end_time,
164 received_bytes, 167 received_bytes,
165 total_bytes, 168 total_bytes,
166 state, 169 state,
170 interrupt_reason,
167 opened, 171 opened,
168 bound_net_log); 172 bound_net_log);
169 } 173 }
170 174
171 virtual DownloadItemImpl* CreateActiveItem( 175 virtual DownloadItemImpl* CreateActiveItem(
172 DownloadItemImplDelegate* delegate, 176 DownloadItemImplDelegate* delegate,
173 const DownloadCreateInfo& info, 177 const DownloadCreateInfo& info,
174 scoped_ptr<DownloadRequestHandleInterface> request_handle, 178 scoped_ptr<DownloadRequestHandleInterface> request_handle,
175 const net::BoundNetLog& bound_net_log) OVERRIDE { 179 const net::BoundNetLog& bound_net_log) OVERRIDE {
176 return new DownloadItemImpl(delegate, info, request_handle.Pass(), 180 return new DownloadItemImpl(delegate, info, request_handle.Pass(),
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 FilePath website_save_directory; // Unused 349 FilePath website_save_directory; // Unused
346 bool skip_dir_check = false; // Unused 350 bool skip_dir_check = false; // Unused
347 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, 351 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory,
348 &default_download_directory, &skip_dir_check); 352 &default_download_directory, &skip_dir_check);
349 } 353 }
350 354
351 // We create the DownloadItem before the DownloadFile because the 355 // We create the DownloadItem before the DownloadFile because the
352 // DownloadItem already needs to handle a state in which there is 356 // DownloadItem already needs to handle a state in which there is
353 // no associated DownloadFile (history downloads, !IN_PROGRESS downloads) 357 // no associated DownloadFile (history downloads, !IN_PROGRESS downloads)
354 DownloadItemImpl* download = 358 DownloadItemImpl* download =
355 CreateDownloadItem(info.get(), bound_net_log); 359 CreateDownloadItemInternal(info.get(), bound_net_log);
356 scoped_ptr<DownloadFile> download_file( 360 scoped_ptr<DownloadFile> download_file(
357 file_factory_->CreateFile( 361 file_factory_->CreateFile(
358 info->save_info.Pass(), default_download_directory, 362 info->save_info.Pass(), default_download_directory,
359 info->url(), info->referrer_url, 363 info->url(), info->referrer_url,
360 delegate_->GenerateFileHash(), 364 delegate_->GenerateFileHash(),
361 stream.Pass(), bound_net_log, 365 stream.Pass(), bound_net_log,
362 download->DestinationObserverAsWeakPtr())); 366 download->DestinationObserverAsWeakPtr()));
363 download->Start(download_file.Pass()); 367 download->Start(download_file.Pass());
364 368
365 // Delay notification until after Start() so that download_file is bound 369 // Delay notification until after Start() so that download_file is bound
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 void DownloadManagerImpl::OnFileRemovalDetected(int32 download_id) { 409 void DownloadManagerImpl::OnFileRemovalDetected(int32 download_id) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
407 if (ContainsKey(downloads_, download_id)) 411 if (ContainsKey(downloads_, download_id))
408 downloads_[download_id]->OnDownloadedFileRemoved(); 412 downloads_[download_id]->OnDownloadedFileRemoved();
409 } 413 }
410 414
411 BrowserContext* DownloadManagerImpl::GetBrowserContext() const { 415 BrowserContext* DownloadManagerImpl::GetBrowserContext() const {
412 return browser_context_; 416 return browser_context_;
413 } 417 }
414 418
415 DownloadItemImpl* DownloadManagerImpl::CreateDownloadItem( 419 DownloadItemImpl* DownloadManagerImpl::CreateDownloadItemInternal(
416 DownloadCreateInfo* info, const net::BoundNetLog& bound_net_log) { 420 DownloadCreateInfo* info, const net::BoundNetLog& bound_net_log) {
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
418 422
419 if (!info->download_id.IsValid()) 423 if (!info->download_id.IsValid())
420 info->download_id = GetNextId(); 424 info->download_id = GetNextId();
421 DownloadItemImpl* download = item_factory_->CreateActiveItem( 425 DownloadItemImpl* download = item_factory_->CreateActiveItem(
422 this, *info, 426 this, *info,
423 scoped_ptr<DownloadRequestHandleInterface>( 427 scoped_ptr<DownloadRequestHandleInterface>(
424 new DownloadRequestHandle(info->request_handle)).Pass(), 428 new DownloadRequestHandle(info->request_handle)).Pass(),
425 bound_net_log); 429 bound_net_log);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 551
548 void DownloadManagerImpl::AddObserver(Observer* observer) { 552 void DownloadManagerImpl::AddObserver(Observer* observer) {
549 observers_.AddObserver(observer); 553 observers_.AddObserver(observer);
550 } 554 }
551 555
552 void DownloadManagerImpl::RemoveObserver(Observer* observer) { 556 void DownloadManagerImpl::RemoveObserver(Observer* observer) {
553 observers_.RemoveObserver(observer); 557 observers_.RemoveObserver(observer);
554 } 558 }
555 559
556 DownloadItem* DownloadManagerImpl::CreateDownloadItem( 560 DownloadItem* DownloadManagerImpl::CreateDownloadItem(
557 const FilePath& path, 561 const FilePath& current_path,
558 const GURL& url, 562 const FilePath& target_path,
563 const std::vector<GURL>& url_chain,
559 const GURL& referrer_url, 564 const GURL& referrer_url,
560 const base::Time& start_time, 565 const base::Time& start_time,
561 const base::Time& end_time, 566 const base::Time& end_time,
562 int64 received_bytes, 567 int64 received_bytes,
563 int64 total_bytes, 568 int64 total_bytes,
564 DownloadItem::DownloadState state, 569 DownloadItem::DownloadState state,
570 DownloadInterruptReason interrupt_reason,
565 bool opened) { 571 bool opened) {
566 DownloadItemImpl* item = item_factory_->CreatePersistedItem( 572 DownloadItemImpl* item = item_factory_->CreatePersistedItem(
567 this, 573 this,
568 GetNextId(), 574 GetNextId(),
569 path, 575 current_path,
570 url, 576 target_path,
577 url_chain,
571 referrer_url, 578 referrer_url,
572 start_time, 579 start_time,
573 end_time, 580 end_time,
574 received_bytes, 581 received_bytes,
575 total_bytes, 582 total_bytes,
576 state, 583 state,
584 interrupt_reason,
577 opened, 585 opened,
578 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); 586 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD));
579 DCHECK(!ContainsKey(downloads_, item->GetId())); 587 DCHECK(!ContainsKey(downloads_, item->GetId()));
580 downloads_[item->GetId()] = item; 588 downloads_[item->GetId()] = item;
581 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); 589 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item));
582 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); 590 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true);
583 return item; 591 return item;
584 } 592 }
585 593
586 // TODO(asanka) Move into an observer. 594 // TODO(asanka) Move into an observer.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 it != downloads_.end(); ++it) { 633 it != downloads_.end(); ++it) {
626 DownloadItemImpl* item = it->second; 634 DownloadItemImpl* item = it->second;
627 if (item->IsComplete() && 635 if (item->IsComplete() &&
628 !item->GetOpened()) 636 !item->GetOpened())
629 ++num_unopened; 637 ++num_unopened;
630 } 638 }
631 RecordOpensOutstanding(num_unopened); 639 RecordOpensOutstanding(num_unopened);
632 } 640 }
633 641
634 } // namespace content 642 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698