Index: chrome/browser/extensions/api/downloads/downloads_api.cc |
diff --git a/chrome/browser/extensions/api/downloads/downloads_api.cc b/chrome/browser/extensions/api/downloads/downloads_api.cc |
index 9ee1954712d33bd84591c6b7b6eedbf8b7b80e12..db69dc564864d9486a746208a5e89505003ecbe4 100644 |
--- a/chrome/browser/extensions/api/downloads/downloads_api.cc |
+++ b/chrome/browser/extensions/api/downloads/downloads_api.cc |
@@ -337,13 +337,18 @@ void GetManagers( |
} |
} |
-DownloadItem* GetActiveItem(Profile* profile, bool include_incognito, int id) { |
+DownloadItem* GetDownload(Profile* profile, bool include_incognito, int id) { |
DownloadManager* manager = NULL; |
DownloadManager* incognito_manager = NULL; |
GetManagers(profile, include_incognito, &manager, &incognito_manager); |
DownloadItem* download_item = manager->GetDownload(id); |
if (!download_item && incognito_manager) |
download_item = incognito_manager->GetDownload(id); |
+ return download_item; |
+} |
+ |
+DownloadItem* GetActiveItem(Profile* profile, bool include_incognito, int id) { |
Randy Smith (Not in Mondays)
2012/12/05 14:17:42
Maybe regularize the names of these two functions?
benjhayden
2012/12/05 18:41:02
Is GetDownloadIfInProgress ok?
Randy Smith (Not in Mondays)
2012/12/05 19:12:05
Sure.
|
+ DownloadItem* download_item = GetDownload(profile, include_incognito, id); |
return download_item && download_item->IsInProgress() ? download_item : NULL; |
} |
@@ -802,10 +807,15 @@ bool DownloadsOpenFunction::RunImpl() { |
scoped_ptr<extensions::api::downloads::Open::Params> params( |
extensions::api::downloads::Open::Params::Create(*args_)); |
EXTENSION_FUNCTION_VALIDATE(params.get()); |
- error_ = download_extension_errors::kNotImplementedError; |
- if (error_.empty()) |
- RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); |
- return error_.empty(); |
+ DownloadItem* download_item = GetDownload( |
+ profile(), include_incognito(), params->download_id); |
+ if (!download_item || !download_item->IsComplete()) { |
Randy Smith (Not in Mondays)
2012/12/05 14:17:42
I think I agree with the behavioral choice to not
benjhayden
2012/12/05 18:41:02
Decided to use SetOpenWhenComplete. PTAL.
Randy Smith (Not in Mondays)
2012/12/05 19:12:05
*wince* I guess that's fine. I'm uncomfortable w
benjhayden
2012/12/05 19:29:48
Actually, the primary reason that I'd like for ope
|
+ error_ = download_extension_errors::kInvalidOperationError; |
+ return false; |
+ } |
+ download_item->OpenDownload(); |
+ RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); |
+ return true; |
} |
DownloadsDragFunction::DownloadsDragFunction() {} |
@@ -842,12 +852,8 @@ bool DownloadsGetFileIconFunction::RunImpl() { |
int icon_size = kDefaultIconSize; |
if (options && options->size.get()) |
icon_size = *options->size.get(); |
- DownloadManager* manager = NULL; |
- DownloadManager* incognito_manager = NULL; |
- GetManagers(profile(), include_incognito(), &manager, &incognito_manager); |
- DownloadItem* download_item = manager->GetDownload(params->download_id); |
- if (!download_item && incognito_manager) |
- download_item = incognito_manager->GetDownload(params->download_id); |
+ DownloadItem* download_item = GetDownload( |
+ profile(), include_incognito(), params->download_id); |
if (!download_item || download_item->GetTargetFilePath().empty()) { |
error_ = download_extension_errors::kInvalidOperationError; |
return false; |