| OLD | NEW |
| 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 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" | 5 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/common/extensions/api/bookmarks.h" | 37 #include "chrome/common/extensions/api/bookmarks.h" |
| 38 #include "chrome/common/importer/importer_data_types.h" | 38 #include "chrome/common/importer/importer_data_types.h" |
| 39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 40 #include "components/user_prefs/user_prefs.h" | 40 #include "components/user_prefs/user_prefs.h" |
| 41 #include "content/public/browser/browser_context.h" | 41 #include "content/public/browser/browser_context.h" |
| 42 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 44 #include "content/public/browser/web_contents_view.h" | 44 #include "content/public/browser/web_contents_view.h" |
| 45 #include "extensions/browser/event_router.h" | 45 #include "extensions/browser/event_router.h" |
| 46 #include "extensions/browser/extension_function_dispatcher.h" | 46 #include "extensions/browser/extension_function_dispatcher.h" |
| 47 #include "extensions/browser/extension_system.h" | |
| 48 #include "extensions/browser/quota_service.h" | 47 #include "extensions/browser/quota_service.h" |
| 49 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
| 51 | 50 |
| 52 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 53 #include "ui/aura/remote_window_tree_host_win.h" | 52 #include "ui/aura/remote_window_tree_host_win.h" |
| 54 #endif | 53 #endif |
| 55 | 54 |
| 56 namespace extensions { | 55 namespace extensions { |
| 57 | 56 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 165 |
| 167 BookmarkEventRouter::~BookmarkEventRouter() { | 166 BookmarkEventRouter::~BookmarkEventRouter() { |
| 168 if (model_) { | 167 if (model_) { |
| 169 model_->RemoveObserver(this); | 168 model_->RemoveObserver(this); |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 | 171 |
| 173 void BookmarkEventRouter::DispatchEvent( | 172 void BookmarkEventRouter::DispatchEvent( |
| 174 const std::string& event_name, | 173 const std::string& event_name, |
| 175 scoped_ptr<base::ListValue> event_args) { | 174 scoped_ptr<base::ListValue> event_args) { |
| 176 if (extensions::ExtensionSystem::Get(browser_context_)->event_router()) { | 175 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 177 extensions::ExtensionSystem::Get(browser_context_) | 176 if (event_router) { |
| 178 ->event_router() | 177 event_router->BroadcastEvent( |
| 179 ->BroadcastEvent(make_scoped_ptr( | 178 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass()))); |
| 180 new extensions::Event(event_name, event_args.Pass()))); | |
| 181 } | 179 } |
| 182 } | 180 } |
| 183 | 181 |
| 184 void BookmarkEventRouter::BookmarkModelLoaded(BookmarkModel* model, | 182 void BookmarkEventRouter::BookmarkModelLoaded(BookmarkModel* model, |
| 185 bool ids_reassigned) { | 183 bool ids_reassigned) { |
| 186 // TODO(erikkay): Perhaps we should send this event down to the extension | 184 // TODO(erikkay): Perhaps we should send this event down to the extension |
| 187 // so they know when it's safe to use the API? | 185 // so they know when it's safe to use the API? |
| 188 } | 186 } |
| 189 | 187 |
| 190 void BookmarkEventRouter::BookmarkModelBeingDeleted(BookmarkModel* model) { | 188 void BookmarkEventRouter::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 bookmarks::OnImportBegan::Create()); | 280 bookmarks::OnImportBegan::Create()); |
| 283 } | 281 } |
| 284 | 282 |
| 285 void BookmarkEventRouter::ExtensiveBookmarkChangesEnded(BookmarkModel* model) { | 283 void BookmarkEventRouter::ExtensiveBookmarkChangesEnded(BookmarkModel* model) { |
| 286 DispatchEvent(bookmarks::OnImportEnded::kEventName, | 284 DispatchEvent(bookmarks::OnImportEnded::kEventName, |
| 287 bookmarks::OnImportEnded::Create()); | 285 bookmarks::OnImportEnded::Create()); |
| 288 } | 286 } |
| 289 | 287 |
| 290 BookmarksAPI::BookmarksAPI(BrowserContext* context) | 288 BookmarksAPI::BookmarksAPI(BrowserContext* context) |
| 291 : browser_context_(context) { | 289 : browser_context_(context) { |
| 292 EventRouter* event_router = | 290 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 293 ExtensionSystem::Get(browser_context_)->event_router(); | |
| 294 event_router->RegisterObserver(this, bookmarks::OnCreated::kEventName); | 291 event_router->RegisterObserver(this, bookmarks::OnCreated::kEventName); |
| 295 event_router->RegisterObserver(this, bookmarks::OnRemoved::kEventName); | 292 event_router->RegisterObserver(this, bookmarks::OnRemoved::kEventName); |
| 296 event_router->RegisterObserver(this, bookmarks::OnChanged::kEventName); | 293 event_router->RegisterObserver(this, bookmarks::OnChanged::kEventName); |
| 297 event_router->RegisterObserver(this, bookmarks::OnMoved::kEventName); | 294 event_router->RegisterObserver(this, bookmarks::OnMoved::kEventName); |
| 298 event_router->RegisterObserver(this, | 295 event_router->RegisterObserver(this, |
| 299 bookmarks::OnChildrenReordered::kEventName); | 296 bookmarks::OnChildrenReordered::kEventName); |
| 300 event_router->RegisterObserver(this, bookmarks::OnImportBegan::kEventName); | 297 event_router->RegisterObserver(this, bookmarks::OnImportBegan::kEventName); |
| 301 event_router->RegisterObserver(this, bookmarks::OnImportEnded::kEventName); | 298 event_router->RegisterObserver(this, bookmarks::OnImportEnded::kEventName); |
| 302 } | 299 } |
| 303 | 300 |
| 304 BookmarksAPI::~BookmarksAPI() { | 301 BookmarksAPI::~BookmarksAPI() { |
| 305 } | 302 } |
| 306 | 303 |
| 307 void BookmarksAPI::Shutdown() { | 304 void BookmarksAPI::Shutdown() { |
| 308 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 305 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 309 this); | |
| 310 } | 306 } |
| 311 | 307 |
| 312 static base::LazyInstance<BrowserContextKeyedAPIFactory<BookmarksAPI> > | 308 static base::LazyInstance<BrowserContextKeyedAPIFactory<BookmarksAPI> > |
| 313 g_factory = LAZY_INSTANCE_INITIALIZER; | 309 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 314 | 310 |
| 315 // static | 311 // static |
| 316 BrowserContextKeyedAPIFactory<BookmarksAPI>* | 312 BrowserContextKeyedAPIFactory<BookmarksAPI>* |
| 317 BookmarksAPI::GetFactoryInstance() { | 313 BookmarksAPI::GetFactoryInstance() { |
| 318 return g_factory.Pointer(); | 314 return g_factory.Pointer(); |
| 319 } | 315 } |
| 320 | 316 |
| 321 void BookmarksAPI::OnListenerAdded(const EventListenerInfo& details) { | 317 void BookmarksAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 322 bookmark_event_router_.reset(new BookmarkEventRouter( | 318 bookmark_event_router_.reset(new BookmarkEventRouter( |
| 323 browser_context_, | 319 browser_context_, |
| 324 BookmarkModelFactory::GetForProfile( | 320 BookmarkModelFactory::GetForProfile( |
| 325 Profile::FromBrowserContext(browser_context_)))); | 321 Profile::FromBrowserContext(browser_context_)))); |
| 326 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 322 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 327 this); | |
| 328 } | 323 } |
| 329 | 324 |
| 330 bool BookmarksGetFunction::RunImpl() { | 325 bool BookmarksGetFunction::RunImpl() { |
| 331 scoped_ptr<bookmarks::Get::Params> params( | 326 scoped_ptr<bookmarks::Get::Params> params( |
| 332 bookmarks::Get::Params::Create(*args_)); | 327 bookmarks::Get::Params::Create(*args_)); |
| 333 EXTENSION_FUNCTION_VALIDATE(params.get()); | 328 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 334 | 329 |
| 335 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 330 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 336 if (params->id_or_id_list.as_strings) { | 331 if (params->id_or_id_list.as_strings) { |
| 337 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; | 332 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 #if !defined(OS_ANDROID) | 1008 #if !defined(OS_ANDROID) |
| 1014 // Android does not have support for the standard exporter. | 1009 // Android does not have support for the standard exporter. |
| 1015 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 1010 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
| 1016 // Android. | 1011 // Android. |
| 1017 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 1012 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
| 1018 #endif | 1013 #endif |
| 1019 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1014 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 1020 } | 1015 } |
| 1021 | 1016 |
| 1022 } // namespace extensions | 1017 } // namespace extensions |
| OLD | NEW |