OLD | NEW |
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_extension_api.h" | 5 #include "chrome/browser/download/download_extension_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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return false; | 441 return false; |
442 } | 442 } |
443 | 443 |
444 void DownloadsDragFunction::RunInternal() { | 444 void DownloadsDragFunction::RunInternal() { |
445 NOTIMPLEMENTED(); | 445 NOTIMPLEMENTED(); |
446 } | 446 } |
447 | 447 |
448 namespace { | 448 namespace { |
449 base::DictionaryValue* DownloadItemToJSON(DownloadItem* item) { | 449 base::DictionaryValue* DownloadItemToJSON(DownloadItem* item) { |
450 base::DictionaryValue* json = new base::DictionaryValue(); | 450 base::DictionaryValue* json = new base::DictionaryValue(); |
451 json->SetInteger(kIdKey, item->id()); | 451 json->SetInteger(kIdKey, item->GetId()); |
452 json->SetString(kUrlKey, item->original_url().spec()); | 452 json->SetString(kUrlKey, item->GetOriginalUrl().spec()); |
453 json->SetString(kFilenameKey, item->full_path().LossyDisplayName()); | 453 json->SetString(kFilenameKey, item->GetFullPath().LossyDisplayName()); |
454 json->SetString(kDangerKey, DangerString(item->GetDangerType())); | 454 json->SetString(kDangerKey, DangerString(item->GetDangerType())); |
455 json->SetBoolean(kDangerAcceptedKey, | 455 json->SetBoolean(kDangerAcceptedKey, |
456 item->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED); | 456 item->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED); |
457 json->SetString(kStateKey, StateString(item->state())); | 457 json->SetString(kStateKey, StateString(item->GetState())); |
458 json->SetBoolean(kPausedKey, item->is_paused()); | 458 json->SetBoolean(kPausedKey, item->IsPaused()); |
459 json->SetString(kMimeKey, item->mime_type()); | 459 json->SetString(kMimeKey, item->GetMimeType()); |
460 json->SetInteger(kStartTimeKey, | 460 json->SetInteger(kStartTimeKey, |
461 (item->start_time() - base::Time::UnixEpoch()).InMilliseconds()); | 461 (item->GetStartTime() - base::Time::UnixEpoch()).InMilliseconds()); |
462 json->SetInteger(kBytesReceivedKey, item->received_bytes()); | 462 json->SetInteger(kBytesReceivedKey, item->GetReceivedBytes()); |
463 json->SetInteger(kTotalBytesKey, item->total_bytes()); | 463 json->SetInteger(kTotalBytesKey, item->GetTotalBytes()); |
464 if (item->state() == DownloadItem::INTERRUPTED) | 464 if (item->GetState() == DownloadItem::INTERRUPTED) |
465 json->SetInteger(kErrorKey, static_cast<int>(item->last_reason())); | 465 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason())); |
466 // TODO(benjhayden): Implement endTime and fileSize. | 466 // TODO(benjhayden): Implement endTime and fileSize. |
467 // json->SetInteger(kEndTimeKey, -1); | 467 // json->SetInteger(kEndTimeKey, -1); |
468 json->SetInteger(kFileSizeKey, item->total_bytes()); | 468 json->SetInteger(kFileSizeKey, item->GetTotalBytes()); |
469 return json; | 469 return json; |
470 } | 470 } |
471 } // anonymous namespace | 471 } // anonymous namespace |
472 | 472 |
473 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 473 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( |
474 Profile* profile) | 474 Profile* profile) |
475 : profile_(profile), | 475 : profile_(profile), |
476 manager_( | 476 manager_( |
477 profile ? | 477 profile ? |
478 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager() : | 478 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager() : |
(...skipping 14 matching lines...) Expand all Loading... |
493 if (manager_ == NULL) | 493 if (manager_ == NULL) |
494 return; | 494 return; |
495 DownloadManager::DownloadVector current_vec; | 495 DownloadManager::DownloadVector current_vec; |
496 manager_->SearchDownloads(string16(), ¤t_vec); | 496 manager_->SearchDownloads(string16(), ¤t_vec); |
497 DownloadIdSet current_set; | 497 DownloadIdSet current_set; |
498 ItemMap current_map; | 498 ItemMap current_map; |
499 for (DownloadManager::DownloadVector::const_iterator iter = | 499 for (DownloadManager::DownloadVector::const_iterator iter = |
500 current_vec.begin(); | 500 current_vec.begin(); |
501 iter != current_vec.end(); ++iter) { | 501 iter != current_vec.end(); ++iter) { |
502 DownloadItem* item = *iter; | 502 DownloadItem* item = *iter; |
503 int item_id = item->id(); | 503 int item_id = item->GetId(); |
504 // TODO(benjhayden): Remove the following line when every item's id >= 0, | 504 // TODO(benjhayden): Remove the following line when every item's id >= 0, |
505 // which will allow firing onErased events for items from the history. | 505 // which will allow firing onErased events for items from the history. |
506 if (item_id < 0) continue; | 506 if (item_id < 0) continue; |
507 DCHECK(current_map.find(item_id) == current_map.end()); | 507 DCHECK(current_map.find(item_id) == current_map.end()); |
508 current_set.insert(item_id); | 508 current_set.insert(item_id); |
509 current_map[item_id] = item; | 509 current_map[item_id] = item; |
510 } | 510 } |
511 DownloadIdSet new_set; // current_set - downloads_; | 511 DownloadIdSet new_set; // current_set - downloads_; |
512 DownloadIdSet erased_set; // downloads_ - current_set; | 512 DownloadIdSet erased_set; // downloads_ - current_set; |
513 std::insert_iterator<DownloadIdSet> new_insertor(new_set, new_set.begin()); | 513 std::insert_iterator<DownloadIdSet> new_insertor(new_set, new_set.begin()); |
(...skipping 28 matching lines...) Expand all Loading... |
542 ListValue args; | 542 ListValue args; |
543 args.Append(arg); | 543 args.Append(arg); |
544 std::string json_args; | 544 std::string json_args; |
545 base::JSONWriter::Write(&args, false, &json_args); | 545 base::JSONWriter::Write(&args, false, &json_args); |
546 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 546 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
547 event_name, | 547 event_name, |
548 json_args, | 548 json_args, |
549 profile_, | 549 profile_, |
550 GURL()); | 550 GURL()); |
551 } | 551 } |
OLD | NEW |