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

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: on_changed_stats_,OnChangedStat 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
258 class ExtensionDownloadsEventRouter : public DownloadManager::Observer { 259 // Observes a single DownloadManager and many DownloadItems and dispatches
260 // onCreated and onErased events.
261 class ExtensionDownloadsEventRouter : public DownloadManager::Observer,
262 public DownloadItem::Observer {
259 public: 263 public:
260 explicit ExtensionDownloadsEventRouter(Profile* profile); 264 explicit ExtensionDownloadsEventRouter(Profile* profile);
261 virtual ~ExtensionDownloadsEventRouter(); 265 virtual ~ExtensionDownloadsEventRouter();
262 266
263 virtual void ModelChanged() OVERRIDE; 267 virtual void ModelChanged() OVERRIDE;
264 virtual void ManagerGoingDown() OVERRIDE; 268 virtual void ManagerGoingDown() OVERRIDE;
269 virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE;
270 virtual void OnDownloadOpened(DownloadItem* download) OVERRIDE;
265 271
266 private: 272 private:
273 struct OnChangedStat {
274 OnChangedStat();
275 ~OnChangedStat();
276 int fires;
277 int total;
278 };
279
280 typedef std::map<int, DownloadItem*> ItemMap;
281 typedef std::map<int, base::DictionaryValue*> ItemJsonMap;
282 typedef std::map<int, OnChangedStat*> OnChangedStatMap;
283
267 void DispatchEvent(const char* event_name, base::Value* json_arg); 284 void DispatchEvent(const char* event_name, base::Value* json_arg);
268 typedef base::hash_map<int, DownloadItem*> ItemMap;
269 typedef std::set<int> DownloadIdSet;
270 285
271 Profile* profile_; 286 Profile* profile_;
272 DownloadManager* manager_; 287 DownloadManager* manager_;
273 DownloadIdSet downloads_; 288 ItemMap downloads_;
289 ItemJsonMap item_jsons_;
290 STLValueDeleter<ItemJsonMap> delete_item_jsons_;
291 OnChangedStatMap on_changed_stats_;
292 STLValueDeleter<OnChangedStatMap> delete_on_changed_stats_;
274 293
275 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); 294 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
276 }; 295 };
277 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_ 296 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698