OLD | NEW |
---|---|
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/download/download_extension_api.h" | 5 #include "chrome/browser/download/download_extension_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 19 matching lines...) Expand all Loading... | |
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/extension_event_names.h" |
34 #include "chrome/browser/extensions/extension_event_router.h" | 34 #include "chrome/browser/extensions/extension_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_list.h" | 38 #include "chrome/browser/ui/browser_list.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 "content/public/browser/download_interrupt_reasons.h" | 41 #include "content/public/browser/download_interrupt_reasons.h" |
41 #include "content/public/browser/download_item.h" | 42 #include "content/public/browser/download_item.h" |
42 #include "content/public/browser/download_save_info.h" | 43 #include "content/public/browser/download_save_info.h" |
44 #include "content/public/browser/notification_service.h" | |
43 #include "content/public/browser/render_process_host.h" | 45 #include "content/public/browser/render_process_host.h" |
44 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/resource_dispatcher_host.h" | 47 #include "content/public/browser/resource_dispatcher_host.h" |
46 #include "net/base/load_flags.h" | 48 #include "net/base/load_flags.h" |
47 #include "net/http/http_util.h" | 49 #include "net/http/http_util.h" |
48 #include "net/url_request/url_request.h" | 50 #include "net/url_request/url_request.h" |
49 | 51 |
50 using content::BrowserContext; | 52 using content::BrowserContext; |
51 using content::BrowserThread; | 53 using content::BrowserThread; |
52 using content::DownloadId; | 54 using content::DownloadId; |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 : fires(0), | 977 : fires(0), |
976 total(0) { | 978 total(0) { |
977 } | 979 } |
978 | 980 |
979 ExtensionDownloadsEventRouter::OnChangedStat::~OnChangedStat() { | 981 ExtensionDownloadsEventRouter::OnChangedStat::~OnChangedStat() { |
980 if (total > 0) | 982 if (total > 0) |
981 UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", (fires * 100 / total)); | 983 UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", (fires * 100 / total)); |
982 } | 984 } |
983 | 985 |
984 void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) { | 986 void ExtensionDownloadsEventRouter::OnDownloadUpdated(DownloadItem* item) { |
987 if (!profile_) | |
988 return; | |
985 int download_id = item->GetId(); | 989 int download_id = item->GetId(); |
986 if (item->GetState() == DownloadItem::REMOVING) { | 990 if (item->GetState() == DownloadItem::REMOVING) { |
987 // The REMOVING state indicates that this item is being erased. | 991 // The REMOVING state indicates that this item is being erased. |
988 // Let's unregister as an observer so that we don't see any more updates | 992 // Let's unregister as an observer so that we don't see any more updates |
989 // from it, dispatch the onErased event, and remove its json and is | 993 // from it, dispatch the onErased event, and remove its json and is |
990 // OnChangedStat from our maps. | 994 // OnChangedStat from our maps. |
991 downloads_.erase(download_id); | 995 downloads_.erase(download_id); |
992 item->RemoveObserver(this); | 996 item->RemoveObserver(this); |
993 DispatchEvent(extension_event_names::kOnDownloadErased, | 997 DispatchEvent(extension_event_names::kOnDownloadErased, |
994 base::Value::CreateIntegerValue(download_id)); | 998 base::Value::CreateIntegerValue(download_id)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 downloads_.swap(current_map); | 1103 downloads_.swap(current_map); |
1100 | 1104 |
1101 // Dispatching onErased is handled in OnDownloadUpdated when an item | 1105 // Dispatching onErased is handled in OnDownloadUpdated when an item |
1102 // transitions to the REMOVING state. | 1106 // transitions to the REMOVING state. |
1103 } | 1107 } |
1104 | 1108 |
1105 void ExtensionDownloadsEventRouter::ManagerGoingDown( | 1109 void ExtensionDownloadsEventRouter::ManagerGoingDown( |
1106 DownloadManager* manager) { | 1110 DownloadManager* manager) { |
1107 manager_->RemoveObserver(this); | 1111 manager_->RemoveObserver(this); |
1108 manager_ = NULL; | 1112 manager_ = NULL; |
1113 profile_ = NULL; | |
Randy Smith (Not in Mondays)
2012/06/18 18:42:58
So this means that you'll not handle the notificat
benjhayden
2012/06/19 15:01:59
When I made ChromeDownloadManagerDelegate own Exte
Randy Smith (Not in Mondays)
2012/06/19 19:23:23
Sure, that's a problem, but you've chosen one part
benjhayden
2012/06/21 17:50:48
An extension that wants to keep track of the state
| |
1109 } | 1114 } |
1110 | 1115 |
1111 void ExtensionDownloadsEventRouter::DispatchEvent( | 1116 void ExtensionDownloadsEventRouter::DispatchEvent( |
1112 const char* event_name, base::Value* arg) { | 1117 const char* event_name, base::Value* arg) { |
1118 if (!profile_) | |
1119 return; | |
1113 ListValue args; | 1120 ListValue args; |
1114 args.Append(arg); | 1121 args.Append(arg); |
1115 std::string json_args; | 1122 std::string json_args; |
1116 base::JSONWriter::Write(&args, &json_args); | 1123 base::JSONWriter::Write(&args, &json_args); |
1117 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 1124 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
1118 event_name, | 1125 event_name, |
1119 json_args, | 1126 json_args, |
1120 profile_, | 1127 profile_, |
1121 GURL()); | 1128 GURL()); |
1129 DownloadsNotificationSource notification_source; | |
1130 notification_source.event_name = event_name; | |
1131 notification_source.profile = profile_; | |
1132 content::NotificationService::current()->Notify( | |
1133 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, | |
1134 content::Source<DownloadsNotificationSource>(¬ification_source), | |
1135 content::Details<std::string>(&json_args)); | |
Randy Smith (Not in Mondays)
2012/06/18 18:42:58
This is two different mechanisms for notifying abo
benjhayden
2012/06/19 15:01:59
EDER is-a DM::O already. How would making it a DM:
Randy Smith (Not in Mondays)
2012/06/19 19:23:23
Sorry, this is my cluelessness; I didn't notice th
| |
1122 } | 1136 } |
OLD | NEW |