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

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

Issue 2327723002: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: fix Created 4 years, 3 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 26 matching lines...) Expand all
37 #include "chrome/browser/browser_process.h" 37 #include "chrome/browser/browser_process.h"
38 #include "chrome/browser/download/download_danger_prompt.h" 38 #include "chrome/browser/download/download_danger_prompt.h"
39 #include "chrome/browser/download/download_file_icon_extractor.h" 39 #include "chrome/browser/download/download_file_icon_extractor.h"
40 #include "chrome/browser/download/download_prefs.h" 40 #include "chrome/browser/download/download_prefs.h"
41 #include "chrome/browser/download/download_query.h" 41 #include "chrome/browser/download/download_query.h"
42 #include "chrome/browser/download/download_service.h" 42 #include "chrome/browser/download/download_service.h"
43 #include "chrome/browser/download/download_service_factory.h" 43 #include "chrome/browser/download/download_service_factory.h"
44 #include "chrome/browser/download/download_shelf.h" 44 #include "chrome/browser/download/download_shelf.h"
45 #include "chrome/browser/download/download_stats.h" 45 #include "chrome/browser/download/download_stats.h"
46 #include "chrome/browser/download/drag_download_item.h" 46 #include "chrome/browser/download/drag_download_item.h"
47 #include "chrome/browser/extensions/chrome_extension_function_details.h"
47 #include "chrome/browser/icon_loader.h" 48 #include "chrome/browser/icon_loader.h"
48 #include "chrome/browser/icon_manager.h" 49 #include "chrome/browser/icon_manager.h"
49 #include "chrome/browser/platform_util.h" 50 #include "chrome/browser/platform_util.h"
50 #include "chrome/browser/profiles/profile.h" 51 #include "chrome/browser/profiles/profile.h"
51 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 52 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
52 #include "chrome/browser/ui/browser.h" 53 #include "chrome/browser/ui/browser.h"
53 #include "chrome/browser/ui/browser_list.h" 54 #include "chrome/browser/ui/browser_list.h"
54 #include "chrome/browser/ui/browser_window.h" 55 #include "chrome/browser/ui/browser_window.h"
55 #include "chrome/common/extensions/api/downloads.h" 56 #include "chrome/common/extensions/api/downloads.h"
56 #include "components/web_modal/web_contents_modal_dialog_manager.h" 57 #include "components/web_modal/web_contents_modal_dialog_manager.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 base::Time::Exploded exploded; 244 base::Time::Exploded exploded;
244 t.UTCExplode(&exploded); 245 t.UTCExplode(&exploded);
245 return base::StringPrintf( 246 return base::StringPrintf(
246 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, 247 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month,
247 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, 248 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second,
248 exploded.millisecond); 249 exploded.millisecond);
249 } 250 }
250 251
251 std::unique_ptr<base::DictionaryValue> DownloadItemToJSON( 252 std::unique_ptr<base::DictionaryValue> DownloadItemToJSON(
252 DownloadItem* download_item, 253 DownloadItem* download_item,
253 Profile* profile) { 254 content::BrowserContext* browser_context) {
254 base::DictionaryValue* json = new base::DictionaryValue(); 255 base::DictionaryValue* json = new base::DictionaryValue();
255 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved()); 256 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved());
256 json->SetInteger(kIdKey, download_item->GetId()); 257 json->SetInteger(kIdKey, download_item->GetId());
257 const GURL& url = download_item->GetOriginalUrl(); 258 const GURL& url = download_item->GetOriginalUrl();
258 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string())); 259 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string()));
259 const GURL& finalUrl = download_item->GetURL(); 260 const GURL& finalUrl = download_item->GetURL();
260 json->SetString(kFinalUrlKey, 261 json->SetString(kFinalUrlKey,
261 (finalUrl.is_valid() ? finalUrl.spec() : std::string())); 262 (finalUrl.is_valid() ? finalUrl.spec() : std::string()));
262 const GURL& referrer = download_item->GetReferrerUrl(); 263 const GURL& referrer = download_item->GetReferrerUrl();
263 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec() 264 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec()
264 : std::string())); 265 : std::string()));
265 json->SetString(kFilenameKey, 266 json->SetString(kFilenameKey,
266 download_item->GetTargetFilePath().LossyDisplayName()); 267 download_item->GetTargetFilePath().LossyDisplayName());
267 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); 268 json->SetString(kDangerKey, DangerString(download_item->GetDangerType()));
268 json->SetString(kStateKey, StateString(download_item->GetState())); 269 json->SetString(kStateKey, StateString(download_item->GetState()));
269 json->SetBoolean(kCanResumeKey, download_item->CanResume()); 270 json->SetBoolean(kCanResumeKey, download_item->CanResume());
270 json->SetBoolean(kPausedKey, download_item->IsPaused()); 271 json->SetBoolean(kPausedKey, download_item->IsPaused());
271 json->SetString(kMimeKey, download_item->GetMimeType()); 272 json->SetString(kMimeKey, download_item->GetMimeType());
272 json->SetString(kStartTimeKey, TimeToISO8601(download_item->GetStartTime())); 273 json->SetString(kStartTimeKey, TimeToISO8601(download_item->GetStartTime()));
273 json->SetDouble(kBytesReceivedKey, download_item->GetReceivedBytes()); 274 json->SetDouble(kBytesReceivedKey, download_item->GetReceivedBytes());
274 json->SetDouble(kTotalBytesKey, download_item->GetTotalBytes()); 275 json->SetDouble(kTotalBytesKey, download_item->GetTotalBytes());
275 json->SetBoolean(kIncognitoKey, profile->IsOffTheRecord()); 276 json->SetBoolean(kIncognitoKey, browser_context->IsOffTheRecord());
276 if (download_item->GetState() == DownloadItem::INTERRUPTED) { 277 if (download_item->GetState() == DownloadItem::INTERRUPTED) {
277 json->SetString(kErrorKey, 278 json->SetString(kErrorKey,
278 content::DownloadInterruptReasonToString( 279 content::DownloadInterruptReasonToString(
279 download_item->GetLastReason())); 280 download_item->GetLastReason()));
280 } else if (download_item->GetState() == DownloadItem::CANCELLED) { 281 } else if (download_item->GetState() == DownloadItem::CANCELLED) {
281 json->SetString(kErrorKey, 282 json->SetString(kErrorKey,
282 content::DownloadInterruptReasonToString( 283 content::DownloadInterruptReasonToString(
283 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); 284 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED));
284 } 285 }
285 if (!download_item->GetEndTime().is_null()) 286 if (!download_item->GetEndTime().is_null())
286 json->SetString(kEndTimeKey, TimeToISO8601(download_item->GetEndTime())); 287 json->SetString(kEndTimeKey, TimeToISO8601(download_item->GetEndTime()));
287 base::TimeDelta time_remaining; 288 base::TimeDelta time_remaining;
288 if (download_item->TimeRemaining(&time_remaining)) { 289 if (download_item->TimeRemaining(&time_remaining)) {
289 base::Time now = base::Time::Now(); 290 base::Time now = base::Time::Now();
290 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); 291 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining));
291 } 292 }
292 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); 293 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item);
293 if (by_ext) { 294 if (by_ext) {
294 json->SetString(kByExtensionIdKey, by_ext->id()); 295 json->SetString(kByExtensionIdKey, by_ext->id());
295 json->SetString(kByExtensionNameKey, by_ext->name()); 296 json->SetString(kByExtensionNameKey, by_ext->name());
296 // Lookup the extension's current name() in case the user changed their 297 // Lookup the extension's current name() in case the user changed their
297 // language. This won't work if the extension was uninstalled, so the name 298 // language. This won't work if the extension was uninstalled, so the name
298 // might be the wrong language. 299 // might be the wrong language.
299 const Extension* extension = 300 const Extension* extension =
300 ExtensionRegistry::Get(profile) 301 ExtensionRegistry::Get(browser_context)
301 ->GetExtensionById(by_ext->id(), ExtensionRegistry::EVERYTHING); 302 ->GetExtensionById(by_ext->id(), ExtensionRegistry::EVERYTHING);
302 if (extension) 303 if (extension)
303 json->SetString(kByExtensionNameKey, extension->name()); 304 json->SetString(kByExtensionNameKey, extension->name());
304 } 305 }
305 // TODO(benjhayden): Implement fileSize. 306 // TODO(benjhayden): Implement fileSize.
306 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes()); 307 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes());
307 return std::unique_ptr<base::DictionaryValue>(json); 308 return std::unique_ptr<base::DictionaryValue>(json);
308 } 309 }
309 310
310 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { 311 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 406 }
406 407
407 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { 408 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) {
408 return !download_item.IsTemporary(); 409 return !download_item.IsTemporary();
409 } 410 }
410 411
411 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to 412 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to
412 // the off-record DownloadManager if one exists and is requested via 413 // the off-record DownloadManager if one exists and is requested via
413 // |include_incognito|. This should work regardless of whether |profile| is 414 // |include_incognito|. This should work regardless of whether |profile| is
414 // original or incognito. 415 // original or incognito.
415 void GetManagers( 416 void GetManagers(content::BrowserContext* context,
416 Profile* profile, 417 bool include_incognito,
417 bool include_incognito, 418 DownloadManager** manager,
418 DownloadManager** manager, 419 DownloadManager** incognito_manager) {
419 DownloadManager** incognito_manager) { 420 Profile* profile = Profile::FromBrowserContext(context);
420 *manager = BrowserContext::GetDownloadManager(profile->GetOriginalProfile()); 421 *manager = BrowserContext::GetDownloadManager(profile->GetOriginalProfile());
421 if (profile->HasOffTheRecordProfile() && 422 if (profile->HasOffTheRecordProfile() &&
422 (include_incognito || 423 (include_incognito ||
423 profile->IsOffTheRecord())) { 424 profile->IsOffTheRecord())) {
424 *incognito_manager = BrowserContext::GetDownloadManager( 425 *incognito_manager = BrowserContext::GetDownloadManager(
425 profile->GetOffTheRecordProfile()); 426 profile->GetOffTheRecordProfile());
426 } else { 427 } else {
427 *incognito_manager = NULL; 428 *incognito_manager = NULL;
428 } 429 }
429 } 430 }
430 431
431 DownloadItem* GetDownload(Profile* profile, bool include_incognito, int id) { 432 DownloadItem* GetDownload(content::BrowserContext* context,
433 bool include_incognito,
434 int id) {
432 DownloadManager* manager = NULL; 435 DownloadManager* manager = NULL;
433 DownloadManager* incognito_manager = NULL; 436 DownloadManager* incognito_manager = NULL;
434 GetManagers(profile, include_incognito, &manager, &incognito_manager); 437 GetManagers(context, include_incognito, &manager, &incognito_manager);
435 DownloadItem* download_item = manager->GetDownload(id); 438 DownloadItem* download_item = manager->GetDownload(id);
436 if (!download_item && incognito_manager) 439 if (!download_item && incognito_manager)
437 download_item = incognito_manager->GetDownload(id); 440 download_item = incognito_manager->GetDownload(id);
438 return download_item; 441 return download_item;
439 } 442 }
440 443
441 enum DownloadsFunctionName { 444 enum DownloadsFunctionName {
442 DOWNLOADS_FUNCTION_DOWNLOAD = 0, 445 DOWNLOADS_FUNCTION_DOWNLOAD = 0,
443 DOWNLOADS_FUNCTION_SEARCH = 1, 446 DOWNLOADS_FUNCTION_SEARCH = 1,
444 DOWNLOADS_FUNCTION_PAUSE = 2, 447 DOWNLOADS_FUNCTION_PAUSE = 2,
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); 1072 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
1070 error_ = content::DownloadInterruptReasonToString(interrupt_reason); 1073 error_ = content::DownloadInterruptReasonToString(interrupt_reason);
1071 } 1074 }
1072 SendResponse(error_.empty()); 1075 SendResponse(error_.empty());
1073 } 1076 }
1074 1077
1075 DownloadsSearchFunction::DownloadsSearchFunction() {} 1078 DownloadsSearchFunction::DownloadsSearchFunction() {}
1076 1079
1077 DownloadsSearchFunction::~DownloadsSearchFunction() {} 1080 DownloadsSearchFunction::~DownloadsSearchFunction() {}
1078 1081
1079 bool DownloadsSearchFunction::RunSync() { 1082 ExtensionFunction::ResponseAction DownloadsSearchFunction::Run() {
1080 std::unique_ptr<downloads::Search::Params> params( 1083 std::unique_ptr<downloads::Search::Params> params(
1081 downloads::Search::Params::Create(*args_)); 1084 downloads::Search::Params::Create(*args_));
1082 EXTENSION_FUNCTION_VALIDATE(params.get()); 1085 EXTENSION_FUNCTION_VALIDATE(params.get());
1083 DownloadManager* manager = NULL; 1086 DownloadManager* manager = NULL;
1084 DownloadManager* incognito_manager = NULL; 1087 DownloadManager* incognito_manager = NULL;
1085 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); 1088 GetManagers(browser_context(), include_incognito(), &manager,
1089 &incognito_manager);
1086 ExtensionDownloadsEventRouter* router = 1090 ExtensionDownloadsEventRouter* router =
1087 DownloadServiceFactory::GetForBrowserContext( 1091 DownloadServiceFactory::GetForBrowserContext(
1088 manager->GetBrowserContext())->GetExtensionEventRouter(); 1092 manager->GetBrowserContext())->GetExtensionEventRouter();
1089 router->CheckForHistoryFilesRemoval(); 1093 router->CheckForHistoryFilesRemoval();
1090 if (incognito_manager) { 1094 if (incognito_manager) {
1091 ExtensionDownloadsEventRouter* incognito_router = 1095 ExtensionDownloadsEventRouter* incognito_router =
1092 DownloadServiceFactory::GetForBrowserContext( 1096 DownloadServiceFactory::GetForBrowserContext(
1093 incognito_manager->GetBrowserContext())->GetExtensionEventRouter(); 1097 incognito_manager->GetBrowserContext())->GetExtensionEventRouter();
1094 incognito_router->CheckForHistoryFilesRemoval(); 1098 incognito_router->CheckForHistoryFilesRemoval();
1095 } 1099 }
1096 DownloadQuery::DownloadVector results; 1100 DownloadQuery::DownloadVector results;
1097 RunDownloadQuery(params->query, 1101 std::string error;
1098 manager, 1102 RunDownloadQuery(params->query, manager, incognito_manager, &error, &results);
1099 incognito_manager, 1103 if (!error.empty())
1100 &error_, 1104 return RespondNow(Error(error));
1101 &results);
1102 if (!error_.empty())
1103 return false;
1104 1105
1105 std::unique_ptr<base::ListValue> json_results(new base::ListValue()); 1106 std::unique_ptr<base::ListValue> json_results(new base::ListValue());
1106 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); 1107 for (DownloadManager::DownloadVector::const_iterator it = results.begin();
1107 it != results.end(); ++it) { 1108 it != results.end(); ++it) {
1108 DownloadItem* download_item = *it; 1109 DownloadItem* download_item = *it;
1109 uint32_t download_id = download_item->GetId(); 1110 uint32_t download_id = download_item->GetId();
1110 bool off_record = ((incognito_manager != NULL) && 1111 bool off_record = ((incognito_manager != NULL) &&
1111 (incognito_manager->GetDownload(download_id) != NULL)); 1112 (incognito_manager->GetDownload(download_id) != NULL));
1112 std::unique_ptr<base::DictionaryValue> json_item(DownloadItemToJSON( 1113 Profile* profile = Profile::FromBrowserContext(browser_context());
1113 *it, off_record ? GetProfile()->GetOffTheRecordProfile() 1114 std::unique_ptr<base::DictionaryValue> json_item(
1114 : GetProfile()->GetOriginalProfile())); 1115 DownloadItemToJSON(*it, off_record ? profile->GetOffTheRecordProfile()
1116 : profile->GetOriginalProfile()));
1115 json_results->Append(std::move(json_item)); 1117 json_results->Append(std::move(json_item));
1116 } 1118 }
1117 SetResult(std::move(json_results));
1118 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); 1119 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH);
1119 return true; 1120 return RespondNow(OneArgument(std::move(json_results)));
1120 } 1121 }
1121 1122
1122 DownloadsPauseFunction::DownloadsPauseFunction() {} 1123 DownloadsPauseFunction::DownloadsPauseFunction() {}
1123 1124
1124 DownloadsPauseFunction::~DownloadsPauseFunction() {} 1125 DownloadsPauseFunction::~DownloadsPauseFunction() {}
1125 1126
1126 bool DownloadsPauseFunction::RunSync() { 1127 ExtensionFunction::ResponseAction DownloadsPauseFunction::Run() {
1127 std::unique_ptr<downloads::Pause::Params> params( 1128 std::unique_ptr<downloads::Pause::Params> params(
1128 downloads::Pause::Params::Create(*args_)); 1129 downloads::Pause::Params::Create(*args_));
1129 EXTENSION_FUNCTION_VALIDATE(params.get()); 1130 EXTENSION_FUNCTION_VALIDATE(params.get());
1130 DownloadItem* download_item = 1131 DownloadItem* download_item =
1131 GetDownload(GetProfile(), include_incognito(), params->download_id); 1132 GetDownload(browser_context(), include_incognito(), params->download_id);
1132 if (InvalidId(download_item, &error_) || 1133 std::string error;
1134 if (InvalidId(download_item, &error) ||
1133 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, 1135 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS,
1134 errors::kNotInProgress, &error_)) 1136 errors::kNotInProgress, &error)) {
1135 return false; 1137 return RespondNow(Error(error));
1138 }
1136 // If the item is already paused, this is a no-op and the operation will 1139 // If the item is already paused, this is a no-op and the operation will
1137 // silently succeed. 1140 // silently succeed.
1138 download_item->Pause(); 1141 download_item->Pause();
1139 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); 1142 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE);
1140 return true; 1143 return RespondNow(NoArguments());
1141 } 1144 }
1142 1145
1143 DownloadsResumeFunction::DownloadsResumeFunction() {} 1146 DownloadsResumeFunction::DownloadsResumeFunction() {}
1144 1147
1145 DownloadsResumeFunction::~DownloadsResumeFunction() {} 1148 DownloadsResumeFunction::~DownloadsResumeFunction() {}
1146 1149
1147 bool DownloadsResumeFunction::RunSync() { 1150 ExtensionFunction::ResponseAction DownloadsResumeFunction::Run() {
1148 std::unique_ptr<downloads::Resume::Params> params( 1151 std::unique_ptr<downloads::Resume::Params> params(
1149 downloads::Resume::Params::Create(*args_)); 1152 downloads::Resume::Params::Create(*args_));
1150 EXTENSION_FUNCTION_VALIDATE(params.get()); 1153 EXTENSION_FUNCTION_VALIDATE(params.get());
1151 DownloadItem* download_item = 1154 DownloadItem* download_item =
1152 GetDownload(GetProfile(), include_incognito(), params->download_id); 1155 GetDownload(browser_context(), include_incognito(), params->download_id);
1153 if (InvalidId(download_item, &error_) || 1156 std::string error;
1157 if (InvalidId(download_item, &error) ||
1154 Fault(download_item->IsPaused() && !download_item->CanResume(), 1158 Fault(download_item->IsPaused() && !download_item->CanResume(),
1155 errors::kNotResumable, &error_)) 1159 errors::kNotResumable, &error)) {
1156 return false; 1160 return RespondNow(Error(error));
1161 }
1157 // Note that if the item isn't paused, this will be a no-op, and the extension 1162 // Note that if the item isn't paused, this will be a no-op, and the extension
1158 // call will seem successful. 1163 // call will seem successful.
1159 download_item->Resume(); 1164 download_item->Resume();
1160 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); 1165 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME);
1161 return true; 1166 return RespondNow(NoArguments());
1162 } 1167 }
1163 1168
1164 DownloadsCancelFunction::DownloadsCancelFunction() {} 1169 DownloadsCancelFunction::DownloadsCancelFunction() {}
1165 1170
1166 DownloadsCancelFunction::~DownloadsCancelFunction() {} 1171 DownloadsCancelFunction::~DownloadsCancelFunction() {}
1167 1172
1168 bool DownloadsCancelFunction::RunSync() { 1173 ExtensionFunction::ResponseAction DownloadsCancelFunction::Run() {
1169 std::unique_ptr<downloads::Resume::Params> params( 1174 std::unique_ptr<downloads::Resume::Params> params(
1170 downloads::Resume::Params::Create(*args_)); 1175 downloads::Resume::Params::Create(*args_));
1171 EXTENSION_FUNCTION_VALIDATE(params.get()); 1176 EXTENSION_FUNCTION_VALIDATE(params.get());
1172 DownloadItem* download_item = 1177 DownloadItem* download_item =
1173 GetDownload(GetProfile(), include_incognito(), params->download_id); 1178 GetDownload(browser_context(), include_incognito(), params->download_id);
1174 if (download_item && 1179 if (download_item &&
1175 (download_item->GetState() == DownloadItem::IN_PROGRESS)) 1180 (download_item->GetState() == DownloadItem::IN_PROGRESS))
1176 download_item->Cancel(true); 1181 download_item->Cancel(true);
1177 // |download_item| can be NULL if the download ID was invalid or if the 1182 // |download_item| can be NULL if the download ID was invalid or if the
1178 // download is not currently active. Either way, it's not a failure. 1183 // download is not currently active. Either way, it's not a failure.
1179 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); 1184 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL);
1180 return true; 1185 return RespondNow(NoArguments());
1181 } 1186 }
1182 1187
1183 DownloadsEraseFunction::DownloadsEraseFunction() {} 1188 DownloadsEraseFunction::DownloadsEraseFunction() {}
1184 1189
1185 DownloadsEraseFunction::~DownloadsEraseFunction() {} 1190 DownloadsEraseFunction::~DownloadsEraseFunction() {}
1186 1191
1187 bool DownloadsEraseFunction::RunSync() { 1192 ExtensionFunction::ResponseAction DownloadsEraseFunction::Run() {
1188 std::unique_ptr<downloads::Erase::Params> params( 1193 std::unique_ptr<downloads::Erase::Params> params(
1189 downloads::Erase::Params::Create(*args_)); 1194 downloads::Erase::Params::Create(*args_));
1190 EXTENSION_FUNCTION_VALIDATE(params.get()); 1195 EXTENSION_FUNCTION_VALIDATE(params.get());
1191 DownloadManager* manager = NULL; 1196 DownloadManager* manager = NULL;
1192 DownloadManager* incognito_manager = NULL; 1197 DownloadManager* incognito_manager = NULL;
1193 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); 1198 GetManagers(browser_context(), include_incognito(), &manager,
1199 &incognito_manager);
1194 DownloadQuery::DownloadVector results; 1200 DownloadQuery::DownloadVector results;
1195 RunDownloadQuery(params->query, 1201 std::string error;
1196 manager, 1202 RunDownloadQuery(params->query, manager, incognito_manager, &error, &results);
1197 incognito_manager, 1203 if (!error.empty())
1198 &error_, 1204 return RespondNow(Error(error));
1199 &results);
1200 if (!error_.empty())
1201 return false;
1202 std::unique_ptr<base::ListValue> json_results(new base::ListValue()); 1205 std::unique_ptr<base::ListValue> json_results(new base::ListValue());
1203 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); 1206 for (DownloadManager::DownloadVector::const_iterator it = results.begin();
1204 it != results.end(); ++it) { 1207 it != results.end(); ++it) {
1205 json_results->AppendInteger(static_cast<int>((*it)->GetId())); 1208 json_results->AppendInteger(static_cast<int>((*it)->GetId()));
1206 (*it)->Remove(); 1209 (*it)->Remove();
1207 } 1210 }
1208 SetResult(std::move(json_results));
1209 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); 1211 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE);
1210 return true; 1212 return RespondNow(OneArgument(std::move(json_results)));
1211 } 1213 }
1212 1214
1213 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { 1215 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() {
1214 } 1216 }
1215 1217
1216 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { 1218 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() {
1217 } 1219 }
1218 1220
1219 bool DownloadsRemoveFileFunction::RunAsync() { 1221 bool DownloadsRemoveFileFunction::RunAsync() {
1220 std::unique_ptr<downloads::RemoveFile::Params> params( 1222 std::unique_ptr<downloads::RemoveFile::Params> params(
1221 downloads::RemoveFile::Params::Create(*args_)); 1223 downloads::RemoveFile::Params::Create(*args_));
1222 EXTENSION_FUNCTION_VALIDATE(params.get()); 1224 EXTENSION_FUNCTION_VALIDATE(params.get());
1223 DownloadItem* download_item = 1225 DownloadItem* download_item =
1224 GetDownload(GetProfile(), include_incognito(), params->download_id); 1226 GetDownload(browser_context(), include_incognito(), params->download_id);
1225 if (InvalidId(download_item, &error_) || 1227 if (InvalidId(download_item, &error_) ||
1226 Fault((download_item->GetState() != DownloadItem::COMPLETE), 1228 Fault((download_item->GetState() != DownloadItem::COMPLETE),
1227 errors::kNotComplete, &error_) || 1229 errors::kNotComplete, &error_) ||
1228 Fault(download_item->GetFileExternallyRemoved(), 1230 Fault(download_item->GetFileExternallyRemoved(),
1229 errors::kFileAlreadyDeleted, &error_)) 1231 errors::kFileAlreadyDeleted, &error_))
1230 return false; 1232 return false;
1231 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE); 1233 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE);
1232 download_item->DeleteFile( 1234 download_item->DeleteFile(
1233 base::Bind(&DownloadsRemoveFileFunction::Done, this)); 1235 base::Bind(&DownloadsRemoveFileFunction::Done, this));
1234 return true; 1236 return true;
(...skipping 17 matching lines...) Expand all
1252 bool DownloadsAcceptDangerFunction::RunAsync() { 1254 bool DownloadsAcceptDangerFunction::RunAsync() {
1253 std::unique_ptr<downloads::AcceptDanger::Params> params( 1255 std::unique_ptr<downloads::AcceptDanger::Params> params(
1254 downloads::AcceptDanger::Params::Create(*args_)); 1256 downloads::AcceptDanger::Params::Create(*args_));
1255 EXTENSION_FUNCTION_VALIDATE(params.get()); 1257 EXTENSION_FUNCTION_VALIDATE(params.get());
1256 PromptOrWait(params->download_id, 10); 1258 PromptOrWait(params->download_id, 10);
1257 return true; 1259 return true;
1258 } 1260 }
1259 1261
1260 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) { 1262 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) {
1261 DownloadItem* download_item = 1263 DownloadItem* download_item =
1262 GetDownload(GetProfile(), include_incognito(), download_id); 1264 GetDownload(browser_context(), include_incognito(), download_id);
1263 content::WebContents* web_contents = dispatcher()->GetVisibleWebContents(); 1265 content::WebContents* web_contents = dispatcher()->GetVisibleWebContents();
1264 if (InvalidId(download_item, &error_) || 1266 if (InvalidId(download_item, &error_) ||
1265 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, 1267 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS,
1266 errors::kNotInProgress, &error_) || 1268 errors::kNotInProgress, &error_) ||
1267 Fault(!download_item->IsDangerous(), errors::kNotDangerous, &error_) || 1269 Fault(!download_item->IsDangerous(), errors::kNotDangerous, &error_) ||
1268 Fault(!web_contents, errors::kInvisibleContext, &error_)) { 1270 Fault(!web_contents, errors::kInvisibleContext, &error_)) {
1269 SendResponse(error_.empty()); 1271 SendResponse(error_.empty());
1270 return; 1272 return;
1271 } 1273 }
1272 bool visible = platform_util::IsVisible(web_contents->GetNativeView()); 1274 bool visible = platform_util::IsVisible(web_contents->GetNativeView());
(...skipping 21 matching lines...) Expand all
1294 // DownloadDangerPrompt deletes itself 1296 // DownloadDangerPrompt deletes itself
1295 if (on_prompt_created_ && !on_prompt_created_->is_null()) 1297 if (on_prompt_created_ && !on_prompt_created_->is_null())
1296 on_prompt_created_->Run(prompt); 1298 on_prompt_created_->Run(prompt);
1297 // Function finishes in DangerPromptCallback(). 1299 // Function finishes in DangerPromptCallback().
1298 } 1300 }
1299 1301
1300 void DownloadsAcceptDangerFunction::DangerPromptCallback( 1302 void DownloadsAcceptDangerFunction::DangerPromptCallback(
1301 int download_id, DownloadDangerPrompt::Action action) { 1303 int download_id, DownloadDangerPrompt::Action action) {
1302 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1304 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1303 DownloadItem* download_item = 1305 DownloadItem* download_item =
1304 GetDownload(GetProfile(), include_incognito(), download_id); 1306 GetDownload(browser_context(), include_incognito(), download_id);
1305 if (InvalidId(download_item, &error_) || 1307 if (InvalidId(download_item, &error_) ||
1306 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, 1308 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS,
1307 errors::kNotInProgress, &error_)) 1309 errors::kNotInProgress, &error_))
1308 return; 1310 return;
1309 switch (action) { 1311 switch (action) {
1310 case DownloadDangerPrompt::ACCEPT: 1312 case DownloadDangerPrompt::ACCEPT:
1311 download_item->ValidateDangerousDownload(); 1313 download_item->ValidateDangerousDownload();
1312 break; 1314 break;
1313 case DownloadDangerPrompt::CANCEL: 1315 case DownloadDangerPrompt::CANCEL:
1314 download_item->Remove(); 1316 download_item->Remove();
1315 break; 1317 break;
1316 case DownloadDangerPrompt::DISMISS: 1318 case DownloadDangerPrompt::DISMISS:
1317 break; 1319 break;
1318 } 1320 }
1319 SendResponse(error_.empty()); 1321 SendResponse(error_.empty());
1320 } 1322 }
1321 1323
1322 DownloadsShowFunction::DownloadsShowFunction() {} 1324 DownloadsShowFunction::DownloadsShowFunction() {}
1323 1325
1324 DownloadsShowFunction::~DownloadsShowFunction() {} 1326 DownloadsShowFunction::~DownloadsShowFunction() {}
1325 1327
1326 bool DownloadsShowFunction::RunSync() { 1328 ExtensionFunction::ResponseAction DownloadsShowFunction::Run() {
1327 std::unique_ptr<downloads::Show::Params> params( 1329 std::unique_ptr<downloads::Show::Params> params(
1328 downloads::Show::Params::Create(*args_)); 1330 downloads::Show::Params::Create(*args_));
1329 EXTENSION_FUNCTION_VALIDATE(params.get()); 1331 EXTENSION_FUNCTION_VALIDATE(params.get());
1330 DownloadItem* download_item = 1332 DownloadItem* download_item =
1331 GetDownload(GetProfile(), include_incognito(), params->download_id); 1333 GetDownload(browser_context(), include_incognito(), params->download_id);
1332 if (InvalidId(download_item, &error_)) 1334 std::string error;
1333 return false; 1335 if (InvalidId(download_item, &error))
1336 return RespondNow(Error(error));
1334 download_item->ShowDownloadInShell(); 1337 download_item->ShowDownloadInShell();
1335 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW); 1338 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW);
1336 return true; 1339 return RespondNow(NoArguments());
1337 } 1340 }
1338 1341
1339 DownloadsShowDefaultFolderFunction::DownloadsShowDefaultFolderFunction() {} 1342 DownloadsShowDefaultFolderFunction::DownloadsShowDefaultFolderFunction() {}
1340 1343
1341 DownloadsShowDefaultFolderFunction::~DownloadsShowDefaultFolderFunction() {} 1344 DownloadsShowDefaultFolderFunction::~DownloadsShowDefaultFolderFunction() {}
1342 1345
1343 bool DownloadsShowDefaultFolderFunction::RunSync() { 1346 ExtensionFunction::ResponseAction DownloadsShowDefaultFolderFunction::Run() {
1344 DownloadManager* manager = NULL; 1347 DownloadManager* manager = NULL;
1345 DownloadManager* incognito_manager = NULL; 1348 DownloadManager* incognito_manager = NULL;
1346 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); 1349 GetManagers(browser_context(), include_incognito(), &manager,
1350 &incognito_manager);
1347 platform_util::OpenItem( 1351 platform_util::OpenItem(
1348 GetProfile(), DownloadPrefs::FromDownloadManager(manager)->DownloadPath(), 1352 Profile::FromBrowserContext(browser_context()),
1353 DownloadPrefs::FromDownloadManager(manager)->DownloadPath(),
1349 platform_util::OPEN_FOLDER, platform_util::OpenOperationCallback()); 1354 platform_util::OPEN_FOLDER, platform_util::OpenOperationCallback());
1350 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); 1355 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER);
1351 return true; 1356 return RespondNow(NoArguments());
1352 } 1357 }
1353 1358
1354 DownloadsOpenFunction::DownloadsOpenFunction() {} 1359 DownloadsOpenFunction::DownloadsOpenFunction() {}
1355 1360
1356 DownloadsOpenFunction::~DownloadsOpenFunction() {} 1361 DownloadsOpenFunction::~DownloadsOpenFunction() {}
1357 1362
1358 bool DownloadsOpenFunction::RunSync() { 1363 ExtensionFunction::ResponseAction DownloadsOpenFunction::Run() {
1359 std::unique_ptr<downloads::Open::Params> params( 1364 std::unique_ptr<downloads::Open::Params> params(
1360 downloads::Open::Params::Create(*args_)); 1365 downloads::Open::Params::Create(*args_));
1361 EXTENSION_FUNCTION_VALIDATE(params.get()); 1366 EXTENSION_FUNCTION_VALIDATE(params.get());
1362 DownloadItem* download_item = 1367 DownloadItem* download_item =
1363 GetDownload(GetProfile(), include_incognito(), params->download_id); 1368 GetDownload(browser_context(), include_incognito(), params->download_id);
1364 if (InvalidId(download_item, &error_) || 1369 std::string error;
1365 Fault(!user_gesture(), errors::kUserGesture, &error_) || 1370 if (InvalidId(download_item, &error) ||
1371 Fault(!user_gesture(), errors::kUserGesture, &error) ||
1366 Fault(download_item->GetState() != DownloadItem::COMPLETE, 1372 Fault(download_item->GetState() != DownloadItem::COMPLETE,
1367 errors::kNotComplete, 1373 errors::kNotComplete, &error) ||
1368 &error_) ||
1369 Fault(!extension()->permissions_data()->HasAPIPermission( 1374 Fault(!extension()->permissions_data()->HasAPIPermission(
1370 APIPermission::kDownloadsOpen), 1375 APIPermission::kDownloadsOpen),
1371 errors::kOpenPermission, 1376 errors::kOpenPermission, &error)) {
1372 &error_)) 1377 return RespondNow(Error(error));
1373 return false; 1378 }
1374 download_item->OpenDownload(); 1379 download_item->OpenDownload();
1375 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); 1380 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN);
1376 return true; 1381 return RespondNow(NoArguments());
1377 } 1382 }
1378 1383
1379 DownloadsDragFunction::DownloadsDragFunction() {} 1384 DownloadsDragFunction::DownloadsDragFunction() {}
1380 1385
1381 DownloadsDragFunction::~DownloadsDragFunction() {} 1386 DownloadsDragFunction::~DownloadsDragFunction() {}
1382 1387
1383 bool DownloadsDragFunction::RunSync() { 1388 ExtensionFunction::ResponseAction DownloadsDragFunction::Run() {
1384 std::unique_ptr<downloads::Drag::Params> params( 1389 std::unique_ptr<downloads::Drag::Params> params(
1385 downloads::Drag::Params::Create(*args_)); 1390 downloads::Drag::Params::Create(*args_));
1386 EXTENSION_FUNCTION_VALIDATE(params.get()); 1391 EXTENSION_FUNCTION_VALIDATE(params.get());
1387 DownloadItem* download_item = 1392 DownloadItem* download_item =
1388 GetDownload(GetProfile(), include_incognito(), params->download_id); 1393 GetDownload(browser_context(), include_incognito(), params->download_id);
1389 content::WebContents* web_contents = 1394 content::WebContents* web_contents =
1390 dispatcher()->GetVisibleWebContents(); 1395 dispatcher()->GetVisibleWebContents();
1391 if (InvalidId(download_item, &error_) || 1396 std::string error;
1392 Fault(!web_contents, errors::kInvisibleContext, &error_)) 1397 if (InvalidId(download_item, &error) ||
1393 return false; 1398 Fault(!web_contents, errors::kInvisibleContext, &error)) {
1399 return RespondNow(Error(error));
1400 }
1394 RecordApiFunctions(DOWNLOADS_FUNCTION_DRAG); 1401 RecordApiFunctions(DOWNLOADS_FUNCTION_DRAG);
1395 gfx::Image* icon = g_browser_process->icon_manager()->LookupIconFromFilepath( 1402 gfx::Image* icon = g_browser_process->icon_manager()->LookupIconFromFilepath(
1396 download_item->GetTargetFilePath(), IconLoader::NORMAL); 1403 download_item->GetTargetFilePath(), IconLoader::NORMAL);
1397 gfx::NativeView view = web_contents->GetNativeView(); 1404 gfx::NativeView view = web_contents->GetNativeView();
1398 { 1405 {
1399 // Enable nested tasks during DnD, while |DragDownload()| blocks. 1406 // Enable nested tasks during DnD, while |DragDownload()| blocks.
1400 base::MessageLoop::ScopedNestableTaskAllower allow( 1407 base::MessageLoop::ScopedNestableTaskAllower allow(
1401 base::MessageLoop::current()); 1408 base::MessageLoop::current());
1402 DragDownloadItem(download_item, icon, view); 1409 DragDownloadItem(download_item, icon, view);
1403 } 1410 }
1404 return true; 1411 return RespondNow(NoArguments());
1405 } 1412 }
1406 1413
1407 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} 1414 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {}
1408 1415
1409 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} 1416 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {}
1410 1417
1411 bool DownloadsSetShelfEnabledFunction::RunSync() { 1418 ExtensionFunction::ResponseAction DownloadsSetShelfEnabledFunction::Run() {
1412 std::unique_ptr<downloads::SetShelfEnabled::Params> params( 1419 std::unique_ptr<downloads::SetShelfEnabled::Params> params(
1413 downloads::SetShelfEnabled::Params::Create(*args_)); 1420 downloads::SetShelfEnabled::Params::Create(*args_));
1414 EXTENSION_FUNCTION_VALIDATE(params.get()); 1421 EXTENSION_FUNCTION_VALIDATE(params.get());
1422 // TODO(devlin): Solve this with the feature system.
1415 if (!extension()->permissions_data()->HasAPIPermission( 1423 if (!extension()->permissions_data()->HasAPIPermission(
1416 APIPermission::kDownloadsShelf)) { 1424 APIPermission::kDownloadsShelf)) {
1417 error_ = download_extension_errors::kShelfPermission; 1425 return RespondNow(Error(download_extension_errors::kShelfPermission));
1418 return false;
1419 } 1426 }
1420 1427
1421 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); 1428 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED);
1422 DownloadManager* manager = NULL; 1429 DownloadManager* manager = NULL;
1423 DownloadManager* incognito_manager = NULL; 1430 DownloadManager* incognito_manager = NULL;
1424 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); 1431 GetManagers(browser_context(), include_incognito(), &manager,
1432 &incognito_manager);
1425 DownloadService* service = NULL; 1433 DownloadService* service = NULL;
1426 DownloadService* incognito_service = NULL; 1434 DownloadService* incognito_service = NULL;
1427 if (manager) { 1435 if (manager) {
1428 service = DownloadServiceFactory::GetForBrowserContext( 1436 service = DownloadServiceFactory::GetForBrowserContext(
1429 manager->GetBrowserContext()); 1437 manager->GetBrowserContext());
1430 service->GetExtensionEventRouter()->SetShelfEnabled(extension(), 1438 service->GetExtensionEventRouter()->SetShelfEnabled(extension(),
1431 params->enabled); 1439 params->enabled);
1432 } 1440 }
1433 if (incognito_manager) { 1441 if (incognito_manager) {
1434 incognito_service = DownloadServiceFactory::GetForBrowserContext( 1442 incognito_service = DownloadServiceFactory::GetForBrowserContext(
(...skipping 13 matching lines...) Expand all
1448 (current_service == incognito_service)) && 1456 (current_service == incognito_service)) &&
1449 browser->window()->IsDownloadShelfVisible() && 1457 browser->window()->IsDownloadShelfVisible() &&
1450 !current_service->IsShelfEnabled()) 1458 !current_service->IsShelfEnabled())
1451 browser->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); 1459 browser->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC);
1452 } 1460 }
1453 } 1461 }
1454 1462
1455 if (params->enabled && 1463 if (params->enabled &&
1456 ((manager && !service->IsShelfEnabled()) || 1464 ((manager && !service->IsShelfEnabled()) ||
1457 (incognito_manager && !incognito_service->IsShelfEnabled()))) { 1465 (incognito_manager && !incognito_service->IsShelfEnabled()))) {
1458 error_ = download_extension_errors::kShelfDisabled; 1466 return RespondNow(Error(download_extension_errors::kShelfDisabled));
1459 return false;
1460 } 1467 }
1461 1468
1462 return true; 1469 return RespondNow(NoArguments());
1463 } 1470 }
1464 1471
1465 DownloadsGetFileIconFunction::DownloadsGetFileIconFunction() 1472 DownloadsGetFileIconFunction::DownloadsGetFileIconFunction()
1466 : icon_extractor_(new DownloadFileIconExtractorImpl()) { 1473 : icon_extractor_(new DownloadFileIconExtractorImpl()) {
1467 } 1474 }
1468 1475
1469 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} 1476 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {}
1470 1477
1471 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( 1478 void DownloadsGetFileIconFunction::SetIconExtractorForTesting(
1472 DownloadFileIconExtractor* extractor) { 1479 DownloadFileIconExtractor* extractor) {
1473 DCHECK(extractor); 1480 DCHECK(extractor);
1474 icon_extractor_.reset(extractor); 1481 icon_extractor_.reset(extractor);
1475 } 1482 }
1476 1483
1477 bool DownloadsGetFileIconFunction::RunAsync() { 1484 bool DownloadsGetFileIconFunction::RunAsync() {
1478 std::unique_ptr<downloads::GetFileIcon::Params> params( 1485 std::unique_ptr<downloads::GetFileIcon::Params> params(
1479 downloads::GetFileIcon::Params::Create(*args_)); 1486 downloads::GetFileIcon::Params::Create(*args_));
1480 EXTENSION_FUNCTION_VALIDATE(params.get()); 1487 EXTENSION_FUNCTION_VALIDATE(params.get());
1481 const downloads::GetFileIconOptions* options = 1488 const downloads::GetFileIconOptions* options =
1482 params->options.get(); 1489 params->options.get();
1483 int icon_size = kDefaultIconSize; 1490 int icon_size = kDefaultIconSize;
1484 if (options && options->size.get()) 1491 if (options && options->size.get())
1485 icon_size = *options->size; 1492 icon_size = *options->size;
1486 DownloadItem* download_item = 1493 DownloadItem* download_item =
1487 GetDownload(GetProfile(), include_incognito(), params->download_id); 1494 GetDownload(browser_context(), include_incognito(), params->download_id);
1488 if (InvalidId(download_item, &error_) || 1495 if (InvalidId(download_item, &error_) ||
1489 Fault(download_item->GetTargetFilePath().empty(), 1496 Fault(download_item->GetTargetFilePath().empty(),
1490 errors::kEmptyFile, &error_)) 1497 errors::kEmptyFile, &error_))
1491 return false; 1498 return false;
1492 // In-progress downloads return the intermediate filename for GetFullPath() 1499 // In-progress downloads return the intermediate filename for GetFullPath()
1493 // which doesn't have the final extension. Therefore a good file icon can't be 1500 // which doesn't have the final extension. Therefore a good file icon can't be
1494 // found, so use GetTargetFilePath() instead. 1501 // found, so use GetTargetFilePath() instead.
1495 DCHECK(icon_extractor_.get()); 1502 DCHECK(icon_extractor_.get());
1496 DCHECK(icon_size == 16 || icon_size == 32); 1503 DCHECK(icon_size == 16 || icon_size == 32);
1497 float scale = 1.0; 1504 float scale = 1.0;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 return; 1918 return;
1912 base::Time now(base::Time::Now()); 1919 base::Time now(base::Time::Now());
1913 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); 1920 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT();
1914 if (delta <= kFileExistenceRateLimitSeconds) 1921 if (delta <= kFileExistenceRateLimitSeconds)
1915 return; 1922 return;
1916 last_checked_removal_ = now; 1923 last_checked_removal_ = now;
1917 manager->CheckForHistoryFilesRemoval(); 1924 manager->CheckForHistoryFilesRemoval();
1918 } 1925 }
1919 1926
1920 } // namespace extensions 1927 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.h ('k') | chrome/browser/extensions/api/module/module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698