| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/md_downloads/downloads_list_tracker.h" | 5 #include "chrome/browser/ui/webui/md_downloads/downloads_list_tracker.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 // Don't return a danger type string if it is NOT_DANGEROUS, | 65 // Don't return a danger type string if it is NOT_DANGEROUS, |
| 66 // MAYBE_DANGEROUS_CONTENT, or USER_VALIDATED. | 66 // MAYBE_DANGEROUS_CONTENT, or USER_VALIDATED. |
| 67 NOTREACHED(); | 67 NOTREACHED(); |
| 68 return ""; | 68 return ""; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(dbeam): if useful elsewhere, move to base/i18n/time_formatting.h? | 71 // TODO(dbeam): if useful elsewhere, move to base/i18n/time_formatting.h? |
| 72 base::string16 TimeFormatLongDate(const base::Time& time) { | 72 base::string16 TimeFormatLongDate(const base::Time& time) { |
| 73 scoped_ptr<icu::DateFormat> formatter( | 73 std::unique_ptr<icu::DateFormat> formatter( |
| 74 icu::DateFormat::createDateInstance(icu::DateFormat::kLong)); | 74 icu::DateFormat::createDateInstance(icu::DateFormat::kLong)); |
| 75 icu::UnicodeString date_string; | 75 icu::UnicodeString date_string; |
| 76 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); | 76 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); |
| 77 return base::string16(date_string.getBuffer(), | 77 return base::string16(date_string.getBuffer(), |
| 78 static_cast<size_t>(date_string.length())); | 78 static_cast<size_t>(date_string.length())); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 DownloadsListTracker::DownloadsListTracker( | 83 DownloadsListTracker::DownloadsListTracker( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 DownloadsListTracker::DownloadsListTracker( | 178 DownloadsListTracker::DownloadsListTracker( |
| 179 DownloadManager* download_manager, | 179 DownloadManager* download_manager, |
| 180 content::WebUI* web_ui, | 180 content::WebUI* web_ui, |
| 181 base::Callback<bool(const DownloadItem&)> should_show) | 181 base::Callback<bool(const DownloadItem&)> should_show) |
| 182 : main_notifier_(download_manager, this), | 182 : main_notifier_(download_manager, this), |
| 183 web_ui_(web_ui), | 183 web_ui_(web_ui), |
| 184 should_show_(should_show) { | 184 should_show_(should_show) { |
| 185 Init(); | 185 Init(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 scoped_ptr<base::DictionaryValue> DownloadsListTracker::CreateDownloadItemValue( | 188 std::unique_ptr<base::DictionaryValue> |
| 189 DownloadsListTracker::CreateDownloadItemValue( |
| 189 content::DownloadItem* download_item) const { | 190 content::DownloadItem* download_item) const { |
| 190 // TODO(asanka): Move towards using download_model here for getting status and | 191 // TODO(asanka): Move towards using download_model here for getting status and |
| 191 // progress. The difference currently only matters to Drive downloads and | 192 // progress. The difference currently only matters to Drive downloads and |
| 192 // those don't show up on the downloads page, but should. | 193 // those don't show up on the downloads page, but should. |
| 193 DownloadItemModel download_model(download_item); | 194 DownloadItemModel download_model(download_item); |
| 194 | 195 |
| 195 // The items which are to be written into file_value are also described in | 196 // The items which are to be written into file_value are also described in |
| 196 // chrome/browser/resources/downloads/downloads.js in @typedef for | 197 // chrome/browser/resources/downloads/downloads.js in @typedef for |
| 197 // BackendDownloadObject. Please update it whenever you add or remove | 198 // BackendDownloadObject. Please update it whenever you add or remove |
| 198 // any keys in file_value. | 199 // any keys in file_value. |
| 199 scoped_ptr<base::DictionaryValue> file_value(new base::DictionaryValue); | 200 std::unique_ptr<base::DictionaryValue> file_value(new base::DictionaryValue); |
| 200 | 201 |
| 201 file_value->SetInteger( | 202 file_value->SetInteger( |
| 202 "started", static_cast<int>(download_item->GetStartTime().ToTimeT())); | 203 "started", static_cast<int>(download_item->GetStartTime().ToTimeT())); |
| 203 file_value->SetString( | 204 file_value->SetString( |
| 204 "since_string", ui::TimeFormat::RelativeDate( | 205 "since_string", ui::TimeFormat::RelativeDate( |
| 205 download_item->GetStartTime(), NULL)); | 206 download_item->GetStartTime(), NULL)); |
| 206 file_value->SetString( | 207 file_value->SetString( |
| 207 "date_string", TimeFormatLongDate(download_item->GetStartTime())); | 208 "date_string", TimeFormatLongDate(download_item->GetStartTime())); |
| 208 | 209 |
| 209 file_value->SetString("id", base::Uint64ToString(download_item->GetId())); | 210 file_value->SetString("id", base::Uint64ToString(download_item->GetId())); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 size_t index = GetIndex(remove); | 413 size_t index = GetIndex(remove); |
| 413 if (index < sent_to_page_) { | 414 if (index < sent_to_page_) { |
| 414 web_ui_->CallJavascriptFunction( | 415 web_ui_->CallJavascriptFunction( |
| 415 "downloads.Manager.removeItem", | 416 "downloads.Manager.removeItem", |
| 416 base::FundamentalValue(static_cast<int>(index))); | 417 base::FundamentalValue(static_cast<int>(index))); |
| 417 sent_to_page_--; | 418 sent_to_page_--; |
| 418 } | 419 } |
| 419 } | 420 } |
| 420 sorted_items_.erase(remove); | 421 sorted_items_.erase(remove); |
| 421 } | 422 } |
| OLD | NEW |