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

Side by Side Diff: chrome/browser/download/download_item.cc

Issue 6905049: Detect removed files and reflect the state in chrome://downloads and the download shelf (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Correct typo Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/download/download_item.h" 5 #include "chrome/browser/download/download_item.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 original_mime_type_(info.original_mime_type), 124 original_mime_type_(info.original_mime_type),
125 total_bytes_(info.total_bytes), 125 total_bytes_(info.total_bytes),
126 received_bytes_(info.received_bytes), 126 received_bytes_(info.received_bytes),
127 start_tick_(base::TimeTicks()), 127 start_tick_(base::TimeTicks()),
128 state_(static_cast<DownloadState>(info.state)), 128 state_(static_cast<DownloadState>(info.state)),
129 start_time_(info.start_time), 129 start_time_(info.start_time),
130 db_handle_(info.db_handle), 130 db_handle_(info.db_handle),
131 download_manager_(download_manager), 131 download_manager_(download_manager),
132 is_paused_(false), 132 is_paused_(false),
133 open_when_complete_(false), 133 open_when_complete_(false),
134 file_externally_removed_(false),
134 safety_state_(SAFE), 135 safety_state_(SAFE),
135 danger_type_(NOT_DANGEROUS), 136 danger_type_(NOT_DANGEROUS),
136 auto_opened_(false), 137 auto_opened_(false),
137 target_name_(info.original_name), 138 target_name_(info.original_name),
138 save_as_(false), 139 save_as_(false),
139 is_otr_(false), 140 is_otr_(false),
140 is_extension_install_(info.is_extension_install), 141 is_extension_install_(info.is_extension_install),
141 is_temporary_(false), 142 is_temporary_(false),
142 all_data_saved_(false), 143 all_data_saved_(false),
143 opened_(false) { 144 opened_(false) {
(...skipping 18 matching lines...) Expand all
162 total_bytes_(info.total_bytes), 163 total_bytes_(info.total_bytes),
163 received_bytes_(0), 164 received_bytes_(0),
164 last_os_error_(0), 165 last_os_error_(0),
165 start_tick_(base::TimeTicks::Now()), 166 start_tick_(base::TimeTicks::Now()),
166 state_(IN_PROGRESS), 167 state_(IN_PROGRESS),
167 start_time_(info.start_time), 168 start_time_(info.start_time),
168 db_handle_(DownloadHistory::kUninitializedHandle), 169 db_handle_(DownloadHistory::kUninitializedHandle),
169 download_manager_(download_manager), 170 download_manager_(download_manager),
170 is_paused_(false), 171 is_paused_(false),
171 open_when_complete_(false), 172 open_when_complete_(false),
173 file_externally_removed_(false),
172 safety_state_(GetSafetyState(info.is_dangerous_file, 174 safety_state_(GetSafetyState(info.is_dangerous_file,
173 info.is_dangerous_url)), 175 info.is_dangerous_url)),
174 danger_type_(GetDangerType(info.is_dangerous_file, 176 danger_type_(GetDangerType(info.is_dangerous_file,
175 info.is_dangerous_url)), 177 info.is_dangerous_url)),
176 auto_opened_(false), 178 auto_opened_(false),
177 target_name_(info.original_name), 179 target_name_(info.original_name),
178 process_handle_(info.process_handle), 180 process_handle_(info.process_handle),
179 save_as_(info.prompt_user_for_save_location), 181 save_as_(info.prompt_user_for_save_location),
180 is_otr_(is_otr), 182 is_otr_(is_otr),
181 is_extension_install_(info.is_extension_install), 183 is_extension_install_(info.is_extension_install),
(...skipping 18 matching lines...) Expand all
200 total_bytes_(0), 202 total_bytes_(0),
201 received_bytes_(0), 203 received_bytes_(0),
202 last_os_error_(0), 204 last_os_error_(0),
203 start_tick_(base::TimeTicks::Now()), 205 start_tick_(base::TimeTicks::Now()),
204 state_(IN_PROGRESS), 206 state_(IN_PROGRESS),
205 start_time_(base::Time::Now()), 207 start_time_(base::Time::Now()),
206 db_handle_(DownloadHistory::kUninitializedHandle), 208 db_handle_(DownloadHistory::kUninitializedHandle),
207 download_manager_(download_manager), 209 download_manager_(download_manager),
208 is_paused_(false), 210 is_paused_(false),
209 open_when_complete_(false), 211 open_when_complete_(false),
212 file_externally_removed_(false),
210 safety_state_(SAFE), 213 safety_state_(SAFE),
211 danger_type_(NOT_DANGEROUS), 214 danger_type_(NOT_DANGEROUS),
212 auto_opened_(false), 215 auto_opened_(false),
213 save_as_(false), 216 save_as_(false),
214 is_otr_(is_otr), 217 is_otr_(is_otr),
215 is_extension_install_(false), 218 is_extension_install_(false),
216 is_temporary_(false), 219 is_temporary_(false),
217 all_data_saved_(false), 220 all_data_saved_(false),
218 opened_(false) { 221 opened_(false) {
219 Init(true /* start progress timer */); 222 Init(true /* start progress timer */);
(...skipping 29 matching lines...) Expand all
249 DownloadPrefs* prefs = download_manager_->download_prefs(); 252 DownloadPrefs* prefs = download_manager_->download_prefs();
250 if (open) 253 if (open)
251 prefs->EnableAutoOpenBasedOnExtension(GetUserVerifiedFilePath()); 254 prefs->EnableAutoOpenBasedOnExtension(GetUserVerifiedFilePath());
252 else 255 else
253 prefs->DisableAutoOpenBasedOnExtension(GetUserVerifiedFilePath()); 256 prefs->DisableAutoOpenBasedOnExtension(GetUserVerifiedFilePath());
254 } 257 }
255 258
256 void DownloadItem::OpenDownload() { 259 void DownloadItem::OpenDownload() {
257 if (IsPartialDownload()) { 260 if (IsPartialDownload()) {
258 open_when_complete_ = !open_when_complete_; 261 open_when_complete_ = !open_when_complete_;
259 } else if (IsComplete()) { 262 } else if (IsComplete() && !file_externally_removed()) {
263 download_manager_->CheckForFileRemoval(this);
Randy Smith (Not in Mondays) 2011/05/16 20:57:12 I think I'd like a comment here explaining this de
Paweł Hajdan Jr. 2011/05/17 20:03:39 There is an ugliness in a way those objects commun
Randy Smith (Not in Mondays) 2011/05/18 19:28:18 Pawel: I'm confused about what you mean. Dispatch
Paweł Hajdan Jr. 2011/05/18 20:03:43 Sorry, I was a bit afraid that comment could be co
Randy Smith (Not in Mondays) 2011/05/18 20:13:13 Ah, thank you! That makes sense, but it won't wor
Paweł Hajdan Jr. 2011/05/18 20:23:44 Oh, I see. Indeed, please ignore my comment about
haraken1 2011/06/07 12:49:18 In conclusion, here I only added the comment that
260 opened_ = true; 264 opened_ = true;
261 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); 265 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
262 if (is_extension_install()) { 266 if (is_extension_install()) {
263 download_util::OpenChromeExtension(download_manager_->profile(), 267 download_util::OpenChromeExtension(download_manager_->profile(),
264 download_manager_, 268 download_manager_,
265 *this); 269 *this);
266 return; 270 return;
267 } 271 }
268 #if defined(OS_MACOSX) 272 #if defined(OS_MACOSX)
269 // Mac OS X requires opening downloads on the UI thread. 273 // Mac OS X requires opening downloads on the UI thread.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 UpdateObservers(); 353 UpdateObservers();
350 } 354 }
351 355
352 void DownloadItem::OnAllDataSaved(int64 size) { 356 void DownloadItem::OnAllDataSaved(int64 size) {
353 DCHECK(!all_data_saved_); 357 DCHECK(!all_data_saved_);
354 all_data_saved_ = true; 358 all_data_saved_ = true;
355 UpdateSize(size); 359 UpdateSize(size);
356 StopProgressTimer(); 360 StopProgressTimer();
357 } 361 }
358 362
363 void DownloadItem::OnDownloadedFileRemoved() {
364 file_externally_removed_ = true;
365 UpdateObservers();
366 }
367
359 void DownloadItem::Completed() { 368 void DownloadItem::Completed() {
360 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); 369 VLOG(20) << __FUNCTION__ << "() " << DebugString(false);
361 370
362 download_util::RecordDownloadCount(download_util::COMPLETED_COUNT); 371 download_util::RecordDownloadCount(download_util::COMPLETED_COUNT);
363 372
364 // Handle chrome extensions explicitly and skip the shell execute. 373 // Handle chrome extensions explicitly and skip the shell execute.
365 if (is_extension_install()) { 374 if (is_extension_install()) {
366 download_util::OpenChromeExtension(download_manager_->profile(), 375 download_util::OpenChromeExtension(download_manager_->profile(),
367 download_manager_, 376 download_manager_,
368 *this); 377 *this);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 is_otr() ? 'T' : 'F', 652 is_otr() ? 'T' : 'F',
644 DebugSafetyStateString(safety_state()), 653 DebugSafetyStateString(safety_state()),
645 url_list.c_str(), 654 url_list.c_str(),
646 target_name_.value().c_str(), 655 target_name_.value().c_str(),
647 full_path().value().c_str()); 656 full_path().value().c_str());
648 } else { 657 } else {
649 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 658 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
650 } 659 }
651 return description; 660 return description;
652 } 661 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698