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

Side by Side Diff: chrome/browser/download/download_manager.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_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
256 256
257 // Create a client to verify download URL with safebrowsing. 257 // Create a client to verify download URL with safebrowsing.
258 // It deletes itself after the callback. 258 // It deletes itself after the callback.
259 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( 259 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient(
260 info->download_id, info->url_chain, info->referrer_url); 260 info->download_id, info->url_chain, info->referrer_url);
261 sb_client->CheckDownloadUrl( 261 sb_client->CheckDownloadUrl(
262 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); 262 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone));
263 } 263 }
264 264
265 void DownloadManager::CheckForHistoryFilesRemoval() {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
267 for (DownloadMap::iterator it = history_downloads_.begin();
268 it != history_downloads_.end(); ++it) {
269 CheckForFileRemoval(it->second);
270 }
271 }
272
273 void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) {
Paweł Hajdan Jr. 2011/05/17 20:03:39 nit: Add a BrowserThread::CurrentlyOn DCHECK here
haraken1 2011/06/07 12:49:18 Done.
274 if (download_item->IsComplete() &&
275 !download_item->file_externally_removed()) {
276 BrowserThread::PostTask(
277 BrowserThread::FILE, FROM_HERE,
278 NewRunnableMethod(this,
279 &DownloadManager::CheckForFileRemovalOnFileThread,
280 download_item->db_handle(),
281 download_item->GetTargetFilePath()));
282 }
283 }
284
285 void DownloadManager::CheckForFileRemovalOnFileThread(
286 int64 db_handle, const FilePath& path) {
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
288 if (!file_util::PathExists(path)) {
289 BrowserThread::PostTask(
290 BrowserThread::UI, FROM_HERE,
291 NewRunnableMethod(this,
292 &DownloadManager::OnFileRemovalDetected,
293 db_handle));
294 }
295 }
296
297 void DownloadManager::OnFileRemovalDetected(int64 db_handle) {
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
299 DownloadMap::iterator it = history_downloads_.find(db_handle);
300 if (it != history_downloads_.end()) {
301 DownloadItem* download_item = it->second;
302 download_item->OnDownloadedFileRemoved();
303 }
304 }
305
265 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, 306 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info,
266 bool is_dangerous_url) { 307 bool is_dangerous_url) {
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
268 DCHECK(info); 309 DCHECK(info);
269 310
270 info->is_dangerous_url = is_dangerous_url; 311 info->is_dangerous_url = is_dangerous_url;
271 312
272 // Check whether this download is for an extension install or not. 313 // Check whether this download is for an extension install or not.
273 // Allow extensions to be explicitly saved. 314 // Allow extensions to be explicitly saved.
274 if (!info->prompt_user_for_save_location) { 315 if (!info->prompt_user_for_save_location) {
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 observed_download_manager_->RemoveObserver(this); 1211 observed_download_manager_->RemoveObserver(this);
1171 } 1212 }
1172 1213
1173 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1214 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1174 observing_download_manager_->NotifyModelChanged(); 1215 observing_download_manager_->NotifyModelChanged();
1175 } 1216 }
1176 1217
1177 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1218 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1178 observed_download_manager_ = NULL; 1219 observed_download_manager_ = NULL;
1179 } 1220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698