OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/singleton.h" | |
16 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
17 #include "chrome/browser/extensions/extension_function.h" | 16 #include "chrome/browser/extensions/extension_function.h" |
18 #include "chrome/browser/ui/shell_dialogs.h" | 17 #include "chrome/browser/ui/shell_dialogs.h" |
19 #include "content/common/notification_observer.h" | 18 #include "content/common/notification_observer.h" |
20 #include "content/common/notification_registrar.h" | 19 #include "content/common/notification_registrar.h" |
21 | 20 |
22 class FilePath; | 21 class FilePath; |
23 | 22 |
24 // Observes BookmarkModel and then routes the notifications as events to | 23 // Observes BookmarkModel and then routes the notifications as events to |
25 // the extension system. | 24 // the extension system. |
26 class ExtensionBookmarkEventRouter : public BookmarkModelObserver { | 25 class ExtensionBookmarkEventRouter : public BookmarkModelObserver { |
27 public: | 26 public: |
28 static ExtensionBookmarkEventRouter* GetInstance(); | 27 explicit ExtensionBookmarkEventRouter() {} |
29 virtual ~ExtensionBookmarkEventRouter(); | 28 virtual ~ExtensionBookmarkEventRouter() {} |
asargent_no_longer_on_chrome
2011/05/24 18:18:00
nit: probably shouldn't inline the constructor/des
Yoyo Zhou
2011/05/24 19:17:55
Done here and elsewhere.
| |
30 | 29 |
31 // Call this for each model to observe. Safe to call multiple times per | 30 // Initialize to observe this bookmark model. |
32 // model. | |
33 void Observe(BookmarkModel* model); | 31 void Observe(BookmarkModel* model); |
34 | 32 |
35 // BookmarkModelObserver: | 33 // BookmarkModelObserver: |
36 virtual void Loaded(BookmarkModel* model) OVERRIDE; | 34 virtual void Loaded(BookmarkModel* model) OVERRIDE; |
37 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE {} | 35 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE {} |
38 virtual void BookmarkNodeMoved(BookmarkModel* model, | 36 virtual void BookmarkNodeMoved(BookmarkModel* model, |
39 const BookmarkNode* old_parent, | 37 const BookmarkNode* old_parent, |
40 int old_index, | 38 int old_index, |
41 const BookmarkNode* new_parent, | 39 const BookmarkNode* new_parent, |
42 int new_index) OVERRIDE; | 40 int new_index) OVERRIDE; |
43 virtual void BookmarkNodeAdded(BookmarkModel* model, | 41 virtual void BookmarkNodeAdded(BookmarkModel* model, |
44 const BookmarkNode* parent, | 42 const BookmarkNode* parent, |
45 int index) OVERRIDE; | 43 int index) OVERRIDE; |
46 virtual void BookmarkNodeRemoved(BookmarkModel* model, | 44 virtual void BookmarkNodeRemoved(BookmarkModel* model, |
47 const BookmarkNode* parent, | 45 const BookmarkNode* parent, |
48 int old_index, | 46 int old_index, |
49 const BookmarkNode* node) OVERRIDE; | 47 const BookmarkNode* node) OVERRIDE; |
50 virtual void BookmarkNodeChanged(BookmarkModel* model, | 48 virtual void BookmarkNodeChanged(BookmarkModel* model, |
51 const BookmarkNode* node) OVERRIDE; | 49 const BookmarkNode* node) OVERRIDE; |
52 virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model, | 50 virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model, |
53 const BookmarkNode* node) OVERRIDE; | 51 const BookmarkNode* node) OVERRIDE; |
54 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | 52 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
55 const BookmarkNode* node) OVERRIDE; | 53 const BookmarkNode* node) OVERRIDE; |
56 virtual void BookmarkImportBeginning(BookmarkModel* model) OVERRIDE; | 54 virtual void BookmarkImportBeginning(BookmarkModel* model) OVERRIDE; |
57 virtual void BookmarkImportEnding(BookmarkModel* model) OVERRIDE; | 55 virtual void BookmarkImportEnding(BookmarkModel* model) OVERRIDE; |
58 | 56 |
59 private: | 57 private: |
60 ExtensionBookmarkEventRouter(); | |
61 friend struct DefaultSingletonTraits<ExtensionBookmarkEventRouter>; | |
62 | |
63 // Helper to actually dispatch an event to extension listeners. | 58 // Helper to actually dispatch an event to extension listeners. |
64 void DispatchEvent(Profile* profile, | 59 void DispatchEvent(Profile* profile, |
65 const char* event_name, | 60 const char* event_name, |
66 const std::string& json_args); | 61 const std::string& json_args); |
67 | 62 |
68 // These are stored so that Observe can be called multiple times safely. | 63 // The model being observed. |
69 // This way the caller doesn't have to know whether it's already observing | 64 BookmarkModel* model_; |
70 // a particular model or not. The pointers are not owned by this object. | |
71 std::set<BookmarkModel*> models_; | |
72 | 65 |
73 DISALLOW_COPY_AND_ASSIGN(ExtensionBookmarkEventRouter); | 66 DISALLOW_COPY_AND_ASSIGN(ExtensionBookmarkEventRouter); |
74 }; | 67 }; |
75 | 68 |
76 class BookmarksFunction : public AsyncExtensionFunction, | 69 class BookmarksFunction : public AsyncExtensionFunction, |
77 public NotificationObserver { | 70 public NotificationObserver { |
78 public: | 71 public: |
79 // AsyncExtensionFunction: | 72 // AsyncExtensionFunction: |
80 virtual void Run() OVERRIDE; | 73 virtual void Run() OVERRIDE; |
81 | 74 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 // BookmarkManagerIOFunction: | 225 // BookmarkManagerIOFunction: |
233 virtual bool RunImpl() OVERRIDE; | 226 virtual bool RunImpl() OVERRIDE; |
234 virtual void FileSelected(const FilePath& path, int index, void* params) | 227 virtual void FileSelected(const FilePath& path, int index, void* params) |
235 OVERRIDE; | 228 OVERRIDE; |
236 | 229 |
237 private: | 230 private: |
238 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.export"); | 231 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.export"); |
239 }; | 232 }; |
240 | 233 |
241 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ | 234 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ |
OLD | NEW |