| 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(BookmarkModel* model); |
| 29 virtual ~ExtensionBookmarkEventRouter(); | 28 virtual ~ExtensionBookmarkEventRouter(); |
| 30 | 29 |
| 31 // Call this for each model to observe. Safe to call multiple times per | 30 void Init(); |
| 32 // model. | |
| 33 void Observe(BookmarkModel* model); | |
| 34 | 31 |
| 35 // BookmarkModelObserver: | 32 // BookmarkModelObserver: |
| 36 virtual void Loaded(BookmarkModel* model) OVERRIDE; | 33 virtual void Loaded(BookmarkModel* model) OVERRIDE; |
| 37 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE {} | 34 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; |
| 38 virtual void BookmarkNodeMoved(BookmarkModel* model, | 35 virtual void BookmarkNodeMoved(BookmarkModel* model, |
| 39 const BookmarkNode* old_parent, | 36 const BookmarkNode* old_parent, |
| 40 int old_index, | 37 int old_index, |
| 41 const BookmarkNode* new_parent, | 38 const BookmarkNode* new_parent, |
| 42 int new_index) OVERRIDE; | 39 int new_index) OVERRIDE; |
| 43 virtual void BookmarkNodeAdded(BookmarkModel* model, | 40 virtual void BookmarkNodeAdded(BookmarkModel* model, |
| 44 const BookmarkNode* parent, | 41 const BookmarkNode* parent, |
| 45 int index) OVERRIDE; | 42 int index) OVERRIDE; |
| 46 virtual void BookmarkNodeRemoved(BookmarkModel* model, | 43 virtual void BookmarkNodeRemoved(BookmarkModel* model, |
| 47 const BookmarkNode* parent, | 44 const BookmarkNode* parent, |
| 48 int old_index, | 45 int old_index, |
| 49 const BookmarkNode* node) OVERRIDE; | 46 const BookmarkNode* node) OVERRIDE; |
| 50 virtual void BookmarkNodeChanged(BookmarkModel* model, | 47 virtual void BookmarkNodeChanged(BookmarkModel* model, |
| 51 const BookmarkNode* node) OVERRIDE; | 48 const BookmarkNode* node) OVERRIDE; |
| 52 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | 49 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, |
| 53 const BookmarkNode* node) OVERRIDE; | 50 const BookmarkNode* node) OVERRIDE; |
| 54 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | 51 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
| 55 const BookmarkNode* node) OVERRIDE; | 52 const BookmarkNode* node) OVERRIDE; |
| 56 virtual void BookmarkImportBeginning(BookmarkModel* model) OVERRIDE; | 53 virtual void BookmarkImportBeginning(BookmarkModel* model) OVERRIDE; |
| 57 virtual void BookmarkImportEnding(BookmarkModel* model) OVERRIDE; | 54 virtual void BookmarkImportEnding(BookmarkModel* model) OVERRIDE; |
| 58 | 55 |
| 59 private: | 56 private: |
| 60 ExtensionBookmarkEventRouter(); | |
| 61 friend struct DefaultSingletonTraits<ExtensionBookmarkEventRouter>; | |
| 62 | |
| 63 // Helper to actually dispatch an event to extension listeners. | 57 // Helper to actually dispatch an event to extension listeners. |
| 64 void DispatchEvent(Profile* profile, | 58 void DispatchEvent(Profile* profile, |
| 65 const char* event_name, | 59 const char* event_name, |
| 66 const std::string& json_args); | 60 const std::string& json_args); |
| 67 | 61 |
| 68 // These are stored so that Observe can be called multiple times safely. | 62 BookmarkModel* model_; |
| 69 // This way the caller doesn't have to know whether it's already observing | |
| 70 // a particular model or not. The pointers are not owned by this object. | |
| 71 std::set<BookmarkModel*> models_; | |
| 72 | 63 |
| 73 DISALLOW_COPY_AND_ASSIGN(ExtensionBookmarkEventRouter); | 64 DISALLOW_COPY_AND_ASSIGN(ExtensionBookmarkEventRouter); |
| 74 }; | 65 }; |
| 75 | 66 |
| 76 class BookmarksFunction : public AsyncExtensionFunction, | 67 class BookmarksFunction : public AsyncExtensionFunction, |
| 77 public NotificationObserver { | 68 public NotificationObserver { |
| 78 public: | 69 public: |
| 79 // AsyncExtensionFunction: | 70 // AsyncExtensionFunction: |
| 80 virtual void Run() OVERRIDE; | 71 virtual void Run() OVERRIDE; |
| 81 | 72 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // BookmarkManagerIOFunction: | 231 // BookmarkManagerIOFunction: |
| 241 virtual bool RunImpl() OVERRIDE; | 232 virtual bool RunImpl() OVERRIDE; |
| 242 virtual void FileSelected(const FilePath& path, int index, void* params) | 233 virtual void FileSelected(const FilePath& path, int index, void* params) |
| 243 OVERRIDE; | 234 OVERRIDE; |
| 244 | 235 |
| 245 private: | 236 private: |
| 246 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.export"); | 237 DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.export"); |
| 247 }; | 238 }; |
| 248 | 239 |
| 249 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ | 240 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ |
| OLD | NEW |