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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_
7 7
8 #include <set>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/download_item.h" 13 #include "content/public/browser/download_item.h"
13 #include "content/public/browser/download_manager.h" 14 #include "content/public/browser/download_manager.h"
14 #include "content/public/browser/web_ui_message_handler.h" 15 #include "content/public/browser/web_ui_message_handler.h"
15 16
16 namespace base { 17 namespace base {
17 class ListValue; 18 class ListValue;
18 } 19 }
19 20
21 namespace content {
22 class WebContents;
23 }
24
20 // The handler for Javascript messages related to the "downloads" view, 25 // The handler for Javascript messages related to the "downloads" view,
21 // also observes changes to the download manager. 26 // also observes changes to the download manager.
22 class DownloadsDOMHandler : public content::WebUIMessageHandler, 27 class DownloadsDOMHandler : public content::WebUIMessageHandler,
23 public content::DownloadManager::Observer, 28 public content::DownloadManager::Observer,
24 public content::DownloadItem::Observer { 29 public content::DownloadItem::Observer {
25 public: 30 public:
26 explicit DownloadsDOMHandler(content::DownloadManager* dlm); 31 explicit DownloadsDOMHandler(content::DownloadManager* dlm);
27 virtual ~DownloadsDOMHandler(); 32 virtual ~DownloadsDOMHandler();
28 33
29 void Init(); 34 void Init();
30 35
31 // WebUIMessageHandler implementation. 36 // WebUIMessageHandler implementation.
32 virtual void RegisterMessages() OVERRIDE; 37 virtual void RegisterMessages() OVERRIDE;
33 38
34 // content::DownloadItem::Observer interface 39 // content::DownloadItem::Observer interface
35 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; 40 virtual void OnDownloadUpdated(
36 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; 41 content::DownloadItem* download_item) OVERRIDE;
42 virtual void OnDownloadDestroyed(
43 content::DownloadItem* download_item) OVERRIDE;
37 44
38 // content::DownloadManager::Observer interface 45 // content::DownloadManager::Observer interface
39 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; 46 virtual void OnDownloadCreated(content::DownloadManager* manager,
47 content::DownloadItem* download_item) OVERRIDE;
40 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; 48 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE;
41 49
42 // Callback for the "onPageLoaded" message. 50 // Callback for the "onPageLoaded" message.
43 void OnPageLoaded(const base::ListValue* args); 51 void OnPageLoaded(const base::ListValue* args);
44 52
45 // Callback for the "getDownloads" message. 53 // Callback for the "getDownloads" message.
46 void HandleGetDownloads(const base::ListValue* args); 54 void HandleGetDownloads(const base::ListValue* args);
47 55
48 // Callback for the "openFile" message - opens the file in the shell. 56 // Callback for the "openFile" message - opens the file in the shell.
49 void HandleOpenFile(const base::ListValue* args); 57 void HandleOpenFile(const base::ListValue* args);
(...skipping 22 matching lines...) Expand all
72 // Callback for the "cancel" message - cancels the download. 80 // Callback for the "cancel" message - cancels the download.
73 void HandleCancel(const base::ListValue* args); 81 void HandleCancel(const base::ListValue* args);
74 82
75 // Callback for the "clearAll" message - clears all the downloads. 83 // Callback for the "clearAll" message - clears all the downloads.
76 void HandleClearAll(const base::ListValue* args); 84 void HandleClearAll(const base::ListValue* args);
77 85
78 // Callback for the "openDownloadsFolder" message - opens the downloads 86 // Callback for the "openDownloadsFolder" message - opens the downloads
79 // folder. 87 // folder.
80 void HandleOpenDownloadsFolder(const base::ListValue* args); 88 void HandleOpenDownloadsFolder(const base::ListValue* args);
81 89
90 protected:
91 // These methods are for mocking so that most of this class does not actually
92 // depend on WebUI. The other methods that depend on WebUI are
93 // RegisterMessages() and HandleDrag().
94 virtual content::WebContents* GetWebUIWebContents();
95 virtual void CallDownloadsList(const base::ListValue& downloads);
96 virtual void CallDownloadUpdated(const base::ListValue& download);
97
82 private: 98 private:
83 class OriginalDownloadManagerObserver; 99 typedef std::set<content::DownloadItem*> DownloadSet;
James Hawkins 2012/08/19 06:17:29 nit: Documentation.
benjhayden 2012/08/19 22:20:27 Done. Not sure what you wanted. It's a set of Down
84 100
85 // Send the current list of downloads to the page. 101 // Send the current list of downloads to the page.
86 void SendCurrentDownloads(); 102 void SendCurrentDownloads();
87 103
104 // Returns all the items for both DownloadManagers matching |search_text_|.
105 void SearchDownloads(content::DownloadManager::DownloadVector* downloads);
James Hawkins 2012/08/19 06:17:29 nit: Document |downloads|.
benjhayden 2012/08/19 22:20:27 Done.
106
88 // Clear all download items and their observers. 107 // Clear all download items and their observers.
89 void ClearDownloadItems(); 108 void ClearDownloadItems();
90 109
91 // Display a native prompt asking the user for confirmation after accepting 110 // Display a native prompt asking the user for confirmation after accepting
92 // the dangerous download specified by |dangerous|. The function returns 111 // the dangerous download specified by |dangerous|. The function returns
93 // immediately, and will invoke DangerPromptAccepted() asynchronously if the 112 // immediately, and will invoke DangerPromptAccepted() asynchronously if the
94 // user accepts the dangerous download. The native prompt will observe 113 // user accepts the dangerous download. The native prompt will observe
95 // |dangerous| until either the dialog is dismissed or |dangerous| is no 114 // |dangerous| until either the dialog is dismissed or |dangerous| is no
96 // longer an in-progress dangerous download. 115 // longer an in-progress dangerous download.
97 void ShowDangerPrompt(content::DownloadItem* dangerous); 116 void ShowDangerPrompt(content::DownloadItem* dangerous);
98 117
99 // Called when the user accepts a dangerous download via the 118 // Called when the user accepts a dangerous download via the
100 // DownloadDangerPrompt invoked via ShowDangerPrompt(). 119 // DownloadDangerPrompt invoked via ShowDangerPrompt().
101 void DangerPromptAccepted(int download_id); 120 void DangerPromptAccepted(int download_id);
102 121
103 // Return the download that corresponds to a given id.
104 content::DownloadItem* GetDownloadById(int id);
105
106 // Return the download that is referred to in a given value. 122 // Return the download that is referred to in a given value.
107 content::DownloadItem* GetDownloadByValue(const base::ListValue* args); 123 content::DownloadItem* GetDownloadByValue(const base::ListValue* args);
108 124
109 // Current search text. 125 // Current search text.
110 std::wstring search_text_; 126 string16 search_text_;
127
128 // Keep track of all items that we are observing so that we can be sure to
James Hawkins 2012/08/19 06:17:29 nit: Don't use pronouns in comments (we); pronouns
benjhayden 2012/08/19 22:20:27 Done.
129 // RemoveObserver when we are destroyed.
130 DownloadSet observing_items_;
111 131
112 // Our model 132 // Our model
113 content::DownloadManager* download_manager_; 133 content::DownloadManager* download_manager_;
114 134
115 // If |download_manager_| belongs to an incognito profile than this 135 // If |download_manager_| belongs to an incognito profile then this
116 // is the DownloadManager for the original profile; otherwise, this is 136 // is the DownloadManager for the original profile; otherwise, this is
117 // NULL. 137 // NULL.
118 content::DownloadManager* original_profile_download_manager_; 138 content::DownloadManager* original_profile_download_manager_;
119 139
120 // True once the page has loaded the first time (it may load multiple times, 140 bool update_scheduled_;
James Hawkins 2012/08/19 06:17:29 nit: Documentation.
benjhayden 2012/08/19 22:20:27 Done.
121 // e.g. on reload).
122 bool initialized_;
123
124 // The current set of visible DownloadItems for this view received from the
125 // DownloadManager. DownloadManager owns the DownloadItems. The vector is
126 // kept in order, sorted by ascending start time.
127 // Note that when a download item is removed, the entry in the vector becomes
128 // null. This should only be a transient state, as a ModelChanged()
129 // notification should follow close on the heels of such a change.
130 typedef std::vector<content::DownloadItem*> OrderedDownloads;
131 OrderedDownloads download_items_;
132 141
133 base::WeakPtrFactory<DownloadsDOMHandler> weak_ptr_factory_; 142 base::WeakPtrFactory<DownloadsDOMHandler> weak_ptr_factory_;
134 143
135 DISALLOW_COPY_AND_ASSIGN(DownloadsDOMHandler); 144 DISALLOW_COPY_AND_ASSIGN(DownloadsDOMHandler);
136 }; 145 };
137 146
138 #endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_ 147 #endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_
OLDNEW
« 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