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

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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
259 259
260 // Create a client to verify download URL with safebrowsing. 260 // Create a client to verify download URL with safebrowsing.
261 // It deletes itself after the callback. 261 // It deletes itself after the callback.
262 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( 262 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient(
263 info->download_id, info->url_chain, info->referrer_url); 263 info->download_id, info->url_chain, info->referrer_url);
264 sb_client->CheckDownloadUrl( 264 sb_client->CheckDownloadUrl(
265 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); 265 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone));
266 } 266 }
267 267
268 void DownloadManager::CheckForFilesRemoval() {
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
270 for (DownloadMap::iterator it = history_downloads_.begin();
271 it != history_downloads_.end(); ++it) {
272 DownloadItem* download_item = it->second;
273 if (download_item->IsComplete() && download_item->file_exists()) {
274 BrowserThread::PostTask(
275 BrowserThread::FILE, FROM_HERE,
276 NewRunnableMethod(this,
277 &DownloadManager::CheckForFilesRemovalOnFileThread,
278 it->first, download_item->GetTargetFilePath()));
279 }
280 }
281 }
282
283 void DownloadManager::CheckForFilesRemovalOnFileThread(
284 int64 db_handle, const FilePath& path) {
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
286 bool file_exists = file_util::PathExists(path);
287 BrowserThread::PostTask(
288 BrowserThread::UI, FROM_HERE,
289 NewRunnableMethod(this,
290 &DownloadManager::OnFilesRemovalDetected,
291 db_handle, file_exists));
292 }
293
294 void DownloadManager::OnFilesRemovalDetected(
Randy Smith (Not in Mondays) 2011/05/12 20:21:17 Given that we're doing single file checks now, we
haraken1 2011/05/13 14:08:17 Done.
295 int64 db_handle, bool file_exists) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
297 if (!file_exists) {
Randy Smith (Not in Mondays) 2011/05/12 20:21:17 Given that this function doesn't do anything if fi
haraken1 2011/05/13 14:08:17 Done.
298 DownloadMap::iterator it = history_downloads_.find(db_handle);
299 if (it != history_downloads_.end()) {
300 DownloadItem* download_item = it->second;
301 download_item->OnDownloadedFileRemoved();
302 }
303 }
304 }
305
268 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, 306 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info,
269 bool is_dangerous_url) { 307 bool is_dangerous_url) {
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
271 DCHECK(info); 309 DCHECK(info);
272 310
273 info->is_dangerous_url = is_dangerous_url; 311 info->is_dangerous_url = is_dangerous_url;
274 312
275 // Check whether this download is for an extension install or not. 313 // Check whether this download is for an extension install or not.
276 // Allow extensions to be explicitly saved. 314 // Allow extensions to be explicitly saved.
277 if (!info->prompt_user_for_save_location) { 315 if (!info->prompt_user_for_save_location) {
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 observed_download_manager_->RemoveObserver(this); 1213 observed_download_manager_->RemoveObserver(this);
1176 } 1214 }
1177 1215
1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1216 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1179 observing_download_manager_->NotifyModelChanged(); 1217 observing_download_manager_->NotifyModelChanged();
1180 } 1218 }
1181 1219
1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1220 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1183 observed_download_manager_ = NULL; 1221 observed_download_manager_ = NULL;
1184 } 1222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698