Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 | 92 |
| 93 bool BookmarksFunction::RunAsync() { | 93 bool BookmarksFunction::RunAsync() { |
| 94 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 94 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
| 95 if (!model->loaded()) { | 95 if (!model->loaded()) { |
| 96 // Bookmarks are not ready yet. We'll wait. | 96 // Bookmarks are not ready yet. We'll wait. |
| 97 model->AddObserver(this); | 97 model->AddObserver(this); |
| 98 AddRef(); // Balanced in Loaded(). | 98 AddRef(); // Balanced in Loaded(). |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool success = RunOnReady(); | 102 RunAndSendResponse(); |
| 103 if (success) { | |
| 104 content::NotificationService::current()->Notify( | |
| 105 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | |
| 106 content::Source<const Extension>(extension()), | |
| 107 content::Details<const BookmarksFunction>(this)); | |
| 108 } | |
| 109 SendResponse(success); | |
| 110 return true; | 103 return true; |
| 111 } | 104 } |
| 112 | 105 |
| 113 BookmarkModel* BookmarksFunction::GetBookmarkModel() { | 106 BookmarkModel* BookmarksFunction::GetBookmarkModel() { |
| 114 return BookmarkModelFactory::GetForProfile(GetProfile()); | 107 return BookmarkModelFactory::GetForProfile(GetProfile()); |
| 115 } | 108 } |
| 116 | 109 |
| 117 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() { | 110 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() { |
| 118 return ChromeBookmarkClientFactory::GetForProfile(GetProfile()); | 111 return ChromeBookmarkClientFactory::GetForProfile(GetProfile()); |
| 119 } | 112 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 } | 216 } |
| 224 return true; | 217 return true; |
| 225 } | 218 } |
| 226 | 219 |
| 227 void BookmarksFunction::BookmarkModelChanged() { | 220 void BookmarksFunction::BookmarkModelChanged() { |
| 228 } | 221 } |
| 229 | 222 |
| 230 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, | 223 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, |
| 231 bool ids_reassigned) { | 224 bool ids_reassigned) { |
| 232 model->RemoveObserver(this); | 225 model->RemoveObserver(this); |
| 233 RunOnReady(); | 226 RunAndSendResponse(); |
|
tfarina
2014/10/16 19:08:25
I don't know if it is fine to send extensions::NOT
not at google - send to devlin
2014/10/16 19:40:21
Good point.
It looks like this notification is us
| |
| 234 Release(); // Balanced in RunOnReady(). | 227 Release(); // Balanced in RunOnReady(). |
| 235 } | 228 } |
| 236 | 229 |
| 230 void BookmarksFunction::RunAndSendResponse() { | |
| 231 bool success = RunOnReady(); | |
| 232 if (success) { | |
| 233 content::NotificationService::current()->Notify( | |
| 234 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | |
| 235 content::Source<const Extension>(extension()), | |
| 236 content::Details<const BookmarksFunction>(this)); | |
| 237 } | |
| 238 SendResponse(success); | |
| 239 } | |
| 240 | |
| 237 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) | 241 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) |
| 238 : browser_context_(profile), | 242 : browser_context_(profile), |
| 239 model_(BookmarkModelFactory::GetForProfile(profile)), | 243 model_(BookmarkModelFactory::GetForProfile(profile)), |
| 240 client_(ChromeBookmarkClientFactory::GetForProfile(profile)) { | 244 client_(ChromeBookmarkClientFactory::GetForProfile(profile)) { |
| 241 model_->AddObserver(this); | 245 model_->AddObserver(this); |
| 242 } | 246 } |
| 243 | 247 |
| 244 BookmarkEventRouter::~BookmarkEventRouter() { | 248 BookmarkEventRouter::~BookmarkEventRouter() { |
| 245 if (model_) { | 249 if (model_) { |
| 246 model_->RemoveObserver(this); | 250 model_->RemoveObserver(this); |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 } | 846 } |
| 843 | 847 |
| 844 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 848 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
| 845 int index, | 849 int index, |
| 846 void* params) { | 850 void* params) { |
| 847 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 851 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
| 848 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 852 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 849 } | 853 } |
| 850 | 854 |
| 851 } // namespace extensions | 855 } // namespace extensions |
| OLD | NEW |