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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 params->options.get(); 848 params->options.get();
849 int icon_size = kDefaultIconSize; 849 int icon_size = kDefaultIconSize;
850 if (options && options->size.get()) 850 if (options && options->size.get())
851 icon_size = *options->size.get(); 851 icon_size = *options->size.get();
852 DownloadManager* manager = NULL; 852 DownloadManager* manager = NULL;
853 DownloadManager* incognito_manager = NULL; 853 DownloadManager* incognito_manager = NULL;
854 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); 854 GetManagers(profile(), include_incognito(), &manager, &incognito_manager);
855 DownloadItem* download_item = manager->GetDownload(params->download_id); 855 DownloadItem* download_item = manager->GetDownload(params->download_id);
856 if (!download_item && incognito_manager) 856 if (!download_item && incognito_manager)
857 download_item = incognito_manager->GetDownload(params->download_id); 857 download_item = incognito_manager->GetDownload(params->download_id);
858 if (!download_item) { 858 if (!download_item || download_item->GetTargetFilePath().empty()) {
859 // The DownloadItem is is added to history when the path is determined. If 859 // The DownloadItem is is added to history when the path is determined. If
Randy Smith (Not in Mondays) 2012/09/24 18:03:25 Is this comment still accurate?
benjhayden 2012/09/24 20:12:11 Nope. Deleted. chrome.downloads.onCreated is fired
860 // the download is not in history, then we don't have a path / final 860 // the download is not in history, then we don't have a path / final
861 // filename and no icon. 861 // filename and no icon.
862 error_ = download_extension_errors::kInvalidOperationError; 862 error_ = download_extension_errors::kInvalidOperationError;
863 return false; 863 return false;
864 } 864 }
865 // In-progress downloads return the intermediate filename for GetFullPath() 865 // In-progress downloads return the intermediate filename for GetFullPath()
866 // which doesn't have the final extension. Therefore we won't be able to 866 // which doesn't have the final extension. Therefore we won't be able to
867 // derive a good file icon for it. So we use GetTargetFilePath() instead. 867 // derive a good file icon for it. So we use GetTargetFilePath() instead.
868 FilePath path = download_item->GetTargetFilePath();
869 DCHECK(!path.empty());
870 DCHECK(icon_extractor_.get()); 868 DCHECK(icon_extractor_.get());
871 DCHECK(icon_size == 16 || icon_size == 32); 869 DCHECK(icon_size == 16 || icon_size == 32);
872 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( 870 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath(
873 path, IconLoaderSizeFromPixelSize(icon_size), 871 download_item->GetTargetFilePath(),
872 IconLoaderSizeFromPixelSize(icon_size),
874 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); 873 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this)));
875 return true; 874 return true;
876 } 875 }
877 876
878 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { 877 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) {
879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 878 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
880 if (url.empty()) { 879 if (url.empty()) {
881 error_ = download_extension_errors::kIconNotFoundError; 880 error_ = download_extension_errors::kIconNotFoundError;
882 } else { 881 } else {
883 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); 882 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 if (profile_->HasOffTheRecordProfile() && 1001 if (profile_->HasOffTheRecordProfile() &&
1003 !profile_->IsOffTheRecord()) { 1002 !profile_->IsOffTheRecord()) {
1004 DispatchEventInternal( 1003 DispatchEventInternal(
1005 profile_->GetOffTheRecordProfile(), 1004 profile_->GetOffTheRecordProfile(),
1006 event_name, 1005 event_name,
1007 json_args, 1006 json_args,
1008 scoped_ptr<base::ListValue>(args->DeepCopy())); 1007 scoped_ptr<base::ListValue>(args->DeepCopy()));
1009 } 1008 }
1010 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); 1009 DispatchEventInternal(profile_, event_name, json_args, args.Pass());
1011 } 1010 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698