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

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 // A set of DownloadItem*s.
James Hawkins 2012/08/22 17:39:01 Nix this. The documentation should describe the p
benjhayden 2012/08/22 20:19:22 Done.
100 typedef std::set<content::DownloadItem*> DownloadSet;
101
102 // Schedule a call to SendCurrentDownloads() in the next message loop
James Hawkins 2012/08/22 17:39:01 nit: Method documentation should use third-person
benjhayden 2012/08/22 20:19:22 Done.
103 // iteration.
104 void ScheduleSendCurrentDownloads();
84 105
85 // Send the current list of downloads to the page. 106 // Send the current list of downloads to the page.
86 void SendCurrentDownloads(); 107 void SendCurrentDownloads();
87 108
109 // Fills |downloads| with all the items for both DownloadManagers matching
110 // |search_text_|.
111 void SearchDownloads(content::DownloadManager::DownloadVector* downloads);
112
88 // Clear all download items and their observers. 113 // Clear all download items and their observers.
89 void ClearDownloadItems(); 114 void ClearDownloadItems();
90 115
91 // Display a native prompt asking the user for confirmation after accepting 116 // Display a native prompt asking the user for confirmation after accepting
92 // the dangerous download specified by |dangerous|. The function returns 117 // the dangerous download specified by |dangerous|. The function returns
93 // immediately, and will invoke DangerPromptAccepted() asynchronously if the 118 // immediately, and will invoke DangerPromptAccepted() asynchronously if the
94 // user accepts the dangerous download. The native prompt will observe 119 // user accepts the dangerous download. The native prompt will observe
95 // |dangerous| until either the dialog is dismissed or |dangerous| is no 120 // |dangerous| until either the dialog is dismissed or |dangerous| is no
96 // longer an in-progress dangerous download. 121 // longer an in-progress dangerous download.
97 void ShowDangerPrompt(content::DownloadItem* dangerous); 122 void ShowDangerPrompt(content::DownloadItem* dangerous);
98 123
99 // Called when the user accepts a dangerous download via the 124 // Called when the user accepts a dangerous download via the
100 // DownloadDangerPrompt invoked via ShowDangerPrompt(). 125 // DownloadDangerPrompt invoked via ShowDangerPrompt().
101 void DangerPromptAccepted(int download_id); 126 void DangerPromptAccepted(int download_id);
102 127
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. 128 // Return the download that is referred to in a given value.
107 content::DownloadItem* GetDownloadByValue(const base::ListValue* args); 129 content::DownloadItem* GetDownloadByValue(const base::ListValue* args);
108 130
109 // Current search text. 131 // Current search text.
110 std::wstring search_text_; 132 string16 search_text_;
133
134 // Keep track of all items that this is observing so that RemoveObserver will
135 // be called for all of them.
136 DownloadSet observing_items_;
111 137
112 // Our model 138 // Our model
113 content::DownloadManager* download_manager_; 139 content::DownloadManager* download_manager_;
114 140
115 // If |download_manager_| belongs to an incognito profile than this 141 // If |download_manager_| belongs to an incognito profile then this
116 // is the DownloadManager for the original profile; otherwise, this is 142 // is the DownloadManager for the original profile; otherwise, this is
117 // NULL. 143 // NULL.
118 content::DownloadManager* original_profile_download_manager_; 144 content::DownloadManager* original_profile_download_manager_;
119 145
120 // True once the page has loaded the first time (it may load multiple times, 146 // Whether a call to SendCurrentDownloads() is currently scheduled.
121 // e.g. on reload). 147 bool update_scheduled_;
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 148
133 base::WeakPtrFactory<DownloadsDOMHandler> weak_ptr_factory_; 149 base::WeakPtrFactory<DownloadsDOMHandler> weak_ptr_factory_;
134 150
135 DISALLOW_COPY_AND_ASSIGN(DownloadsDOMHandler); 151 DISALLOW_COPY_AND_ASSIGN(DownloadsDOMHandler);
136 }; 152 };
137 153
138 #endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOM_HANDLER_H_ 154 #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