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

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..79a0d9bb54521328979f987c7d90d7534a25913e 100644
--- a/chrome/browser/ui/webui/downloads_dom_handler.h
+++ b/chrome/browser/ui/webui/downloads_dom_handler.h
@@ -17,6 +17,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,
@@ -36,7 +40,8 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler,
virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE;
// content::DownloadManager::Observer interface
- virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE;
+ virtual void OnDownloadCreated(content::DownloadManager* manager,
+ content::DownloadItem* download) OVERRIDE;
virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE;
// Callback for the "onPageLoaded" message.
@@ -79,12 +84,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;
// 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,9 +116,6 @@ 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);
@@ -117,18 +130,7 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler,
// 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_;

Powered by Google App Engine
This is Rietveld 408576698