Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_api.cc

Issue 2916383004: Revert of Minimize the delegate dependencies for non persistent notifications. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/notifications/notifications_api.h" 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/rand_util.h" 17 #include "base/rand_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h" 22 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h"
24 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h" 23 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h"
25 #include "chrome/browser/notifications/native_notification_delegate.h"
26 #include "chrome/browser/notifications/notification.h" 24 #include "chrome/browser/notifications/notification.h"
27 #include "chrome/browser/notifications/notification_common.h"
28 #include "chrome/browser/notifications/notification_delegate.h"
29 #include "chrome/browser/notifications/notifier_state_tracker.h" 25 #include "chrome/browser/notifications/notifier_state_tracker.h"
30 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" 26 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
31 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/common/chrome_features.h" 28 #include "chrome/common/chrome_features.h"
33 #include "chrome/common/extensions/api/notifications/notification_style.h" 29 #include "chrome/common/extensions/api/notifications/notification_style.h"
34 #include "chrome/common/features.h" 30 #include "chrome/common/features.h"
35 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h" 31 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h"
36 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" 32 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
37 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ShutdownNotifierFactory() 199 ShutdownNotifierFactory()
204 : BrowserContextKeyedServiceShutdownNotifierFactory( 200 : BrowserContextKeyedServiceShutdownNotifierFactory(
205 "NotificationsApiDelegate") { 201 "NotificationsApiDelegate") {
206 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 202 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
207 } 203 }
208 ~ShutdownNotifierFactory() override {} 204 ~ShutdownNotifierFactory() override {}
209 205
210 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory); 206 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory);
211 }; 207 };
212 208
209 // Temporary native notification api delagate, it is only used
210 // to extract the delegate id.
211 // This is an interim state until the work in
212 // https://bugs.chromium.org/p/chromium/issues/detail?id=720345
213 // is completed. We need a small delegate shim since the
214 // Notification object has a non virtual method (delegate_id) that is
215 // used all over the place whose implementation returns delegate->id()
216 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
217 class NativeNotificationApiDelegate : public NotificationDelegate {
218 public:
219 NativeNotificationApiDelegate(const std::string& extension_id,
220 const std::string& notification_id)
221 : scoped_notification_id_(
222 CreateScopedIdentifier(extension_id, notification_id)) {}
223
224 std::string id() const override { return scoped_notification_id_; }
225
226 private:
227 ~NativeNotificationApiDelegate() override = default;
228 const std::string scoped_notification_id_;
229
230 DISALLOW_COPY_AND_ASSIGN(NativeNotificationApiDelegate);
231 };
232 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
233
213 // Message center based notification delegate with all the functionality. 234 // Message center based notification delegate with all the functionality.
214 class NotificationApiDelegate : public NotificationDelegate { 235 class NotificationApiDelegate : public NotificationDelegate {
215 public: 236 public:
216 NotificationApiDelegate(ChromeAsyncExtensionFunction* api_function, 237 NotificationApiDelegate(ChromeAsyncExtensionFunction* api_function,
217 Profile* profile, 238 Profile* profile,
218 const std::string& extension_id, 239 const std::string& extension_id,
219 const std::string& id) 240 const std::string& id)
220 : api_function_(api_function), 241 : api_function_(api_function),
221 event_router_(EventRouter::Get(profile)), 242 event_router_(EventRouter::Get(profile)),
222 display_helper_( 243 display_helper_(
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 base::UTF8ToUTF16(api_item.message))); 513 base::UTF8ToUTF16(api_item.message)));
493 } 514 }
494 } 515 }
495 516
496 if (options->is_clickable.get()) 517 if (options->is_clickable.get())
497 optional_fields.clickable = *options->is_clickable; 518 optional_fields.clickable = *options->is_clickable;
498 519
499 // Create the notification api delegate. Ownership passed to the notification. 520 // Create the notification api delegate. Ownership passed to the notification.
500 NotificationDelegate* api_delegate; 521 NotificationDelegate* api_delegate;
501 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) 522 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
502 if (base::FeatureList::IsEnabled(features::kNativeNotifications) && 523 if (base::FeatureList::IsEnabled(features::kNativeNotifications)) {
503 g_browser_process->notification_platform_bridge()) { 524 api_delegate = new NativeNotificationApiDelegate(extension_->id(), id);
504 api_delegate = new NativeNotificationDelegate(
505 CreateScopedIdentifier(extension_->id(), id));
506 } else { 525 } else {
507 api_delegate = 526 api_delegate =
508 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id); 527 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id);
509 } 528 }
510 #else 529 #else
511 api_delegate = 530 api_delegate =
512 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id); 531 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id);
513 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) 532 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
514 533
515 Notification notification( 534 Notification notification(
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 : api::notifications::PERMISSION_LEVEL_DENIED; 867 : api::notifications::PERMISSION_LEVEL_DENIED;
849 868
850 SetResult( 869 SetResult(
851 base::MakeUnique<base::Value>(api::notifications::ToString(result))); 870 base::MakeUnique<base::Value>(api::notifications::ToString(result)));
852 SendResponse(true); 871 SendResponse(true);
853 872
854 return true; 873 return true;
855 } 874 }
856 875
857 } // namespace extensions 876 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698