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

Side by Side Diff: chrome/browser/extensions/extension_downloads_api.h

Issue 8203005: Implement chrome.experimental.downloads.onChanged (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/stl_util.h"
15 #include "base/string16.h" 16 #include "base/string16.h"
16 #include "chrome/browser/extensions/extension_function.h" 17 #include "chrome/browser/extensions/extension_function.h"
17 #include "content/browser/download/download_item.h" 18 #include "content/browser/download/download_item.h"
18 #include "content/browser/download/download_manager.h" 19 #include "content/browser/download/download_manager.h"
19 20
20 namespace base { 21 namespace base {
21 class DictionaryValue; 22 class DictionaryValue;
22 } 23 }
23 class ResourceDispatcherHost; 24 class ResourceDispatcherHost;
24 class TabContents; 25 class TabContents;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.drag"); 249 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.drag");
249 250
250 protected: 251 protected:
251 virtual bool ParseArgs() OVERRIDE; 252 virtual bool ParseArgs() OVERRIDE;
252 virtual void RunInternal() OVERRIDE; 253 virtual void RunInternal() OVERRIDE;
253 254
254 private: 255 private:
255 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction); 256 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction);
256 }; 257 };
257 258
259 // Observes a single DownloadManager and dispatches onCreated and onErased
260 // events.
258 class ExtensionDownloadsEventRouter : public DownloadManager::Observer { 261 class ExtensionDownloadsEventRouter : public DownloadManager::Observer {
259 public: 262 public:
260 explicit ExtensionDownloadsEventRouter(Profile* profile); 263 explicit ExtensionDownloadsEventRouter(Profile* profile);
261 virtual ~ExtensionDownloadsEventRouter(); 264 virtual ~ExtensionDownloadsEventRouter();
262 265
263 virtual void ModelChanged() OVERRIDE; 266 virtual void ModelChanged() OVERRIDE;
264 virtual void ManagerGoingDown() OVERRIDE; 267 virtual void ManagerGoingDown() OVERRIDE;
265 268
266 private: 269 private:
267 void DispatchEvent(const char* event_name, base::Value* json_arg); 270 // Observes a single DownloadItem and dispatches onChanged events.
Randy Smith (Not in Mondays) 2011/10/12 18:46:30 Might want a comment here as to why it's not a mix
benjhayden 2011/10/13 16:30:29 Done.
271 class ItemObserver : public DownloadItem::Observer {
272 public:
273 typedef base::Callback<void(base::Value*)> EventDispatcher;
274 ItemObserver(const EventDispatcher& dispatcher, DownloadItem* item);
275 virtual ~ItemObserver();
276
277 virtual void OnDownloadUpdated(DownloadItem* download);
278 virtual void OnDownloadOpened(DownloadItem* download);
279
280 private:
281 EventDispatcher dispatcher_;
282 DownloadItem* item_;
283 scoped_ptr<base::DictionaryValue> json_;
284
285 DISALLOW_COPY_AND_ASSIGN(ItemObserver);
286 };
287
268 typedef base::hash_map<int, DownloadItem*> ItemMap; 288 typedef base::hash_map<int, DownloadItem*> ItemMap;
269 typedef std::set<int> DownloadIdSet; 289 typedef std::set<int> DownloadIdSet;
290 typedef base::hash_map<int, ItemObserver*> ItemObserverMap;
291
292 void DispatchEvent(const char* event_name, base::Value* json_arg);
270 293
271 Profile* profile_; 294 Profile* profile_;
272 DownloadManager* manager_; 295 DownloadManager* manager_;
273 DownloadIdSet downloads_; 296 DownloadIdSet downloads_;
297 ItemObserverMap item_observers_;
298 STLValueDeleter<ItemObserverMap> delete_item_observers_;
274 299
275 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); 300 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
276 }; 301 };
277 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_ 302 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698