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

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

Issue 2888303004: Minimize the delegate dependencies for non persistent notifications. (Closed)
Patch Set: format 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"
22 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h" 23 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h"
23 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h" 24 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h"
25 #include "chrome/browser/notifications/native_notification_delegate.h"
24 #include "chrome/browser/notifications/notification.h" 26 #include "chrome/browser/notifications/notification.h"
27 #include "chrome/browser/notifications/notification_common.h"
28 #include "chrome/browser/notifications/notification_delegate.h"
25 #include "chrome/browser/notifications/notifier_state_tracker.h" 29 #include "chrome/browser/notifications/notifier_state_tracker.h"
26 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" 30 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
27 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/common/chrome_features.h" 32 #include "chrome/common/chrome_features.h"
29 #include "chrome/common/extensions/api/notifications/notification_style.h" 33 #include "chrome/common/extensions/api/notifications/notification_style.h"
30 #include "chrome/common/features.h" 34 #include "chrome/common/features.h"
31 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h" 35 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h"
32 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" 36 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
33 #include "content/public/browser/render_process_host.h" 37 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 ShutdownNotifierFactory() 203 ShutdownNotifierFactory()
200 : BrowserContextKeyedServiceShutdownNotifierFactory( 204 : BrowserContextKeyedServiceShutdownNotifierFactory(
201 "NotificationsApiDelegate") { 205 "NotificationsApiDelegate") {
202 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 206 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
203 } 207 }
204 ~ShutdownNotifierFactory() override {} 208 ~ShutdownNotifierFactory() override {}
205 209
206 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory); 210 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory);
207 }; 211 };
208 212
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
234 // Message center based notification delegate with all the functionality. 213 // Message center based notification delegate with all the functionality.
235 class NotificationApiDelegate : public NotificationDelegate { 214 class NotificationApiDelegate : public NotificationDelegate {
236 public: 215 public:
237 NotificationApiDelegate(ChromeAsyncExtensionFunction* api_function, 216 NotificationApiDelegate(ChromeAsyncExtensionFunction* api_function,
238 Profile* profile, 217 Profile* profile,
239 const std::string& extension_id, 218 const std::string& extension_id,
240 const std::string& id) 219 const std::string& id)
241 : api_function_(api_function), 220 : api_function_(api_function),
242 event_router_(EventRouter::Get(profile)), 221 event_router_(EventRouter::Get(profile)),
243 display_helper_( 222 display_helper_(
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 base::UTF8ToUTF16(api_item.message))); 492 base::UTF8ToUTF16(api_item.message)));
514 } 493 }
515 } 494 }
516 495
517 if (options->is_clickable.get()) 496 if (options->is_clickable.get())
518 optional_fields.clickable = *options->is_clickable; 497 optional_fields.clickable = *options->is_clickable;
519 498
520 // Create the notification api delegate. Ownership passed to the notification. 499 // Create the notification api delegate. Ownership passed to the notification.
521 NotificationDelegate* api_delegate; 500 NotificationDelegate* api_delegate;
522 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) 501 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
523 if (base::FeatureList::IsEnabled(features::kNativeNotifications)) { 502 if (base::FeatureList::IsEnabled(features::kNativeNotifications) &&
524 api_delegate = new NativeNotificationApiDelegate(extension_->id(), id); 503 g_browser_process->notification_platform_bridge()) {
dewittj 2017/06/01 18:44:45 Probably fine but it feels strange to ask the brow
Miguel Garcia 2017/06/02 12:37:13 You are right, this is an artifact of how to decid
504 api_delegate = new NativeNotificationDelegate(
505 CreateScopedIdentifier(extension_->id(), id));
525 } else { 506 } else {
526 api_delegate = 507 api_delegate =
527 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id); 508 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id);
528 } 509 }
529 #else 510 #else
530 api_delegate = 511 api_delegate =
531 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id); 512 new NotificationApiDelegate(this, GetProfile(), extension_->id(), id);
532 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) 513 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
533 514
534 Notification notification( 515 Notification notification(
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 : api::notifications::PERMISSION_LEVEL_DENIED; 848 : api::notifications::PERMISSION_LEVEL_DENIED;
868 849
869 SetResult( 850 SetResult(
870 base::MakeUnique<base::Value>(api::notifications::ToString(result))); 851 base::MakeUnique<base::Value>(api::notifications::ToString(result)));
871 SendResponse(true); 852 SendResponse(true);
872 853
873 return true; 854 return true;
874 } 855 }
875 856
876 } // namespace extensions 857 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698