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

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

Issue 10833058: Make DownloadItem derive SupportsUserData instead of re-implementing it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gdata: "external"->"user" Created 8 years, 4 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 #include "chrome/browser/download/chrome_download_manager_delegate.h" 5 #include "chrome/browser/download/chrome_download_manager_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return false; 245 return false;
246 DCHECK(extension[0] == FilePath::kExtensionSeparator); 246 DCHECK(extension[0] == FilePath::kExtensionSeparator);
247 extension.erase(0, 1); 247 extension.erase(0, 1);
248 return download_prefs_->IsAutoOpenEnabledForExtension(extension); 248 return download_prefs_->IsAutoOpenEnabledForExtension(extension);
249 } 249 }
250 250
251 // static 251 // static
252 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) { 252 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) {
253 #if defined(ENABLE_SAFE_BROWSING) 253 #if defined(ENABLE_SAFE_BROWSING)
254 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( 254 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
255 item->GetExternalData(&safe_browsing_id)); 255 item->GetUserData(&safe_browsing_id));
256 DCHECK(!state); 256 DCHECK(!state);
257 if (!state) 257 if (!state)
258 state = new SafeBrowsingState(); 258 state = new SafeBrowsingState();
259 state->SetVerdict(DownloadProtectionService::SAFE); 259 state->SetVerdict(DownloadProtectionService::SAFE);
260 item->SetExternalData(&safe_browsing_id, state); 260 item->SetUserData(&safe_browsing_id, state);
261 #endif 261 #endif
262 } 262 }
263 263
264 bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion( 264 bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion(
265 DownloadItem* item, 265 DownloadItem* item,
266 const base::Closure& internal_complete_callback) { 266 const base::Closure& internal_complete_callback) {
267 #if defined(ENABLE_SAFE_BROWSING) 267 #if defined(ENABLE_SAFE_BROWSING)
268 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( 268 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
269 item->GetExternalData(&safe_browsing_id)); 269 item->GetUserData(&safe_browsing_id));
270 if (!state) { 270 if (!state) {
271 // Begin the safe browsing download protection check. 271 // Begin the safe browsing download protection check.
272 DownloadProtectionService* service = GetDownloadProtectionService(); 272 DownloadProtectionService* service = GetDownloadProtectionService();
273 if (service) { 273 if (service) {
274 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " 274 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = "
275 << item->DebugString(false); 275 << item->DebugString(false);
276 state = new SafeBrowsingState(); 276 state = new SafeBrowsingState();
277 state->set_callback(internal_complete_callback); 277 state->set_callback(internal_complete_callback);
278 item->SetExternalData(&safe_browsing_id, state); 278 item->SetUserData(&safe_browsing_id, state);
279 service->CheckClientDownload( 279 service->CheckClientDownload(
280 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), 280 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item),
281 base::Bind( 281 base::Bind(
282 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, 282 &ChromeDownloadManagerDelegate::CheckClientDownloadDone,
283 this, 283 this,
284 item->GetId())); 284 item->GetId()));
285 return false; 285 return false;
286 } 286 }
287 } else if (!state->is_complete()) { 287 } else if (!state->is_complete()) {
288 // Don't complete the download until we have an answer. 288 // Don't complete the download until we have an answer.
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT); 602 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT);
603 break; 603 break;
604 case DownloadProtectionService::UNCOMMON: 604 case DownloadProtectionService::UNCOMMON:
605 item->OnContentCheckCompleted( 605 item->OnContentCheckCompleted(
606 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT); 606 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
607 break; 607 break;
608 } 608 }
609 } 609 }
610 610
611 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( 611 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
612 item->GetExternalData(&safe_browsing_id)); 612 item->GetUserData(&safe_browsing_id));
613 state->SetVerdict(result); 613 state->SetVerdict(result);
614 } 614 }
615 615
616 // content::NotificationObserver implementation. 616 // content::NotificationObserver implementation.
617 void ChromeDownloadManagerDelegate::Observe( 617 void ChromeDownloadManagerDelegate::Observe(
618 int type, 618 int type,
619 const content::NotificationSource& source, 619 const content::NotificationSource& source,
620 const content::NotificationDetails& details) { 620 const content::NotificationDetails& details) {
621 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); 621 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE);
622 622
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 int32 download_id, int64 db_handle) { 820 int32 download_id, int64 db_handle) {
821 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 821 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
822 // call this function with an invalid |db_handle|. For instance, this can 822 // call this function with an invalid |db_handle|. For instance, this can
823 // happen when the history database is offline. We cannot have multiple 823 // happen when the history database is offline. We cannot have multiple
824 // DownloadItems with the same invalid db_handle, so we need to assign a 824 // DownloadItems with the same invalid db_handle, so we need to assign a
825 // unique |db_handle| here. 825 // unique |db_handle| here.
826 if (db_handle == DownloadItem::kUninitializedHandle) 826 if (db_handle == DownloadItem::kUninitializedHandle)
827 db_handle = download_history_->GetNextFakeDbHandle(); 827 db_handle = download_history_->GetNextFakeDbHandle();
828 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 828 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
829 } 829 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_download_observer.cc ('k') | chrome/browser/download/download_completion_blocker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698