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

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

Issue 2323993004: Remove use of deprecated base::ListValue::Append(Value*) overload in extensions. (Closed)
Patch Set: ... I hate C++ 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 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 const FilenameChangedCallback& change) { 1602 const FilenameChangedCallback& change) {
1603 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1603 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1604 ExtensionDownloadsEventRouterData* data = 1604 ExtensionDownloadsEventRouterData* data =
1605 ExtensionDownloadsEventRouterData::Get(item); 1605 ExtensionDownloadsEventRouterData::Get(item);
1606 if (!data) { 1606 if (!data) {
1607 no_change.Run(); 1607 no_change.Run();
1608 return; 1608 return;
1609 } 1609 }
1610 data->BeginFilenameDetermination(no_change, change); 1610 data->BeginFilenameDetermination(no_change, change);
1611 bool any_determiners = false; 1611 bool any_determiners = false;
1612 base::DictionaryValue* json = DownloadItemToJSON( 1612 std::unique_ptr<base::DictionaryValue> json =
1613 item, profile_).release(); 1613 DownloadItemToJSON(item, profile_);
1614 json->SetString(kFilenameKey, suggested_path.LossyDisplayName()); 1614 json->SetString(kFilenameKey, suggested_path.LossyDisplayName());
1615 DispatchEvent(events::DOWNLOADS_ON_DETERMINING_FILENAME, 1615 DispatchEvent(events::DOWNLOADS_ON_DETERMINING_FILENAME,
1616 downloads::OnDeterminingFilename::kEventName, false, 1616 downloads::OnDeterminingFilename::kEventName, false,
1617 base::Bind(&OnDeterminingFilenameWillDispatchCallback, 1617 base::Bind(&OnDeterminingFilenameWillDispatchCallback,
1618 &any_determiners, data), 1618 &any_determiners, data),
1619 json); 1619 std::move(json));
1620 if (!any_determiners) { 1620 if (!any_determiners) {
1621 data->ClearPendingDeterminers(); 1621 data->ClearPendingDeterminers();
1622 if (!data->creator_suggested_filename().empty() || 1622 if (!data->creator_suggested_filename().empty() ||
1623 (data->creator_conflict_action() != 1623 (data->creator_conflict_action() !=
1624 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { 1624 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) {
1625 change.Run(data->creator_suggested_filename(), 1625 change.Run(data->creator_suggested_filename(),
1626 ConvertConflictAction(data->creator_conflict_action())); 1626 ConvertConflictAction(data->creator_conflict_action()));
1627 // If all listeners are removed, don't keep |data| around. 1627 // If all listeners are removed, don't keep |data| around.
1628 data->ResetCreatorSuggestion(); 1628 data->ResetCreatorSuggestion();
1629 } else { 1629 } else {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 if (!router || 1770 if (!router ||
1771 (!router->HasEventListener(downloads::OnCreated::kEventName) && 1771 (!router->HasEventListener(downloads::OnCreated::kEventName) &&
1772 !router->HasEventListener(downloads::OnChanged::kEventName) && 1772 !router->HasEventListener(downloads::OnChanged::kEventName) &&
1773 !router->HasEventListener( 1773 !router->HasEventListener(
1774 downloads::OnDeterminingFilename::kEventName))) { 1774 downloads::OnDeterminingFilename::kEventName))) {
1775 return; 1775 return;
1776 } 1776 }
1777 std::unique_ptr<base::DictionaryValue> json_item( 1777 std::unique_ptr<base::DictionaryValue> json_item(
1778 DownloadItemToJSON(download_item, profile_)); 1778 DownloadItemToJSON(download_item, profile_));
1779 DispatchEvent(events::DOWNLOADS_ON_CREATED, downloads::OnCreated::kEventName, 1779 DispatchEvent(events::DOWNLOADS_ON_CREATED, downloads::OnCreated::kEventName,
1780 true, Event::WillDispatchCallback(), json_item->DeepCopy()); 1780 true, Event::WillDispatchCallback(),
1781 json_item->CreateDeepCopy());
1781 if (!ExtensionDownloadsEventRouterData::Get(download_item) && 1782 if (!ExtensionDownloadsEventRouterData::Get(download_item) &&
1782 (router->HasEventListener(downloads::OnChanged::kEventName) || 1783 (router->HasEventListener(downloads::OnChanged::kEventName) ||
1783 router->HasEventListener( 1784 router->HasEventListener(
1784 downloads::OnDeterminingFilename::kEventName))) { 1785 downloads::OnDeterminingFilename::kEventName))) {
1785 new ExtensionDownloadsEventRouterData(download_item, std::move(json_item)); 1786 new ExtensionDownloadsEventRouterData(download_item, std::move(json_item));
1786 } 1787 }
1787 } 1788 }
1788 1789
1789 void ExtensionDownloadsEventRouter::OnDownloadUpdated( 1790 void ExtensionDownloadsEventRouter::OnDownloadUpdated(
1790 DownloadManager* manager, DownloadItem* download_item) { 1791 DownloadManager* manager, DownloadItem* download_item) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 changed = true; 1842 changed = true;
1842 } 1843 }
1843 } 1844 }
1844 1845
1845 // Update the OnChangedStat and dispatch the event if something significant 1846 // Update the OnChangedStat and dispatch the event if something significant
1846 // changed. Replace the stored json with the new json. 1847 // changed. Replace the stored json with the new json.
1847 data->OnItemUpdated(); 1848 data->OnItemUpdated();
1848 if (changed) { 1849 if (changed) {
1849 DispatchEvent(events::DOWNLOADS_ON_CHANGED, 1850 DispatchEvent(events::DOWNLOADS_ON_CHANGED,
1850 downloads::OnChanged::kEventName, true, 1851 downloads::OnChanged::kEventName, true,
1851 Event::WillDispatchCallback(), delta.release()); 1852 Event::WillDispatchCallback(), std::move(delta));
1852 data->OnChangedFired(); 1853 data->OnChangedFired();
1853 } 1854 }
1854 data->set_json(std::move(new_json)); 1855 data->set_json(std::move(new_json));
1855 } 1856 }
1856 1857
1857 void ExtensionDownloadsEventRouter::OnDownloadRemoved( 1858 void ExtensionDownloadsEventRouter::OnDownloadRemoved(
1858 DownloadManager* manager, DownloadItem* download_item) { 1859 DownloadManager* manager, DownloadItem* download_item) {
1859 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1860 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1860 if (download_item->IsTemporary()) 1861 if (download_item->IsTemporary())
1861 return; 1862 return;
1862 DispatchEvent( 1863 DispatchEvent(events::DOWNLOADS_ON_ERASED, downloads::OnErased::kEventName,
1863 events::DOWNLOADS_ON_ERASED, downloads::OnErased::kEventName, true, 1864 true, Event::WillDispatchCallback(),
1864 Event::WillDispatchCallback(), 1865 base::MakeUnique<base::FundamentalValue>(
1865 new base::FundamentalValue(static_cast<int>(download_item->GetId()))); 1866 static_cast<int>(download_item->GetId())));
1866 } 1867 }
1867 1868
1868 void ExtensionDownloadsEventRouter::DispatchEvent( 1869 void ExtensionDownloadsEventRouter::DispatchEvent(
1869 events::HistogramValue histogram_value, 1870 events::HistogramValue histogram_value,
1870 const std::string& event_name, 1871 const std::string& event_name,
1871 bool include_incognito, 1872 bool include_incognito,
1872 const Event::WillDispatchCallback& will_dispatch_callback, 1873 const Event::WillDispatchCallback& will_dispatch_callback,
1873 base::Value* arg) { 1874 std::unique_ptr<base::Value> arg) {
1874 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1875 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1875 if (!EventRouter::Get(profile_)) 1876 if (!EventRouter::Get(profile_))
1876 return; 1877 return;
1877 std::unique_ptr<base::ListValue> args(new base::ListValue()); 1878 std::unique_ptr<base::ListValue> args(new base::ListValue());
1878 args->Append(arg); 1879 args->Append(std::move(arg));
1879 std::string json_args; 1880 std::string json_args;
1880 base::JSONWriter::Write(*args, &json_args); 1881 base::JSONWriter::Write(*args, &json_args);
1881 std::unique_ptr<Event> event( 1882 std::unique_ptr<Event> event(
1882 new Event(histogram_value, event_name, std::move(args))); 1883 new Event(histogram_value, event_name, std::move(args)));
1883 // The downloads system wants to share on-record events with off-record 1884 // The downloads system wants to share on-record events with off-record
1884 // extension renderers even in incognito_split_mode because that's how 1885 // extension renderers even in incognito_split_mode because that's how
1885 // chrome://downloads works. The "restrict_to_profile" mechanism does not 1886 // chrome://downloads works. The "restrict_to_profile" mechanism does not
1886 // anticipate this, so it does not automatically prevent sharing off-record 1887 // anticipate this, so it does not automatically prevent sharing off-record
1887 // events with on-record extension renderers. 1888 // events with on-record extension renderers.
1888 event->restrict_to_browser_context = 1889 event->restrict_to_browser_context =
(...skipping 29 matching lines...) Expand all
1918 return; 1919 return;
1919 base::Time now(base::Time::Now()); 1920 base::Time now(base::Time::Now());
1920 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); 1921 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT();
1921 if (delta <= kFileExistenceRateLimitSeconds) 1922 if (delta <= kFileExistenceRateLimitSeconds)
1922 return; 1923 return;
1923 last_checked_removal_ = now; 1924 last_checked_removal_ = now;
1924 manager->CheckForHistoryFilesRemoval(); 1925 manager->CheckForHistoryFilesRemoval();
1925 } 1926 }
1926 1927
1927 } // namespace extensions 1928 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698