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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 bool BookmarksFunction::RunAsync() { | 92 bool BookmarksFunction::RunAsync() { |
93 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 93 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
94 if (!model->loaded()) { | 94 if (!model->loaded()) { |
95 // Bookmarks are not ready yet. We'll wait. | 95 // Bookmarks are not ready yet. We'll wait. |
96 model->AddObserver(this); | 96 model->AddObserver(this); |
97 AddRef(); // Balanced in Loaded(). | 97 AddRef(); // Balanced in Loaded(). |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 bool success = RunOnReady(); | 101 RunAndSendResponse(); |
102 if (success) { | |
103 content::NotificationService::current()->Notify( | |
104 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | |
105 content::Source<const Extension>(extension()), | |
106 content::Details<const BookmarksFunction>(this)); | |
107 } | |
108 SendResponse(success); | |
109 return true; | 102 return true; |
110 } | 103 } |
111 | 104 |
112 BookmarkModel* BookmarksFunction::GetBookmarkModel() { | 105 BookmarkModel* BookmarksFunction::GetBookmarkModel() { |
113 return BookmarkModelFactory::GetForProfile(GetProfile()); | 106 return BookmarkModelFactory::GetForProfile(GetProfile()); |
114 } | 107 } |
115 | 108 |
116 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() { | 109 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() { |
117 return ChromeBookmarkClientFactory::GetForProfile(GetProfile()); | 110 return ChromeBookmarkClientFactory::GetForProfile(GetProfile()); |
118 } | 111 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 215 } |
223 return true; | 216 return true; |
224 } | 217 } |
225 | 218 |
226 void BookmarksFunction::BookmarkModelChanged() { | 219 void BookmarksFunction::BookmarkModelChanged() { |
227 } | 220 } |
228 | 221 |
229 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, | 222 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, |
230 bool ids_reassigned) { | 223 bool ids_reassigned) { |
231 model->RemoveObserver(this); | 224 model->RemoveObserver(this); |
232 RunOnReady(); | 225 RunAndSendResponse(); |
233 Release(); // Balanced in RunOnReady(). | 226 Release(); // Balanced in RunOnReady(). |
234 } | 227 } |
235 | 228 |
| 229 void BookmarksFunction::RunAndSendResponse() { |
| 230 bool success = RunOnReady(); |
| 231 if (success) { |
| 232 content::NotificationService::current()->Notify( |
| 233 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
| 234 content::Source<const Extension>(extension()), |
| 235 content::Details<const BookmarksFunction>(this)); |
| 236 } |
| 237 SendResponse(success); |
| 238 } |
| 239 |
236 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) | 240 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) |
237 : browser_context_(profile), | 241 : browser_context_(profile), |
238 model_(BookmarkModelFactory::GetForProfile(profile)), | 242 model_(BookmarkModelFactory::GetForProfile(profile)), |
239 client_(ChromeBookmarkClientFactory::GetForProfile(profile)) { | 243 client_(ChromeBookmarkClientFactory::GetForProfile(profile)) { |
240 model_->AddObserver(this); | 244 model_->AddObserver(this); |
241 } | 245 } |
242 | 246 |
243 BookmarkEventRouter::~BookmarkEventRouter() { | 247 BookmarkEventRouter::~BookmarkEventRouter() { |
244 if (model_) { | 248 if (model_) { |
245 model_->RemoveObserver(this); | 249 model_->RemoveObserver(this); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 841 } |
838 | 842 |
839 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 843 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
840 int index, | 844 int index, |
841 void* params) { | 845 void* params) { |
842 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 846 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
843 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 847 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
844 } | 848 } |
845 | 849 |
846 } // namespace extensions | 850 } // namespace extensions |
OLD | NEW |