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

Side by Side Diff: chrome/browser/extensions/api/bookmarks/bookmarks_api.h

Issue 11778097: Revert revision 176015 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_
7
8 #include <list>
9 #include <string>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "chrome/browser/bookmarks/bookmark_model_observer.h"
15 #include "chrome/browser/extensions/event_router.h"
16 #include "chrome/browser/extensions/extension_function.h"
17 #include "chrome/browser/profiles/profile_keyed_service.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "ui/base/dialogs/select_file_dialog.h"
21
22 class FilePath;
23
24 namespace base {
25 class ListValue;
26 }
27
28 namespace extensions {
29
30 // Observes BookmarkModel and then routes the notifications as events to
31 // the extension system.
32 class BookmarkEventRouter : public BookmarkModelObserver {
33 public:
34 explicit BookmarkEventRouter(BookmarkModel* model);
35 virtual ~BookmarkEventRouter();
36
37 // BookmarkModelObserver:
38 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
39 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
40 virtual void BookmarkNodeMoved(BookmarkModel* model,
41 const BookmarkNode* old_parent,
42 int old_index,
43 const BookmarkNode* new_parent,
44 int new_index) OVERRIDE;
45 virtual void BookmarkNodeAdded(BookmarkModel* model,
46 const BookmarkNode* parent,
47 int index) OVERRIDE;
48 virtual void BookmarkNodeRemoved(BookmarkModel* model,
49 const BookmarkNode* parent,
50 int old_index,
51 const BookmarkNode* node) OVERRIDE;
52 virtual void BookmarkNodeChanged(BookmarkModel* model,
53 const BookmarkNode* node) OVERRIDE;
54 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
55 const BookmarkNode* node) OVERRIDE;
56 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
57 const BookmarkNode* node) OVERRIDE;
58 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE;
59 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE;
60
61 private:
62 // Helper to actually dispatch an event to extension listeners.
63 void DispatchEvent(Profile* profile,
64 const char* event_name,
65 scoped_ptr<base::ListValue> event_args);
66
67 BookmarkModel* model_;
68
69 DISALLOW_COPY_AND_ASSIGN(BookmarkEventRouter);
70 };
71
72 class BookmarkAPI : public ProfileKeyedService,
73 public EventRouter::Observer {
74 public:
75 explicit BookmarkAPI(Profile* profile);
76 virtual ~BookmarkAPI();
77
78 // ProfileKeyedService implementation.
79 virtual void Shutdown() OVERRIDE;
80
81 // EventRouter::Observer implementation.
82 virtual void OnListenerAdded(const EventListenerInfo& details)
83 OVERRIDE;
84
85 private:
86 Profile* profile_;
87
88 // Created lazily upon OnListenerAdded.
89 scoped_ptr<BookmarkEventRouter> bookmark_event_router_;
90 };
91
92 class BookmarksFunction : public AsyncExtensionFunction,
93 public content::NotificationObserver {
94 public:
95 // AsyncExtensionFunction:
96 virtual void Run() OVERRIDE;
97
98 protected:
99 virtual ~BookmarksFunction() {}
100
101 // Helper to get the bookmark id as int64 from the given string id.
102 // Sets error_ to an error string if the given id string can't be parsed
103 // as an int64. In case of error, doesn't change id and returns false.
104 bool GetBookmarkIdAsInt64(const std::string& id_string, int64* id);
105
106 // Helper that checks if bookmark editing is enabled. If it's not, this sets
107 // error_ to the appropriate error string.
108 bool EditBookmarksEnabled();
109
110 private:
111 // content::NotificationObserver:
112 virtual void Observe(int type,
113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) OVERRIDE;
115
116 content::NotificationRegistrar registrar_;
117 };
118
119 class BookmarksGetTreeFunction : public BookmarksFunction {
120 public:
121 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.get")
122
123 protected:
124 virtual ~BookmarksGetTreeFunction() {}
125
126 // ExtensionFunction:
127 virtual bool RunImpl() OVERRIDE;
128 };
129
130 class BookmarksGetChildrenFunction : public BookmarksFunction {
131 public:
132 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.getChildren")
133
134 protected:
135 virtual ~BookmarksGetChildrenFunction() {}
136
137 // ExtensionFunction:
138 virtual bool RunImpl() OVERRIDE;
139 };
140
141 class BookmarksGetFunction : public BookmarksFunction {
142 public:
143 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.getRecent")
144
145 protected:
146 virtual ~BookmarksGetFunction() {}
147
148 // ExtensionFunction:
149 virtual bool RunImpl() OVERRIDE;
150 };
151
152 class BookmarksGetSubTreeFunction : public BookmarksFunction {
153 public:
154 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.getTree")
155
156 protected:
157 virtual ~BookmarksGetSubTreeFunction() {}
158
159 // ExtensionFunction:
160 virtual bool RunImpl() OVERRIDE;
161 };
162
163 class BookmarksGetRecentFunction : public BookmarksFunction {
164 public:
165 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.getSubTree")
166
167 protected:
168 virtual ~BookmarksGetRecentFunction() {}
169
170 // ExtensionFunction:
171 virtual bool RunImpl() OVERRIDE;
172 };
173
174 class BookmarksSearchFunction : public BookmarksFunction {
175 public:
176 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.search")
177
178 protected:
179 virtual ~BookmarksSearchFunction() {}
180
181 // ExtensionFunction:
182 virtual bool RunImpl() OVERRIDE;
183 };
184
185 class BookmarksRemoveFunction : public BookmarksFunction {
186 public:
187 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.remove")
188
189 // Returns true on successful parse and sets invalid_id to true if conversion
190 // from id string to int64 failed.
191 static bool ExtractIds(const base::ListValue* args, std::list<int64>* ids,
192 bool* invalid_id);
193 // ExtensionFunction:
194 virtual void GetQuotaLimitHeuristics(
195 QuotaLimitHeuristics* heuristics) const OVERRIDE;
196
197 protected:
198 virtual ~BookmarksRemoveFunction() {}
199
200 // ExtensionFunction:
201 virtual bool RunImpl() OVERRIDE;
202 };
203
204 class BookmarksRemoveTreeFunction : public BookmarksRemoveFunction {
205 public:
206 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.removeTree")
207
208 protected:
209 virtual ~BookmarksRemoveTreeFunction() {}
210 };
211
212 class BookmarksCreateFunction : public BookmarksFunction {
213 public:
214 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.create")
215
216 // ExtensionFunction:
217 virtual void GetQuotaLimitHeuristics(
218 QuotaLimitHeuristics* heuristics) const OVERRIDE;
219
220 protected:
221 virtual ~BookmarksCreateFunction() {}
222
223 // ExtensionFunction:
224 virtual bool RunImpl() OVERRIDE;
225 };
226
227 class BookmarksMoveFunction : public BookmarksFunction {
228 public:
229 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.move")
230
231 static bool ExtractIds(const base::ListValue* args, std::list<int64>* ids,
232 bool* invalid_id);
233
234 // ExtensionFunction:
235 virtual void GetQuotaLimitHeuristics(
236 QuotaLimitHeuristics* heuristics) const OVERRIDE;
237
238 protected:
239 virtual ~BookmarksMoveFunction() {}
240
241 // ExtensionFunction:
242 virtual bool RunImpl() OVERRIDE;
243 };
244
245 class BookmarksUpdateFunction : public BookmarksFunction {
246 public:
247 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.update")
248
249 static bool ExtractIds(const base::ListValue* args, std::list<int64>* ids,
250 bool* invalid_id);
251
252 // ExtensionFunction:
253 virtual void GetQuotaLimitHeuristics(
254 QuotaLimitHeuristics* heuristics) const OVERRIDE;
255
256 protected:
257 virtual ~BookmarksUpdateFunction() {}
258
259 // ExtensionFunction:
260 virtual bool RunImpl() OVERRIDE;
261 };
262
263 class BookmarksIOFunction : public BookmarksFunction,
264 public ui::SelectFileDialog::Listener {
265 public:
266 BookmarksIOFunction();
267
268 virtual void FileSelected(const FilePath& path, int index, void* params) = 0;
269
270 // ui::SelectFileDialog::Listener:
271 virtual void MultiFilesSelected(const std::vector<FilePath>& files,
272 void* params) OVERRIDE;
273 virtual void FileSelectionCanceled(void* params) OVERRIDE;
274
275 void SelectFile(ui::SelectFileDialog::Type type);
276
277 protected:
278 virtual ~BookmarksIOFunction();
279
280 private:
281 void ShowSelectFileDialog(
282 ui::SelectFileDialog::Type type,
283 const FilePath& default_path);
284
285 protected:
286 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
287 };
288
289 class BookmarksImportFunction : public BookmarksIOFunction {
290 public:
291 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.import");
292
293 // BookmarkManagerIOFunction:
294 virtual void FileSelected(const FilePath& path, int index, void* params)
295 OVERRIDE;
296
297 private:
298 virtual ~BookmarksImportFunction() {}
299
300 // ExtensionFunction:
301 virtual bool RunImpl() OVERRIDE;
302 };
303
304 class BookmarksExportFunction : public BookmarksIOFunction {
305 public:
306 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.export");
307
308 // BookmarkManagerIOFunction:
309 virtual void FileSelected(const FilePath& path, int index, void* params)
310 OVERRIDE;
311
312 private:
313 virtual ~BookmarksExportFunction() {}
314
315 // ExtensionFunction:
316 virtual bool RunImpl() OVERRIDE;
317 };
318
319 } // namespace extensions
320
321 #endif // CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698