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