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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/extensions/extension_bookmark_helpers.h" | 23 #include "chrome/browser/extensions/extension_bookmark_helpers.h" |
24 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" | 24 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" |
25 #include "chrome/browser/extensions/extension_event_router.h" | 25 #include "chrome/browser/extensions/extension_event_router.h" |
26 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 26 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
27 #include "chrome/browser/extensions/extensions_quota_service.h" | 27 #include "chrome/browser/extensions/extensions_quota_service.h" |
28 #include "chrome/browser/importer/importer_data_types.h" | 28 #include "chrome/browser/importer/importer_data_types.h" |
29 #include "chrome/browser/importer/importer_host.h" | 29 #include "chrome/browser/importer/importer_host.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
| 33 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
35 #include "content/common/notification_service.h" | 36 #include "content/common/notification_service.h" |
36 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
38 | 39 |
39 namespace keys = extension_bookmarks_module_constants; | 40 namespace keys = extension_bookmarks_module_constants; |
40 | 41 |
41 using base::TimeDelta; | 42 using base::TimeDelta; |
42 typedef QuotaLimitHeuristic::Bucket Bucket; | 43 typedef QuotaLimitHeuristic::Bucket Bucket; |
(...skipping 27 matching lines...) Expand all Loading... |
70 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path); | 71 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path); |
71 return default_path.Append(filename); | 72 return default_path.Append(filename); |
72 } | 73 } |
73 | 74 |
74 } // namespace | 75 } // namespace |
75 | 76 |
76 void BookmarksFunction::Run() { | 77 void BookmarksFunction::Run() { |
77 BookmarkModel* model = profile()->GetBookmarkModel(); | 78 BookmarkModel* model = profile()->GetBookmarkModel(); |
78 if (!model->IsLoaded()) { | 79 if (!model->IsLoaded()) { |
79 // Bookmarks are not ready yet. We'll wait. | 80 // Bookmarks are not ready yet. We'll wait. |
80 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, | 81 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
81 NotificationService::AllSources()); | 82 NotificationService::AllSources()); |
82 AddRef(); // Balanced in Observe(). | 83 AddRef(); // Balanced in Observe(). |
83 return; | 84 return; |
84 } | 85 } |
85 | 86 |
86 bool success = RunImpl(); | 87 bool success = RunImpl(); |
87 if (success) { | 88 if (success) { |
88 NotificationService::current()->Notify( | 89 NotificationService::current()->Notify( |
89 NotificationType::EXTENSION_BOOKMARKS_API_INVOKED, | 90 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
90 Source<const Extension>(GetExtension()), | 91 Source<const Extension>(GetExtension()), |
91 Details<const BookmarksFunction>(this)); | 92 Details<const BookmarksFunction>(this)); |
92 } | 93 } |
93 SendResponse(success); | 94 SendResponse(success); |
94 } | 95 } |
95 | 96 |
96 bool BookmarksFunction::GetBookmarkIdAsInt64( | 97 bool BookmarksFunction::GetBookmarkIdAsInt64( |
97 const std::string& id_string, int64* id) { | 98 const std::string& id_string, int64* id) { |
98 if (base::StringToInt64(id_string, id)) | 99 if (base::StringToInt64(id_string, id)) |
99 return true; | 100 return true; |
100 | 101 |
101 error_ = keys::kInvalidIdError; | 102 error_ = keys::kInvalidIdError; |
102 return false; | 103 return false; |
103 } | 104 } |
104 | 105 |
105 bool BookmarksFunction::EditBookmarksEnabled() { | 106 bool BookmarksFunction::EditBookmarksEnabled() { |
106 if (profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled)) | 107 if (profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled)) |
107 return true; | 108 return true; |
108 error_ = keys::kEditBookmarksDisabled; | 109 error_ = keys::kEditBookmarksDisabled; |
109 return false; | 110 return false; |
110 } | 111 } |
111 | 112 |
112 void BookmarksFunction::Observe(NotificationType type, | 113 void BookmarksFunction::Observe(int type, |
113 const NotificationSource& source, | 114 const NotificationSource& source, |
114 const NotificationDetails& details) { | 115 const NotificationDetails& details) { |
115 DCHECK(type == NotificationType::BOOKMARK_MODEL_LOADED); | 116 DCHECK(type == chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED); |
116 DCHECK(profile()->GetBookmarkModel()->IsLoaded()); | 117 DCHECK(profile()->GetBookmarkModel()->IsLoaded()); |
117 Run(); | 118 Run(); |
118 Release(); // Balanced in Run(). | 119 Release(); // Balanced in Run(). |
119 } | 120 } |
120 | 121 |
121 ExtensionBookmarkEventRouter::ExtensionBookmarkEventRouter( | 122 ExtensionBookmarkEventRouter::ExtensionBookmarkEventRouter( |
122 BookmarkModel* model) : model_(model) { | 123 BookmarkModel* model) : model_(model) { |
123 } | 124 } |
124 | 125 |
125 ExtensionBookmarkEventRouter::~ExtensionBookmarkEventRouter() { | 126 ExtensionBookmarkEventRouter::~ExtensionBookmarkEventRouter() { |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); | 927 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); |
927 return true; | 928 return true; |
928 } | 929 } |
929 | 930 |
930 void ExportBookmarksFunction::FileSelected(const FilePath& path, | 931 void ExportBookmarksFunction::FileSelected(const FilePath& path, |
931 int index, | 932 int index, |
932 void* params) { | 933 void* params) { |
933 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 934 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
934 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 935 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
935 } | 936 } |
OLD | NEW |