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 #include "chrome/browser/extensions/extension_bookmarks_module.h" | 5 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/i18n/file_util_icu.h" | 8 #include "base/i18n/file_util_icu.h" |
9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 return default_path.Append(filename); | 72 return default_path.Append(filename); |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 void BookmarksFunction::Run() { | 77 void BookmarksFunction::Run() { |
78 BookmarkModel* model = profile()->GetBookmarkModel(); | 78 BookmarkModel* model = profile()->GetBookmarkModel(); |
79 if (!model->IsLoaded()) { | 79 if (!model->IsLoaded()) { |
80 // Bookmarks are not ready yet. We'll wait. | 80 // Bookmarks are not ready yet. We'll wait. |
81 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 81 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
82 Source<Profile>(profile())); | 82 NotificationService::AllBrowserContextsAndSources()); |
83 AddRef(); // Balanced in Observe(). | 83 AddRef(); // Balanced in Observe(). |
84 return; | 84 return; |
85 } | 85 } |
86 | 86 |
87 bool success = RunImpl(); | 87 bool success = RunImpl(); |
88 if (success) { | 88 if (success) { |
89 NotificationService::current()->Notify( | 89 NotificationService::current()->Notify( |
90 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | 90 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
91 Source<const Extension>(GetExtension()), | 91 Source<const Extension>(GetExtension()), |
92 Details<const BookmarksFunction>(this)); | 92 Details<const BookmarksFunction>(this)); |
(...skipping 13 matching lines...) Expand all Loading... |
106 bool BookmarksFunction::EditBookmarksEnabled() { | 106 bool BookmarksFunction::EditBookmarksEnabled() { |
107 if (profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled)) | 107 if (profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled)) |
108 return true; | 108 return true; |
109 error_ = keys::kEditBookmarksDisabled; | 109 error_ = keys::kEditBookmarksDisabled; |
110 return false; | 110 return false; |
111 } | 111 } |
112 | 112 |
113 void BookmarksFunction::Observe(int type, | 113 void BookmarksFunction::Observe(int type, |
114 const NotificationSource& source, | 114 const NotificationSource& source, |
115 const NotificationDetails& details) { | 115 const NotificationDetails& details) { |
116 DCHECK_EQ(chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, type); | 116 DCHECK(type == chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED); |
117 DCHECK_EQ(profile(), Source<Profile>(source).ptr()); | 117 Profile* source_profile = Source<Profile>(source).ptr(); |
| 118 if (!source_profile || !source_profile->IsSameProfile(profile())) |
| 119 return; |
| 120 |
118 DCHECK(profile()->GetBookmarkModel()->IsLoaded()); | 121 DCHECK(profile()->GetBookmarkModel()->IsLoaded()); |
119 Run(); | 122 Run(); |
120 Release(); // Balanced in Run(). | 123 Release(); // Balanced in Run(). |
121 } | 124 } |
122 | 125 |
123 ExtensionBookmarkEventRouter::ExtensionBookmarkEventRouter( | 126 ExtensionBookmarkEventRouter::ExtensionBookmarkEventRouter( |
124 BookmarkModel* model) : model_(model) { | 127 BookmarkModel* model) : model_(model) { |
125 } | 128 } |
126 | 129 |
127 ExtensionBookmarkEventRouter::~ExtensionBookmarkEventRouter() { | 130 ExtensionBookmarkEventRouter::~ExtensionBookmarkEventRouter() { |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); | 932 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); |
930 return true; | 933 return true; |
931 } | 934 } |
932 | 935 |
933 void ExportBookmarksFunction::FileSelected(const FilePath& path, | 936 void ExportBookmarksFunction::FileSelected(const FilePath& path, |
934 int index, | 937 int index, |
935 void* params) { | 938 void* params) { |
936 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 939 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
937 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 940 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
938 } | 941 } |
OLD | NEW |