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

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

Issue 10696208: Move ExtensionEventRouter and related into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed bug + latest master Created 8 years, 5 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 <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 12 matching lines...) Expand all
23 #include "base/string_split.h" 23 #include "base/string_split.h"
24 #include "base/string_util.h" 24 #include "base/string_util.h"
25 #include "base/stringprintf.h" 25 #include "base/stringprintf.h"
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/download/download_file_icon_extractor.h" 28 #include "chrome/browser/download/download_file_icon_extractor.h"
29 #include "chrome/browser/download/download_query.h" 29 #include "chrome/browser/download/download_query.h"
30 #include "chrome/browser/download/download_service.h" 30 #include "chrome/browser/download/download_service.h"
31 #include "chrome/browser/download/download_service_factory.h" 31 #include "chrome/browser/download/download_service_factory.h"
32 #include "chrome/browser/download/download_util.h" 32 #include "chrome/browser/download/download_util.h"
33 #include "chrome/browser/extensions/extension_event_names.h" 33 #include "chrome/browser/extensions/event_names.h"
34 #include "chrome/browser/extensions/extension_event_router.h" 34 #include "chrome/browser/extensions/event_router.h"
35 #include "chrome/browser/icon_loader.h" 35 #include "chrome/browser/icon_loader.h"
36 #include "chrome/browser/icon_manager.h" 36 #include "chrome/browser/icon_manager.h"
37 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 37 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
38 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/webui/web_ui_util.h" 39 #include "chrome/browser/ui/webui/web_ui_util.h"
40 #include "chrome/common/chrome_notification_types.h" 40 #include "chrome/common/chrome_notification_types.h"
41 #include "chrome/common/extensions/api/downloads.h" 41 #include "chrome/common/extensions/api/downloads.h"
42 #include "content/public/browser/download_interrupt_reasons.h" 42 #include "content/public/browser/download_interrupt_reasons.h"
43 #include "content/public/browser/download_item.h" 43 #include "content/public/browser/download_item.h"
44 #include "content/public/browser/download_save_info.h" 44 #include "content/public/browser/download_save_info.h"
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) { 823 void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) {
824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
825 int download_id = item->GetId(); 825 int download_id = item->GetId();
826 if (item->GetState() == DownloadItem::REMOVING) { 826 if (item->GetState() == DownloadItem::REMOVING) {
827 // The REMOVING state indicates that this item is being erased. 827 // The REMOVING state indicates that this item is being erased.
828 // Let's unregister as an observer so that we don't see any more updates 828 // Let's unregister as an observer so that we don't see any more updates
829 // from it, dispatch the onErased event, and remove its json and is 829 // from it, dispatch the onErased event, and remove its json and is
830 // OnChangedStat from our maps. 830 // OnChangedStat from our maps.
831 downloads_.erase(download_id); 831 downloads_.erase(download_id);
832 item->RemoveObserver(this); 832 item->RemoveObserver(this);
833 DispatchEvent(extension_event_names::kOnDownloadErased, 833 DispatchEvent(extensions::event_names::kOnDownloadErased,
834 base::Value::CreateIntegerValue(download_id)); 834 base::Value::CreateIntegerValue(download_id));
835 delete item_jsons_[download_id]; 835 delete item_jsons_[download_id];
836 item_jsons_.erase(download_id); 836 item_jsons_.erase(download_id);
837 delete on_changed_stats_[download_id]; 837 delete on_changed_stats_[download_id];
838 on_changed_stats_.erase(download_id); 838 on_changed_stats_.erase(download_id);
839 return; 839 return;
840 } 840 }
841 841
842 base::DictionaryValue* old_json = item_jsons_[download_id]; 842 base::DictionaryValue* old_json = item_jsons_[download_id];
843 scoped_ptr<base::DictionaryValue> new_json(DownloadItemToJSON(item)); 843 scoped_ptr<base::DictionaryValue> new_json(DownloadItemToJSON(item));
(...skipping 29 matching lines...) Expand all
873 if (new_fields.find(iter.key()) == new_fields.end()) { 873 if (new_fields.find(iter.key()) == new_fields.end()) {
874 delta->Set(iter.key() + ".previous", iter.value().DeepCopy()); 874 delta->Set(iter.key() + ".previous", iter.value().DeepCopy());
875 changed = true; 875 changed = true;
876 } 876 }
877 } 877 }
878 878
879 // Update the OnChangedStat and dispatch the event if something significant 879 // Update the OnChangedStat and dispatch the event if something significant
880 // changed. Replace the stored json with the new json. 880 // changed. Replace the stored json with the new json.
881 ++(on_changed_stats_[download_id]->total); 881 ++(on_changed_stats_[download_id]->total);
882 if (changed) { 882 if (changed) {
883 DispatchEvent(extension_event_names::kOnDownloadChanged, delta.release()); 883 DispatchEvent(extensions::event_names::kOnDownloadChanged, delta.release());
884 ++(on_changed_stats_[download_id]->fires); 884 ++(on_changed_stats_[download_id]->fires);
885 } 885 }
886 item_jsons_[download_id]->Swap(new_json.get()); 886 item_jsons_[download_id]->Swap(new_json.get());
887 } 887 }
888 888
889 void ExtensionDownloadsEventRouter::OnDownloadOpened(DownloadItem* item) { 889 void ExtensionDownloadsEventRouter::OnDownloadOpened(DownloadItem* item) {
890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
891 } 891 }
892 892
893 void ExtensionDownloadsEventRouter::ModelChanged(DownloadManager* manager) { 893 void ExtensionDownloadsEventRouter::ModelChanged(DownloadManager* manager) {
(...skipping 30 matching lines...) Expand all
924 new_set, new_set.begin())); 924 new_set, new_set.begin()));
925 925
926 // For each download that was not in the old set of downloads but is in the 926 // For each download that was not in the old set of downloads but is in the
927 // new set of downloads, fire an onCreated event, register as an Observer of 927 // new set of downloads, fire an onCreated event, register as an Observer of
928 // the item, store a json representation of the item so that we can easily 928 // the item, store a json representation of the item so that we can easily
929 // find changes in that json representation, and make an OnChangedStat. 929 // find changes in that json representation, and make an OnChangedStat.
930 for (DownloadIdSet::const_iterator iter = new_set.begin(); 930 for (DownloadIdSet::const_iterator iter = new_set.begin();
931 iter != new_set.end(); ++iter) { 931 iter != new_set.end(); ++iter) {
932 scoped_ptr<base::DictionaryValue> item( 932 scoped_ptr<base::DictionaryValue> item(
933 DownloadItemToJSON(current_map[*iter])); 933 DownloadItemToJSON(current_map[*iter]));
934 DispatchEvent(extension_event_names::kOnDownloadCreated, item->DeepCopy()); 934 DispatchEvent(extensions::event_names::kOnDownloadCreated,
935 item->DeepCopy());
935 DCHECK(item_jsons_.find(*iter) == item_jsons_.end()); 936 DCHECK(item_jsons_.find(*iter) == item_jsons_.end());
936 on_changed_stats_[*iter] = new OnChangedStat(); 937 on_changed_stats_[*iter] = new OnChangedStat();
937 current_map[*iter]->AddObserver(this); 938 current_map[*iter]->AddObserver(this);
938 item_jsons_[*iter] = item.release(); 939 item_jsons_[*iter] = item.release();
939 } 940 }
940 downloads_.swap(current_map); 941 downloads_.swap(current_map);
941 942
942 // Dispatching onErased is handled in OnDownloadUpdated when an item 943 // Dispatching onErased is handled in OnDownloadUpdated when an item
943 // transitions to the REMOVING state. 944 // transitions to the REMOVING state.
944 } 945 }
(...skipping 20 matching lines...) Expand all
965 extensions::EventFilteringInfo()); 966 extensions::EventFilteringInfo());
966 967
967 DownloadsNotificationSource notification_source; 968 DownloadsNotificationSource notification_source;
968 notification_source.event_name = event_name; 969 notification_source.event_name = event_name;
969 notification_source.profile = profile_; 970 notification_source.profile = profile_;
970 content::NotificationService::current()->Notify( 971 content::NotificationService::current()->Notify(
971 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, 972 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT,
972 content::Source<DownloadsNotificationSource>(&notification_source), 973 content::Source<DownloadsNotificationSource>(&notification_source),
973 content::Details<std::string>(&json_args)); 974 content::Details<std::string>(&json_args));
974 } 975 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698