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

Side by Side Diff: chrome/browser/extensions/extension_downloads_api.h

Issue 7825035: Implement chrome.experimental.downloads.search() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rewrite Created 9 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
7 #pragma once
8
9 #include <map>
10 #include <set>
11 #include <string>
12
13 #include "base/file_path.h"
14 #include "base/memory/singleton.h"
15 #include "base/string16.h"
16 #include "chrome/browser/extensions/extension_function.h"
17 #include "content/browser/download/download_item.h"
18 #include "content/browser/download/download_manager.h"
19
20 namespace base {
21 class DictionaryValue;
22 }
23 class ResourceDispatcherHost;
24 class TabContents;
25 namespace content {
26 class ResourceContext;
27 }
28
29 // Functions in the chrome.experimental.downloads namespace facilitate
30 // controlling downloads from extensions. See the full API doc at
31 // http://goo.gl/6hO1n
32
33 class DownloadsFunctionInterface {
34 public:
35 enum DownloadsFunctionName {
36 DOWNLOADS_FUNCTION_DOWNLOAD = 0,
37 DOWNLOADS_FUNCTION_SEARCH = 1,
38 DOWNLOADS_FUNCTION_PAUSE = 2,
39 DOWNLOADS_FUNCTION_RESUME = 3,
40 DOWNLOADS_FUNCTION_CANCEL = 4,
41 DOWNLOADS_FUNCTION_ERASE = 5,
42 DOWNLOADS_FUNCTION_SET_DESTINATION = 6,
43 DOWNLOADS_FUNCTION_ACCEPT_DANGER = 7,
44 DOWNLOADS_FUNCTION_SHOW = 8,
45 DOWNLOADS_FUNCTION_DRAG = 9,
46 // Insert new values here, not at the beginning.
47 DOWNLOADS_FUNCTION_LAST
48 };
49
50 protected:
51 // Return true if args_ is well-formed, otherwise set error_ and return false.
52 virtual bool ParseArgs() = 0;
53
54 // Implementation-specific logic. "Do the thing that you do."
55 virtual void RunInternal() = 0;
56
57 // Which subclass is this.
58 virtual DownloadsFunctionName function() const = 0;
59
60 // Wrap ParseArgs(), RunInternal().
61 static bool RunImplImpl(DownloadsFunctionInterface* pimpl);
62 };
63
64 class SyncDownloadsFunction : public SyncExtensionFunction,
65 public DownloadsFunctionInterface {
66 public:
67 virtual bool RunImpl() OVERRIDE;
68
69 protected:
70 explicit SyncDownloadsFunction(DownloadsFunctionName function);
71 virtual ~SyncDownloadsFunction();
72 virtual DownloadsFunctionName function() const OVERRIDE;
73
74 private:
75 DownloadsFunctionName function_;
76
77 DISALLOW_COPY_AND_ASSIGN(SyncDownloadsFunction);
78 };
79
80 class AsyncDownloadsFunction : public AsyncExtensionFunction,
81 public DownloadsFunctionInterface {
82 public:
83 virtual bool RunImpl() OVERRIDE;
84
85 protected:
86 explicit AsyncDownloadsFunction(DownloadsFunctionName function);
87 virtual ~AsyncDownloadsFunction();
88 virtual DownloadsFunctionName function() const OVERRIDE;
89
90 private:
91 DownloadsFunctionName function_;
92
93 DISALLOW_COPY_AND_ASSIGN(AsyncDownloadsFunction);
94 };
95
96 class DownloadsDownloadFunction : public AsyncDownloadsFunction {
97 public:
98 DownloadsDownloadFunction();
99 virtual ~DownloadsDownloadFunction();
100 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.download");
101
102 protected:
103 virtual bool ParseArgs() OVERRIDE;
104 virtual void RunInternal() OVERRIDE;
105
106 private:
107 struct IOData {
108 public:
109 IOData();
110 ~IOData();
111
112 GURL url;
113 string16 filename;
114 bool save_as;
115 base::ListValue* extra_headers;
116 std::string method;
117 std::string post_body;
118 ResourceDispatcherHost* rdh;
119 const content::ResourceContext* resource_context;
120 int render_process_host_id;
121 int render_view_host_routing_id;
122 };
123 void BeginDownloadOnIOThread();
124 void OnStarted(DownloadId dl_id, net::Error error);
125 void RespondOnUIThread(int dl_id, net::Error error);
126
127 scoped_ptr<IOData> iodata_;
128
129 DISALLOW_COPY_AND_ASSIGN(DownloadsDownloadFunction);
130 };
131
132 class DownloadsSearchFunction : public SyncDownloadsFunction {
133 public:
134 DownloadsSearchFunction();
135 virtual ~DownloadsSearchFunction();
136 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.search");
137
138 protected:
139 virtual bool ParseArgs() OVERRIDE;
140 virtual void RunInternal() OVERRIDE;
141
142 private:
143 DISALLOW_COPY_AND_ASSIGN(DownloadsSearchFunction);
144 };
145
146 class DownloadsPauseFunction : public SyncDownloadsFunction {
147 public:
148 DownloadsPauseFunction();
149 virtual ~DownloadsPauseFunction();
150 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.pause");
151
152 protected:
153 virtual bool ParseArgs() OVERRIDE;
154 virtual void RunInternal() OVERRIDE;
155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(DownloadsPauseFunction);
158 };
159
160 class DownloadsResumeFunction : public AsyncDownloadsFunction {
161 public:
162 DownloadsResumeFunction();
163 virtual ~DownloadsResumeFunction();
164 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.resume");
165
166 protected:
167 virtual bool ParseArgs() OVERRIDE;
168 virtual void RunInternal() OVERRIDE;
169
170 private:
171 DISALLOW_COPY_AND_ASSIGN(DownloadsResumeFunction);
172 };
173
174 class DownloadsCancelFunction : public AsyncDownloadsFunction {
175 public:
176 DownloadsCancelFunction();
177 virtual ~DownloadsCancelFunction();
178 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.cancel");
179
180 protected:
181 virtual bool ParseArgs() OVERRIDE;
182 virtual void RunInternal() OVERRIDE;
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(DownloadsCancelFunction);
186 };
187
188 class DownloadsEraseFunction : public AsyncDownloadsFunction {
189 public:
190 DownloadsEraseFunction();
191 virtual ~DownloadsEraseFunction();
192 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.erase");
193
194 protected:
195 virtual bool ParseArgs() OVERRIDE;
196 virtual void RunInternal() OVERRIDE;
197
198 private:
199 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction);
200 };
201
202 class DownloadsSetDestinationFunction : public AsyncDownloadsFunction {
203 public:
204 DownloadsSetDestinationFunction();
205 virtual ~DownloadsSetDestinationFunction();
206 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.setDestination");
207
208 protected:
209 virtual bool ParseArgs() OVERRIDE;
210 virtual void RunInternal() OVERRIDE;
211
212 private:
213 DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction);
214 };
215
216 class DownloadsAcceptDangerFunction : public AsyncDownloadsFunction {
217 public:
218 DownloadsAcceptDangerFunction();
219 virtual ~DownloadsAcceptDangerFunction();
220 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.acceptDanger");
221
222 protected:
223 virtual bool ParseArgs() OVERRIDE;
224 virtual void RunInternal() OVERRIDE;
225
226 private:
227 DISALLOW_COPY_AND_ASSIGN(DownloadsAcceptDangerFunction);
228 };
229
230 class DownloadsShowFunction : public AsyncDownloadsFunction {
231 public:
232 DownloadsShowFunction();
233 virtual ~DownloadsShowFunction();
234 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.show");
235
236 protected:
237 virtual bool ParseArgs() OVERRIDE;
238 virtual void RunInternal() OVERRIDE;
239
240 private:
241 DISALLOW_COPY_AND_ASSIGN(DownloadsShowFunction);
242 };
243
244 class DownloadsDragFunction : public AsyncDownloadsFunction {
245 public:
246 DownloadsDragFunction();
247 virtual ~DownloadsDragFunction();
248 DECLARE_EXTENSION_FUNCTION_NAME("experimental.downloads.drag");
249
250 protected:
251 virtual bool ParseArgs() OVERRIDE;
252 virtual void RunInternal() OVERRIDE;
253
254 private:
255 DISALLOW_COPY_AND_ASSIGN(DownloadsDragFunction);
256 };
257
258 class ExtensionDownloadsEventRouter : public DownloadManager::Observer {
259 public:
260 explicit ExtensionDownloadsEventRouter(Profile* profile);
261 virtual ~ExtensionDownloadsEventRouter();
262
263 virtual void ModelChanged() OVERRIDE;
264 virtual void ManagerGoingDown() OVERRIDE;
265
266 private:
267 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
271 Profile* profile_;
272 DownloadManager* manager_;
273 DownloadIdSet downloads_;
274
275 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
276 };
277 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOWNLOADS_API_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/downloads_extension_apitest.cc ('k') | chrome/browser/extensions/extension_downloads_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698