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

Side by Side Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 580093003: Factor Google Now welcome notifications out of DesktopNotificationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 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/notifications/desktop_notification_service.h" 5 #include "chrome/browser/notifications/desktop_notification_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/scoped_user_pref_update.h" 9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #endif 48 #endif
49 49
50 using blink::WebTextDirection; 50 using blink::WebTextDirection;
51 using content::BrowserThread; 51 using content::BrowserThread;
52 using content::RenderViewHost; 52 using content::RenderViewHost;
53 using content::WebContents; 53 using content::WebContents;
54 using message_center::NotifierId; 54 using message_center::NotifierId;
55 55
56 namespace { 56 namespace {
57 57
58 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh";
59
60 void CancelNotification(const std::string& id) { 58 void CancelNotification(const std::string& id) {
61 g_browser_process->notification_ui_manager()->CancelById(id); 59 g_browser_process->notification_ui_manager()->CancelById(id);
62 } 60 }
63 61
64 } // namespace 62 } // namespace
65 63
66 // DesktopNotificationService ------------------------------------------------- 64 // DesktopNotificationService -------------------------------------------------
67 65
68 // static 66 // static
69 void DesktopNotificationService::RegisterProfilePrefs( 67 void DesktopNotificationService::RegisterProfilePrefs(
70 user_prefs::PrefRegistrySyncable* registry) { 68 user_prefs::PrefRegistrySyncable* registry) {
71 registry->RegisterListPref( 69 registry->RegisterListPref(
72 prefs::kMessageCenterDisabledExtensionIds, 70 prefs::kMessageCenterDisabledExtensionIds,
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 71 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
74 registry->RegisterListPref( 72 registry->RegisterListPref(
75 prefs::kMessageCenterDisabledSystemComponentIds, 73 prefs::kMessageCenterDisabledSystemComponentIds,
76 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
77 ExtensionWelcomeNotification::RegisterProfilePrefs(registry);
78 } 75 }
79 76
80 // static 77 // static
81 std::string DesktopNotificationService::AddIconNotification( 78 std::string DesktopNotificationService::AddIconNotification(
82 const GURL& origin_url, 79 const GURL& origin_url,
83 const base::string16& title, 80 const base::string16& title,
84 const base::string16& message, 81 const base::string16& message,
85 const gfx::Image& icon, 82 const gfx::Image& icon,
86 const base::string16& replace_id, 83 const base::string16& replace_id,
87 NotificationDelegate* delegate, 84 NotificationDelegate* delegate,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 base::ListValue* const list = update.Get(); 261 base::ListValue* const list = update.Get();
265 if (add_new_item) { 262 if (add_new_item) {
266 // AppendIfNotPresent will delete |adding_value| when the same value 263 // AppendIfNotPresent will delete |adding_value| when the same value
267 // already exists. 264 // already exists.
268 list->AppendIfNotPresent(id.release()); 265 list->AppendIfNotPresent(id.release());
269 } else { 266 } else {
270 list->Remove(*id, NULL); 267 list->Remove(*id, NULL);
271 } 268 }
272 } 269 }
273 270
274 void DesktopNotificationService::ShowWelcomeNotificationIfNecessary(
275 const Notification& notification) {
276 if (!chrome_now_welcome_notification_) {
277 chrome_now_welcome_notification_ =
278 ExtensionWelcomeNotification::Create(kChromeNowExtensionID, profile_);
279 }
280
281 if (chrome_now_welcome_notification_) {
282 chrome_now_welcome_notification_->ShowWelcomeNotificationIfNecessary(
283 notification);
284 }
285 }
286
287 void DesktopNotificationService::OnStringListPrefChanged( 271 void DesktopNotificationService::OnStringListPrefChanged(
288 const char* pref_name, std::set<std::string>* ids_field) { 272 const char* pref_name, std::set<std::string>* ids_field) {
289 ids_field->clear(); 273 ids_field->clear();
290 // Separate GetPrefs()->GetList() to analyze the crash. See crbug.com/322320 274 // Separate GetPrefs()->GetList() to analyze the crash. See crbug.com/322320
291 const PrefService* pref_service = profile_->GetPrefs(); 275 const PrefService* pref_service = profile_->GetPrefs();
292 CHECK(pref_service); 276 CHECK(pref_service);
293 const base::ListValue* pref_list = pref_service->GetList(pref_name); 277 const base::ListValue* pref_list = pref_service->GetList(pref_name);
294 for (size_t i = 0; i < pref_list->GetSize(); ++i) { 278 for (size_t i = 0; i < pref_list->GetSize(); ++i) {
295 std::string element; 279 std::string element;
296 if (pref_list->GetString(i, &element) && !element.empty()) 280 if (pref_list->GetString(i, &element) && !element.empty())
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Tell the IO thread that this extension's permission for notifications 346 // Tell the IO thread that this extension's permission for notifications
363 // has changed. 347 // has changed.
364 extensions::InfoMap* extension_info_map = 348 extensions::InfoMap* extension_info_map =
365 extensions::ExtensionSystem::Get(profile_)->info_map(); 349 extensions::ExtensionSystem::Get(profile_)->info_map();
366 BrowserThread::PostTask( 350 BrowserThread::PostTask(
367 BrowserThread::IO, FROM_HERE, 351 BrowserThread::IO, FROM_HERE,
368 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, 352 base::Bind(&extensions::InfoMap::SetNotificationsDisabled,
369 extension_info_map, notifier_id.id, !enabled)); 353 extension_info_map, notifier_id.id, !enabled));
370 #endif 354 #endif
371 } 355 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698