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

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

Issue 280853004: Use EventRouter::Get instead of ExtensionSystem::Get(browser_context)->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); 274 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining));
275 } 275 }
276 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); 276 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item);
277 if (by_ext) { 277 if (by_ext) {
278 json->SetString(kByExtensionIdKey, by_ext->id()); 278 json->SetString(kByExtensionIdKey, by_ext->id());
279 json->SetString(kByExtensionNameKey, by_ext->name()); 279 json->SetString(kByExtensionNameKey, by_ext->name());
280 // Lookup the extension's current name() in case the user changed their 280 // Lookup the extension's current name() in case the user changed their
281 // language. This won't work if the extension was uninstalled, so the name 281 // language. This won't work if the extension was uninstalled, so the name
282 // might be the wrong language. 282 // might be the wrong language.
283 bool include_disabled = true; 283 bool include_disabled = true;
284 const extensions::Extension* extension = extensions::ExtensionSystem::Get( 284 const extensions::Extension* extension = extensions::ExtensionSystem::Get(
Devlin 2014/05/16 15:32:53 This is totally unrelated to this patch... but sin
limasdf 2014/05/16 16:25:03 Done.
285 profile)->extension_service()->GetExtensionById( 285 profile)->extension_service()->GetExtensionById(
286 by_ext->id(), include_disabled); 286 by_ext->id(), include_disabled);
287 if (extension) 287 if (extension)
288 json->SetString(kByExtensionNameKey, extension->name()); 288 json->SetString(kByExtensionNameKey, extension->name());
289 } 289 }
290 // TODO(benjhayden): Implement fileSize. 290 // TODO(benjhayden): Implement fileSize.
291 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes()); 291 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes());
292 return scoped_ptr<base::DictionaryValue>(json); 292 return scoped_ptr<base::DictionaryValue>(json);
293 } 293 }
294 294
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 if (Fault(!data->DeterminerCallback( 1730 if (Fault(!data->DeterminerCallback(
1731 profile, ext_id, filename, conflict_action), 1731 profile, ext_id, filename, conflict_action),
1732 errors::kUnexpectedDeterminer, error) || 1732 errors::kUnexpectedDeterminer, error) ||
1733 Fault((!const_filename.empty() && !valid_filename), 1733 Fault((!const_filename.empty() && !valid_filename),
1734 errors::kInvalidFilename, error)) 1734 errors::kInvalidFilename, error))
1735 return false; 1735 return false;
1736 return true; 1736 return true;
1737 } 1737 }
1738 1738
1739 void ExtensionDownloadsEventRouter::OnListenerRemoved( 1739 void ExtensionDownloadsEventRouter::OnListenerRemoved(
1740 const extensions::EventListenerInfo& details) { 1740 const extensions::EventListenerInfo& details) {
Devlin 2014/05/16 15:32:53 Can you take out the extensions:: prefixes in this
limasdf 2014/05/16 16:25:03 Done.
1741 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1741 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1742 DownloadManager* manager = notifier_.GetManager(); 1742 DownloadManager* manager = notifier_.GetManager();
1743 if (!manager) 1743 if (!manager)
1744 return; 1744 return;
1745 bool determiner_removed = ( 1745 bool determiner_removed = (
1746 details.event_name == downloads::OnDeterminingFilename::kEventName); 1746 details.event_name == downloads::OnDeterminingFilename::kEventName);
1747 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> 1747 EventRouter* router = EventRouter::Get(profile_);
1748 event_router();
1749 bool any_listeners = 1748 bool any_listeners =
1750 router->HasEventListener(downloads::OnChanged::kEventName) || 1749 router->HasEventListener(downloads::OnChanged::kEventName) ||
1751 router->HasEventListener(downloads::OnDeterminingFilename::kEventName); 1750 router->HasEventListener(downloads::OnDeterminingFilename::kEventName);
1752 if (!determiner_removed && any_listeners) 1751 if (!determiner_removed && any_listeners)
1753 return; 1752 return;
1754 DownloadManager::DownloadVector items; 1753 DownloadManager::DownloadVector items;
1755 manager->GetAllDownloads(&items); 1754 manager->GetAllDownloads(&items);
1756 for (DownloadManager::DownloadVector::const_iterator iter = 1755 for (DownloadManager::DownloadVector::const_iterator iter =
1757 items.begin(); 1756 items.begin();
1758 iter != items.end(); ++iter) { 1757 iter != items.end(); ++iter) {
(...skipping 18 matching lines...) Expand all
1777 1776
1778 // That's all the methods that have to do with filename determination. The rest 1777 // That's all the methods that have to do with filename determination. The rest
1779 // have to do with the other, less special events. 1778 // have to do with the other, less special events.
1780 1779
1781 void ExtensionDownloadsEventRouter::OnDownloadCreated( 1780 void ExtensionDownloadsEventRouter::OnDownloadCreated(
1782 DownloadManager* manager, DownloadItem* download_item) { 1781 DownloadManager* manager, DownloadItem* download_item) {
1783 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1784 if (download_item->IsTemporary()) 1783 if (download_item->IsTemporary())
1785 return; 1784 return;
1786 1785
1787 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> 1786 EventRouter* router = EventRouter::Get(profile_);
1788 event_router();
1789 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going 1787 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going
1790 // to be used. 1788 // to be used.
1791 if (!router || 1789 if (!router ||
1792 (!router->HasEventListener(downloads::OnCreated::kEventName) && 1790 (!router->HasEventListener(downloads::OnCreated::kEventName) &&
1793 !router->HasEventListener(downloads::OnChanged::kEventName) && 1791 !router->HasEventListener(downloads::OnChanged::kEventName) &&
1794 !router->HasEventListener( 1792 !router->HasEventListener(
1795 downloads::OnDeterminingFilename::kEventName))) { 1793 downloads::OnDeterminingFilename::kEventName))) {
1796 return; 1794 return;
1797 } 1795 }
1798 scoped_ptr<base::DictionaryValue> json_item( 1796 scoped_ptr<base::DictionaryValue> json_item(
1799 DownloadItemToJSON(download_item, profile_)); 1797 DownloadItemToJSON(download_item, profile_));
1800 DispatchEvent(downloads::OnCreated::kEventName, 1798 DispatchEvent(downloads::OnCreated::kEventName,
1801 true, 1799 true,
1802 extensions::Event::WillDispatchCallback(), 1800 extensions::Event::WillDispatchCallback(),
1803 json_item->DeepCopy()); 1801 json_item->DeepCopy());
1804 if (!ExtensionDownloadsEventRouterData::Get(download_item) && 1802 if (!ExtensionDownloadsEventRouterData::Get(download_item) &&
1805 (router->HasEventListener(downloads::OnChanged::kEventName) || 1803 (router->HasEventListener(downloads::OnChanged::kEventName) ||
1806 router->HasEventListener( 1804 router->HasEventListener(
1807 downloads::OnDeterminingFilename::kEventName))) { 1805 downloads::OnDeterminingFilename::kEventName))) {
1808 new ExtensionDownloadsEventRouterData(download_item, json_item.Pass()); 1806 new ExtensionDownloadsEventRouterData(download_item, json_item.Pass());
1809 } 1807 }
1810 } 1808 }
1811 1809
1812 void ExtensionDownloadsEventRouter::OnDownloadUpdated( 1810 void ExtensionDownloadsEventRouter::OnDownloadUpdated(
1813 DownloadManager* manager, DownloadItem* download_item) { 1811 DownloadManager* manager, DownloadItem* download_item) {
1814 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1812 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1815 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> 1813 EventRouter* router = EventRouter::Get(profile_);
1816 event_router();
1817 ExtensionDownloadsEventRouterData* data = 1814 ExtensionDownloadsEventRouterData* data =
1818 ExtensionDownloadsEventRouterData::Get(download_item); 1815 ExtensionDownloadsEventRouterData::Get(download_item);
1819 if (download_item->IsTemporary() || 1816 if (download_item->IsTemporary() ||
1820 !router->HasEventListener(downloads::OnChanged::kEventName)) { 1817 !router->HasEventListener(downloads::OnChanged::kEventName)) {
1821 return; 1818 return;
1822 } 1819 }
1823 if (!data) { 1820 if (!data) {
1824 // The download_item probably transitioned from temporary to not temporary, 1821 // The download_item probably transitioned from temporary to not temporary,
1825 // or else an event listener was added. 1822 // or else an event listener was added.
1826 data = new ExtensionDownloadsEventRouterData( 1823 data = new ExtensionDownloadsEventRouterData(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 const extensions::Extension* extension, 1927 const extensions::Extension* extension,
1931 extensions::UnloadedExtensionInfo::Reason reason) { 1928 extensions::UnloadedExtensionInfo::Reason reason) {
1932 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1929 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1933 std::set<const extensions::Extension*>::iterator iter = 1930 std::set<const extensions::Extension*>::iterator iter =
1934 shelf_disabling_extensions_.find(extension); 1931 shelf_disabling_extensions_.find(extension);
1935 if (iter != shelf_disabling_extensions_.end()) 1932 if (iter != shelf_disabling_extensions_.end())
1936 shelf_disabling_extensions_.erase(iter); 1933 shelf_disabling_extensions_.erase(iter);
1937 } 1934 }
1938 1935
1939 } // namespace extensions 1936 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698