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

Unified Diff: chrome/browser/ui/webui/downloads_dom_handler.h

Issue 10854127: Rewrite DownloadsDOMHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/downloads_dom_handler.h
diff --git a/chrome/browser/ui/webui/downloads_dom_handler.h b/chrome/browser/ui/webui/downloads_dom_handler.h
index d57df0a9524d9094c0d6d05b65108716d00e5f28..4ff2291379e623b08f8e6b74f557d89d9e22a37e 100644
--- a/chrome/browser/ui/webui/downloads_dom_handler.h
+++ b/chrome/browser/ui/webui/downloads_dom_handler.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_
+#include <set>
#include <vector>
#include "base/compiler_specific.h"
@@ -17,6 +18,10 @@ namespace base {
class ListValue;
}
+namespace content {
+class WebContents;
+}
+
// The handler for Javascript messages related to the "downloads" view,
// also observes changes to the download manager.
class DownloadsDOMHandler : public content::WebUIMessageHandler,
@@ -32,11 +37,14 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler,
virtual void RegisterMessages() OVERRIDE;
// content::DownloadItem::Observer interface
- virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
- virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE;
+ virtual void OnDownloadUpdated(
+ content::DownloadItem* download_item) OVERRIDE;
+ virtual void OnDownloadDestroyed(
+ content::DownloadItem* download_item) OVERRIDE;
// content::DownloadManager::Observer interface
- virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE;
+ virtual void OnDownloadCreated(content::DownloadManager* manager,
+ content::DownloadItem* download_item) OVERRIDE;
virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE;
// Callback for the "onPageLoaded" message.
@@ -79,12 +87,23 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler,
// folder.
void HandleOpenDownloadsFolder(const base::ListValue* args);
+ protected:
+ // These methods are for mocking so that most of this class does not actually
+ // depend on WebUI. The other methods that depend on WebUI are
+ // RegisterMessages() and HandleDrag().
+ virtual content::WebContents* GetWebUIWebContents();
+ virtual void CallDownloadsList(const base::ListValue& downloads);
+ virtual void CallDownloadUpdated(const base::ListValue& download);
+
private:
- class OriginalDownloadManagerObserver;
+ typedef std::set<content::DownloadItem*> DownloadSet;
// Send the current list of downloads to the page.
void SendCurrentDownloads();
+ // Returns all the items for both DownloadManagers matching |search_text_|.
+ void SearchDownloads(content::DownloadManager::DownloadVector* downloads);
+
// Clear all download items and their observers.
void ClearDownloadItems();
@@ -100,35 +119,25 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler,
// DownloadDangerPrompt invoked via ShowDangerPrompt().
void DangerPromptAccepted(int download_id);
- // Return the download that corresponds to a given id.
- content::DownloadItem* GetDownloadById(int id);
-
// Return the download that is referred to in a given value.
content::DownloadItem* GetDownloadByValue(const base::ListValue* args);
// Current search text.
- std::wstring search_text_;
+ string16 search_text_;
+
+ // Keep track of all items that we are observing so that we can be sure to
+ // RemoveObserver when we are destroyed.
+ DownloadSet observing_items_;
// Our model
content::DownloadManager* download_manager_;
- // If |download_manager_| belongs to an incognito profile than this
+ // If |download_manager_| belongs to an incognito profile then this
// is the DownloadManager for the original profile; otherwise, this is
// NULL.
content::DownloadManager* original_profile_download_manager_;
- // True once the page has loaded the first time (it may load multiple times,
- // e.g. on reload).
- bool initialized_;
-
- // The current set of visible DownloadItems for this view received from the
- // DownloadManager. DownloadManager owns the DownloadItems. The vector is
- // kept in order, sorted by ascending start time.
- // Note that when a download item is removed, the entry in the vector becomes
- // null. This should only be a transient state, as a ModelChanged()
- // notification should follow close on the heels of such a change.
- typedef std::vector<content::DownloadItem*> OrderedDownloads;
- OrderedDownloads download_items_;
+ bool update_scheduled_;
base::WeakPtrFactory<DownloadsDOMHandler> weak_ptr_factory_;
« no previous file with comments | « no previous file | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | chrome/browser/ui/webui/downloads_dom_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698