OLD | NEW |
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 Loading... |
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 base::ListValue* const list = update.Get(); | 257 base::ListValue* const list = update.Get(); |
261 if (add_new_item) { | 258 if (add_new_item) { |
262 // AppendIfNotPresent will delete |adding_value| when the same value | 259 // AppendIfNotPresent will delete |adding_value| when the same value |
263 // already exists. | 260 // already exists. |
264 list->AppendIfNotPresent(id.release()); | 261 list->AppendIfNotPresent(id.release()); |
265 } else { | 262 } else { |
266 list->Remove(*id, NULL); | 263 list->Remove(*id, NULL); |
267 } | 264 } |
268 } | 265 } |
269 | 266 |
270 void DesktopNotificationService::ShowWelcomeNotificationIfNecessary( | |
271 const Notification& notification) { | |
272 if (!chrome_now_welcome_notification_) { | |
273 chrome_now_welcome_notification_ = | |
274 ExtensionWelcomeNotification::Create(kChromeNowExtensionID, profile_); | |
275 } | |
276 | |
277 if (chrome_now_welcome_notification_) { | |
278 chrome_now_welcome_notification_->ShowWelcomeNotificationIfNecessary( | |
279 notification); | |
280 } | |
281 } | |
282 | |
283 void DesktopNotificationService::OnStringListPrefChanged( | 267 void DesktopNotificationService::OnStringListPrefChanged( |
284 const char* pref_name, std::set<std::string>* ids_field) { | 268 const char* pref_name, std::set<std::string>* ids_field) { |
285 ids_field->clear(); | 269 ids_field->clear(); |
286 // Separate GetPrefs()->GetList() to analyze the crash. See crbug.com/322320 | 270 // Separate GetPrefs()->GetList() to analyze the crash. See crbug.com/322320 |
287 const PrefService* pref_service = profile_->GetPrefs(); | 271 const PrefService* pref_service = profile_->GetPrefs(); |
288 CHECK(pref_service); | 272 CHECK(pref_service); |
289 const base::ListValue* pref_list = pref_service->GetList(pref_name); | 273 const base::ListValue* pref_list = pref_service->GetList(pref_name); |
290 for (size_t i = 0; i < pref_list->GetSize(); ++i) { | 274 for (size_t i = 0; i < pref_list->GetSize(); ++i) { |
291 std::string element; | 275 std::string element; |
292 if (pref_list->GetString(i, &element) && !element.empty()) | 276 if (pref_list->GetString(i, &element) && !element.empty()) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // Tell the IO thread that this extension's permission for notifications | 325 // Tell the IO thread that this extension's permission for notifications |
342 // has changed. | 326 // has changed. |
343 extensions::InfoMap* extension_info_map = | 327 extensions::InfoMap* extension_info_map = |
344 extensions::ExtensionSystem::Get(profile_)->info_map(); | 328 extensions::ExtensionSystem::Get(profile_)->info_map(); |
345 BrowserThread::PostTask( | 329 BrowserThread::PostTask( |
346 BrowserThread::IO, FROM_HERE, | 330 BrowserThread::IO, FROM_HERE, |
347 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 331 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
348 extension_info_map, notifier_id.id, !enabled)); | 332 extension_info_map, notifier_id.id, !enabled)); |
349 #endif | 333 #endif |
350 } | 334 } |
OLD | NEW |