Chromium Code Reviews| 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 // Download utility implementation | 5 // Download utility implementation |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 file_value->SetInteger("percent", | 657 file_value->SetInteger("percent", |
| 658 static_cast<int>(download->PercentComplete())); | 658 static_cast<int>(download->PercentComplete())); |
| 659 file_value->SetInteger("received", | 659 file_value->SetInteger("received", |
| 660 static_cast<int>(download->received_bytes())); | 660 static_cast<int>(download->received_bytes())); |
| 661 } else if (download->IsCancelled()) { | 661 } else if (download->IsCancelled()) { |
| 662 file_value->SetString("state", "CANCELLED"); | 662 file_value->SetString("state", "CANCELLED"); |
| 663 } else if (download->IsComplete()) { | 663 } else if (download->IsComplete()) { |
| 664 if (download->safety_state() == DownloadItem::DANGEROUS) { | 664 if (download->safety_state() == DownloadItem::DANGEROUS) { |
| 665 file_value->SetString("state", "DANGEROUS"); | 665 file_value->SetString("state", "DANGEROUS"); |
| 666 } else { | 666 } else { |
| 667 file_value->SetString("state", "COMPLETE"); | 667 bool path_exists = true; |
|
Paweł Hajdan Jr.
2011/04/27 08:53:30
It seems like you're checking whether a path exist
| |
| 668 #if defined(OS_WIN) | |
| 669 if (GetFileAttributes( | |
| 670 download->GetTargetFilePath().value().c_str()) == | |
| 671 INVALID_FILE_ATTRIBUTES) | |
| 672 path_exists = false; | |
| 673 #elif defined(OS_POSIX) | |
| 674 if (access(download->GetTargetFilePath().value().c_str(), F_OK) != 0) | |
| 675 path_exists = false; | |
| 676 #else | |
|
Paweł Hajdan Jr.
2011/04/27 08:53:30
A "dangling else" like that is generally dangerous
| |
| 677 #endif | |
| 678 if (path_exists) { | |
|
Paweł Hajdan Jr.
2011/04/27 08:53:30
nit: It's probably cleaner to use a ternary operat
| |
| 679 file_value->SetString("state", "COMPLETE"); | |
| 680 } else { | |
| 681 file_value->SetString("state", "REMOVED"); | |
| 682 } | |
| 668 } | 683 } |
| 669 } | 684 } |
| 670 | 685 |
| 671 file_value->SetInteger("total", | 686 file_value->SetInteger("total", |
| 672 static_cast<int>(download->total_bytes())); | 687 static_cast<int>(download->total_bytes())); |
| 673 | 688 |
| 674 return file_value; | 689 return file_value; |
| 675 } | 690 } |
| 676 | 691 |
| 677 string16 GetProgressStatusText(DownloadItem* download) { | 692 string16 GetProgressStatusText(DownloadItem* download) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 // Extensions that are not from the gallery are considered dangerous. | 905 // Extensions that are not from the gallery are considered dangerous. |
| 891 ExtensionService* service = profile->GetExtensionService(); | 906 ExtensionService* service = profile->GetExtensionService(); |
| 892 if (!service || | 907 if (!service || |
| 893 !service->IsDownloadFromGallery(info->url(), info->referrer_url)) | 908 !service->IsDownloadFromGallery(info->url(), info->referrer_url)) |
| 894 return true; | 909 return true; |
| 895 } | 910 } |
| 896 return false; | 911 return false; |
| 897 } | 912 } |
| 898 | 913 |
| 899 } // namespace download_util | 914 } // namespace download_util |
| OLD | NEW |