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

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

Issue 11941015: Move OpenItem/ShowItemInFolder from ContentBrowserClient to DownloadManagerDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 7 years, 11 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
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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 end_time_(end_time), 142 end_time_(end_time),
143 delegate_(delegate), 143 delegate_(delegate),
144 is_paused_(false), 144 is_paused_(false),
145 auto_resume_count_(0), 145 auto_resume_count_(0),
146 open_when_complete_(false), 146 open_when_complete_(false),
147 file_externally_removed_(false), 147 file_externally_removed_(false),
148 auto_opened_(false), 148 auto_opened_(false),
149 is_temporary_(false), 149 is_temporary_(false),
150 all_data_saved_(false), 150 all_data_saved_(false),
151 opened_(opened), 151 opened_(opened),
152 open_enabled_(true),
153 delegate_delayed_complete_(false), 152 delegate_delayed_complete_(false),
154 bound_net_log_(bound_net_log), 153 bound_net_log_(bound_net_log),
155 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 154 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
156 delegate_->Attach(); 155 delegate_->Attach();
157 if (state_ == IN_PROGRESS_INTERNAL) 156 if (state_ == IN_PROGRESS_INTERNAL)
158 state_ = CANCELLED_INTERNAL; 157 state_ = CANCELLED_INTERNAL;
159 if (state_ == COMPLETE_INTERNAL) 158 if (state_ == COMPLETE_INTERNAL)
160 all_data_saved_ = true; 159 all_data_saved_ = true;
161 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); 160 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT);
162 } 161 }
(...skipping 28 matching lines...) Expand all
191 start_time_(info.start_time), 190 start_time_(info.start_time),
192 delegate_(delegate), 191 delegate_(delegate),
193 is_paused_(false), 192 is_paused_(false),
194 auto_resume_count_(0), 193 auto_resume_count_(0),
195 open_when_complete_(false), 194 open_when_complete_(false),
196 file_externally_removed_(false), 195 file_externally_removed_(false),
197 auto_opened_(false), 196 auto_opened_(false),
198 is_temporary_(!info.save_info->file_path.empty()), 197 is_temporary_(!info.save_info->file_path.empty()),
199 all_data_saved_(false), 198 all_data_saved_(false),
200 opened_(false), 199 opened_(false),
201 open_enabled_(true),
202 delegate_delayed_complete_(false), 200 delegate_delayed_complete_(false),
203 bound_net_log_(bound_net_log), 201 bound_net_log_(bound_net_log),
204 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 202 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
205 delegate_->Attach(); 203 delegate_->Attach();
206 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD); 204 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD);
207 205
208 // Link the event sources. 206 // Link the event sources.
209 bound_net_log_.AddEvent( 207 bound_net_log_.AddEvent(
210 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, 208 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST,
211 info.request_bound_net_log.source().ToEventParametersCallback()); 209 info.request_bound_net_log.source().ToEventParametersCallback());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 start_time_(base::Time::Now()), 242 start_time_(base::Time::Now()),
245 delegate_(delegate), 243 delegate_(delegate),
246 is_paused_(false), 244 is_paused_(false),
247 auto_resume_count_(0), 245 auto_resume_count_(0),
248 open_when_complete_(false), 246 open_when_complete_(false),
249 file_externally_removed_(false), 247 file_externally_removed_(false),
250 auto_opened_(false), 248 auto_opened_(false),
251 is_temporary_(false), 249 is_temporary_(false),
252 all_data_saved_(false), 250 all_data_saved_(false),
253 opened_(false), 251 opened_(false),
254 open_enabled_(true),
255 delegate_delayed_complete_(false), 252 delegate_delayed_complete_(false),
256 bound_net_log_(bound_net_log), 253 bound_net_log_(bound_net_log),
257 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 254 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
258 delegate_->Attach(); 255 delegate_->Attach();
259 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); 256 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS);
260 } 257 }
261 258
262 DownloadItemImpl::~DownloadItemImpl() { 259 DownloadItemImpl::~DownloadItemImpl() {
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
264 261
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return; 427 return;
431 428
432 // Ideally, we want to detect errors in opening and report them, but we 429 // Ideally, we want to detect errors in opening and report them, but we
433 // don't generally have the proper interface for that to the external 430 // don't generally have the proper interface for that to the external
434 // program that opens the file. So instead we spawn a check to update 431 // program that opens the file. So instead we spawn a check to update
435 // the UI if the file has been deleted in parallel with the open. 432 // the UI if the file has been deleted in parallel with the open.
436 delegate_->CheckForFileRemoval(this); 433 delegate_->CheckForFileRemoval(this);
437 RecordOpen(GetEndTime(), !GetOpened()); 434 RecordOpen(GetEndTime(), !GetOpened());
438 opened_ = true; 435 opened_ = true;
439 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); 436 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
440 delegate_->DownloadOpened(this); 437 delegate_->OpenDownload(this);
441
442 // For testing: If download opening is disabled on this item,
443 // make the rest of the routine a no-op.
444 if (!open_enabled_)
445 return;
446
447 GetContentClient()->browser()->OpenItem(GetFullPath());
448 } 438 }
449 439
450 void DownloadItemImpl::ShowDownloadInShell() { 440 void DownloadItemImpl::ShowDownloadInShell() {
451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
452 442
453 GetContentClient()->browser()->ShowItemInFolder(GetFullPath()); 443 delegate_->ShowDownloadInShell(this);
454 } 444 }
455 445
456 int32 DownloadItemImpl::GetId() const { 446 int32 DownloadItemImpl::GetId() const {
457 return download_id_.local(); 447 return download_id_.local();
458 } 448 }
459 449
460 DownloadId DownloadItemImpl::GetGlobalId() const { 450 DownloadId DownloadItemImpl::GetGlobalId() const {
461 return download_id_; 451 return download_id_;
462 } 452 }
463 453
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 GetTargetFilePath().value().c_str()); 780 GetTargetFilePath().value().c_str());
791 } else { 781 } else {
792 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 782 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
793 } 783 }
794 784
795 description += " }"; 785 description += " }";
796 786
797 return description; 787 return description;
798 } 788 }
799 789
800 void DownloadItemImpl::MockDownloadOpenForTesting() {
801 open_enabled_ = false;
802 }
803
804 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { 790 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const {
805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 791 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
806 if (!IsInterrupted()) 792 if (!IsInterrupted())
807 return RESUME_MODE_INVALID; 793 return RESUME_MODE_INVALID;
808 794
809 // We can't continue without a handle on the intermediate file. 795 // We can't continue without a handle on the intermediate file.
810 const bool force_restart = current_path_.empty(); 796 const bool force_restart = current_path_.empty();
811 797
812 // We won't auto-restart if we've used up our attempts or the 798 // We won't auto-restart if we've used up our attempts or the
813 // download has been paused by user action. 799 // download has been paused by user action.
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 case RESUME_MODE_USER_CONTINUE: 1626 case RESUME_MODE_USER_CONTINUE:
1641 return "USER_CONTINUE"; 1627 return "USER_CONTINUE";
1642 case RESUME_MODE_USER_RESTART: 1628 case RESUME_MODE_USER_RESTART:
1643 return "USER_RESTART"; 1629 return "USER_RESTART";
1644 } 1630 }
1645 NOTREACHED() << "Unknown resume mode " << mode; 1631 NOTREACHED() << "Unknown resume mode " << mode;
1646 return "unknown"; 1632 return "unknown";
1647 } 1633 }
1648 1634
1649 } // namespace content 1635 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698