OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <set> |
| 11 #include <string> |
| 12 |
| 13 #include "base/memory/singleton.h" |
| 14 #include "base/stl_util-inl.h" |
| 15 #include "chrome/browser/download/download_item.h" |
| 16 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/extensions/extension_function.h" |
| 18 |
| 19 class DictionaryValue; |
| 20 class ResourceDispatcherHost; |
| 21 class TabContents; |
| 22 namespace content { |
| 23 class ResourceContext; |
| 24 } |
| 25 |
| 26 // http://goo.gl/6hO1n |
| 27 |
| 28 class DownloadsDownloadFunction : public AsyncExtensionFunction { |
| 29 public: |
| 30 DownloadsDownloadFunction() |
| 31 : options_(NULL), |
| 32 save_as_(false), |
| 33 extra_headers_(NULL), |
| 34 dl_man_(NULL), |
| 35 rdh_(NULL), |
| 36 tab_contents_(NULL), |
| 37 resource_context_(NULL), |
| 38 render_process_host_id_(0), |
| 39 render_view_host_routing_id_(0), |
| 40 products_(NULL), |
| 41 dl_id_(-1), |
| 42 dl_error_(0) { |
| 43 } |
| 44 virtual ~DownloadsDownloadFunction() {} |
| 45 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.download"); |
| 46 |
| 47 virtual bool RunImpl() OVERRIDE; |
| 48 |
| 49 private: |
| 50 void BeginDownloadOnIOThread(); |
| 51 void OnStarted(int dl_id, int error); |
| 52 void RespondOnUIThread(); |
| 53 |
| 54 DictionaryValue* options_; |
| 55 std::string url_; |
| 56 std::string filename_; |
| 57 bool save_as_; |
| 58 DictionaryValue* extra_headers_; |
| 59 std::string method_; |
| 60 std::string post_body_; |
| 61 |
| 62 DownloadManager* dl_man_; |
| 63 ResourceDispatcherHost* rdh_; |
| 64 TabContents* tab_contents_; |
| 65 const content::ResourceContext* resource_context_; |
| 66 int render_process_host_id_; |
| 67 int render_view_host_routing_id_; |
| 68 |
| 69 DictionaryValue* products_; |
| 70 int dl_id_; |
| 71 int dl_error_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction); |
| 74 }; |
| 75 |
| 76 class DownloadsSearchFunction : public SyncExtensionFunction { |
| 77 public: |
| 78 DownloadsSearchFunction() {} |
| 79 virtual ~DownloadsSearchFunction() {} |
| 80 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.search"); |
| 81 |
| 82 virtual bool RunImpl() OVERRIDE; |
| 83 |
| 84 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(DownloadsSearchFunction); |
| 86 }; |
| 87 |
| 88 class DownloadsPauseFunction : public SyncExtensionFunction { |
| 89 public: |
| 90 DownloadsPauseFunction() {} |
| 91 virtual ~DownloadsPauseFunction() {} |
| 92 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.pause"); |
| 93 |
| 94 virtual bool RunImpl() OVERRIDE; |
| 95 |
| 96 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(DownloadsPauseFunction); |
| 98 }; |
| 99 |
| 100 class DownloadsResumeFunction : public AsyncExtensionFunction { |
| 101 public: |
| 102 DownloadsResumeFunction() {} |
| 103 virtual ~DownloadsResumeFunction() {} |
| 104 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.resume"); |
| 105 |
| 106 virtual bool RunImpl() OVERRIDE; |
| 107 |
| 108 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(DownloadsResumeFunction); |
| 110 }; |
| 111 |
| 112 class DownloadsCancelFunction : public AsyncExtensionFunction { |
| 113 public: |
| 114 DownloadsCancelFunction() {} |
| 115 virtual ~DownloadsCancelFunction() {} |
| 116 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.cancel"); |
| 117 |
| 118 virtual bool RunImpl() OVERRIDE; |
| 119 |
| 120 private: |
| 121 DISALLOW_COPY_AND_ASSIGN(DownloadsCancelFunction); |
| 122 }; |
| 123 |
| 124 class DownloadsEraseFunction : public AsyncExtensionFunction { |
| 125 public: |
| 126 DownloadsEraseFunction() {} |
| 127 virtual ~DownloadsEraseFunction() {} |
| 128 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.erase"); |
| 129 |
| 130 virtual bool RunImpl() OVERRIDE; |
| 131 |
| 132 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
| 134 }; |
| 135 |
| 136 class DownloadsSetDestinationFunction : public AsyncExtensionFunction { |
| 137 public: |
| 138 DownloadsSetDestinationFunction() {} |
| 139 virtual ~DownloadsSetDestinationFunction() {} |
| 140 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.setDestination"); |
| 141 |
| 142 virtual bool RunImpl() OVERRIDE; |
| 143 |
| 144 private: |
| 145 DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction); |
| 146 }; |
| 147 |
| 148 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { |
| 149 public: |
| 150 DownloadsAcceptDangerFunction() {} |
| 151 virtual ~DownloadsAcceptDangerFunction() {} |
| 152 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.acceptDanger"); |
| 153 |
| 154 virtual bool RunImpl() OVERRIDE; |
| 155 |
| 156 private: |
| 157 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction); |
| 158 }; |
| 159 |
| 160 class DownloadsShowFunction : public AsyncExtensionFunction { |
| 161 public: |
| 162 DownloadsShowFunction() {} |
| 163 virtual ~DownloadsShowFunction() {} |
| 164 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.show"); |
| 165 |
| 166 virtual bool RunImpl() OVERRIDE; |
| 167 |
| 168 private: |
| 169 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction); |
| 170 }; |
| 171 |
| 172 class DownloadsDragFunction : public AsyncExtensionFunction { |
| 173 public: |
| 174 DownloadsDragFunction() {} |
| 175 virtual ~DownloadsDragFunction() {} |
| 176 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.drag"); |
| 177 |
| 178 virtual bool RunImpl() OVERRIDE; |
| 179 |
| 180 private: |
| 181 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); |
| 182 }; |
| 183 |
| 184 class DownloadsEventRouter { |
| 185 public: |
| 186 enum EventType { |
| 187 CREATED, |
| 188 CHANGED, |
| 189 ERASED, |
| 190 }; |
| 191 |
| 192 static DownloadsEventRouter* GetInstance(); |
| 193 |
| 194 void AddEventListener( |
| 195 EventType event_type, |
| 196 ProfileId profile_id, |
| 197 const std::string& extension_id, |
| 198 base::WeakPtr<IPC::Message::Sender> ipc_sender); |
| 199 |
| 200 void DispatchEvent( |
| 201 EventType event_type, |
| 202 ProfileId profile_id, |
| 203 int download_id); |
| 204 |
| 205 // But I'm a frickin singleton... |
| 206 void AddRef() {} |
| 207 void Release() {} |
| 208 static bool ImplementsThreadSafeReferenceCounting() { return true; } |
| 209 |
| 210 private: |
| 211 DownloadsEventRouter(); |
| 212 ~DownloadsEventRouter(); |
| 213 |
| 214 friend struct DefaultSingletonTraits<DownloadsEventRouter>; |
| 215 struct EventListener; |
| 216 class ManagerObserver; |
| 217 class ItemObserver; |
| 218 typedef std::set<EventListener> ListenerSet; |
| 219 typedef std::map<EventType, ListenerSet> ListenerMapForProfile; |
| 220 typedef std::map<ProfileId, ListenerMapForProfile> ListenerMap; |
| 221 typedef std::map<ProfileId, ManagerObserver*> ManagerObservers; |
| 222 typedef std::map<int/*download_id*/, ItemObserver> ItemObserversForProfile; |
| 223 typedef std::map<ProfileId, ItemObserversForProfile> ItemObservers; |
| 224 |
| 225 ListenerMap listeners_; |
| 226 ManagerObservers manager_observers_; |
| 227 ItemObservers item_observers_; |
| 228 //STLValueDeleter<ManagerObservers> delete_manager_observers_; |
| 229 |
| 230 DISALLOW_COPY_AND_ASSIGN(DownloadsEventRouter); |
| 231 }; |
| 232 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_H_ |
OLD | NEW |