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/file_path.h" | 8 #include "base/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" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/prefs/public/pref_service_base.h" | 15 #include "base/prefs/public/pref_service_base.h" |
15 #include "base/sha1.h" | 16 #include "base/sha1.h" |
16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
17 #include "base/string16.h" | 18 #include "base/string16.h" |
18 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
20 #include "base/time.h" | 21 #include "base/time.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 args.Pass()); | 267 args.Pass()); |
267 } | 268 } |
268 | 269 |
269 void BookmarkEventRouter::ExtensiveBookmarkChangesEnded(BookmarkModel* model) { | 270 void BookmarkEventRouter::ExtensiveBookmarkChangesEnded(BookmarkModel* model) { |
270 scoped_ptr<ListValue> args(new ListValue()); | 271 scoped_ptr<ListValue> args(new ListValue()); |
271 DispatchEvent(model->profile(), | 272 DispatchEvent(model->profile(), |
272 keys::kOnBookmarkImportEnded, | 273 keys::kOnBookmarkImportEnded, |
273 args.Pass()); | 274 args.Pass()); |
274 } | 275 } |
275 | 276 |
276 BookmarkAPI::BookmarkAPI(Profile* profile) : profile_(profile) { | 277 BookmarksAPI::BookmarksAPI(Profile* profile) : profile_(profile) { |
277 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 278 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
278 this, keys::kOnBookmarkCreated); | 279 this, keys::kOnBookmarkCreated); |
279 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 280 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
280 this, keys::kOnBookmarkRemoved); | 281 this, keys::kOnBookmarkRemoved); |
281 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 282 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
282 this, keys::kOnBookmarkChanged); | 283 this, keys::kOnBookmarkChanged); |
283 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 284 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
284 this, keys::kOnBookmarkMoved); | 285 this, keys::kOnBookmarkMoved); |
285 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 286 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
286 this, keys::kOnBookmarkChildrenReordered); | 287 this, keys::kOnBookmarkChildrenReordered); |
287 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 288 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
288 this, keys::kOnBookmarkImportBegan); | 289 this, keys::kOnBookmarkImportBegan); |
289 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 290 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
290 this, keys::kOnBookmarkImportEnded); | 291 this, keys::kOnBookmarkImportEnded); |
291 } | 292 } |
292 | 293 |
293 BookmarkAPI::~BookmarkAPI() { | 294 BookmarksAPI::~BookmarksAPI() { |
294 } | 295 } |
295 | 296 |
296 void BookmarkAPI::Shutdown() { | 297 void BookmarksAPI::Shutdown() { |
297 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 298 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
298 } | 299 } |
299 | 300 |
300 void BookmarkAPI::OnListenerAdded(const EventListenerInfo& details) { | 301 static base::LazyInstance<ProfileKeyedAPIFactory<BookmarksAPI> > |
| 302 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 303 |
| 304 // static |
| 305 ProfileKeyedAPIFactory<BookmarksAPI>* BookmarksAPI::GetFactoryInstance() { |
| 306 return &g_factory.Get(); |
| 307 } |
| 308 |
| 309 void BookmarksAPI::OnListenerAdded(const EventListenerInfo& details) { |
301 bookmark_event_router_.reset(new BookmarkEventRouter( | 310 bookmark_event_router_.reset(new BookmarkEventRouter( |
302 BookmarkModelFactory::GetForProfile(profile_))); | 311 BookmarkModelFactory::GetForProfile(profile_))); |
303 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 312 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
304 } | 313 } |
305 | 314 |
306 bool BookmarksGetTreeFunction::RunImpl() { | 315 bool BookmarksGetTreeFunction::RunImpl() { |
307 scoped_ptr<bookmarks::Get::Params> params( | 316 scoped_ptr<bookmarks::Get::Params> params( |
308 bookmarks::Get::Params::Create(*args_)); | 317 bookmarks::Get::Params::Create(*args_)); |
309 EXTENSION_FUNCTION_VALIDATE(params.get()); | 318 EXTENSION_FUNCTION_VALIDATE(params.get()); |
310 | 319 |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 #if !defined(OS_ANDROID) | 995 #if !defined(OS_ANDROID) |
987 // Android does not have support for the standard exporter. | 996 // Android does not have support for the standard exporter. |
988 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 997 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
989 // Android. | 998 // Android. |
990 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 999 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
991 #endif | 1000 #endif |
992 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1001 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
993 } | 1002 } |
994 | 1003 |
995 } // namespace extensions | 1004 } // namespace extensions |
OLD | NEW |