| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/login/multi_profile_first_run_notification.h" | 5 #include "chrome/browser/chromeos/login/multi_profile_first_run_notification.h" |
| 6 | 6 |
| 7 #include "ash/system/system_notifier.h" |
| 7 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 9 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 10 #include "chrome/browser/prefs/pref_service_syncable.h" | 11 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
| 18 #include "ui/message_center/notification.h" | 19 #include "ui/message_center/notification.h" |
| 19 #include "ui/message_center/notification_delegate.h" | 20 #include "ui/message_center/notification_delegate.h" |
| 20 | 21 |
| 21 using message_center::Notification; | 22 using message_center::Notification; |
| 22 | 23 |
| 23 namespace chromeos { | 24 namespace chromeos { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kNotificationId[] = "chrome:://login/multiprofile"; | 28 const char kNotificationId[] = "chrome:://login/multiprofile"; |
| 28 | 29 |
| 30 class MultiProfileFirstRunNotificationDelegate |
| 31 : public message_center::NotificationDelegate { |
| 32 public: |
| 33 explicit MultiProfileFirstRunNotificationDelegate( |
| 34 const base::Closure& user_close_callback) |
| 35 : user_close_callback_(user_close_callback) {} |
| 36 |
| 37 // Overridden from message_center::NotificationDelegate: |
| 38 virtual void Display() OVERRIDE {} |
| 39 virtual void Error() OVERRIDE {} |
| 40 virtual void Close(bool by_user) OVERRIDE { |
| 41 if (by_user) |
| 42 user_close_callback_.Run(); |
| 43 } |
| 44 virtual void Click() OVERRIDE {} |
| 45 |
| 46 protected: |
| 47 virtual ~MultiProfileFirstRunNotificationDelegate() {} |
| 48 |
| 49 private: |
| 50 base::Closure user_close_callback_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(MultiProfileFirstRunNotificationDelegate); |
| 53 }; |
| 54 |
| 29 } // namespace | 55 } // namespace |
| 30 | 56 |
| 31 MultiProfileFirstRunNotification::MultiProfileFirstRunNotification() | 57 MultiProfileFirstRunNotification::MultiProfileFirstRunNotification() |
| 32 : weak_ptr_factory_(this) {} | 58 : weak_ptr_factory_(this) {} |
| 33 | 59 |
| 34 MultiProfileFirstRunNotification::~MultiProfileFirstRunNotification() {} | 60 MultiProfileFirstRunNotification::~MultiProfileFirstRunNotification() {} |
| 35 | 61 |
| 36 // static | 62 // static |
| 37 void MultiProfileFirstRunNotification::RegisterProfilePrefs( | 63 void MultiProfileFirstRunNotification::RegisterProfilePrefs( |
| 38 user_prefs::PrefRegistrySyncable* registry) { | 64 user_prefs::PrefRegistrySyncable* registry) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 const base::string16 title; | 80 const base::string16 title; |
| 55 const base::string16 display_source; | 81 const base::string16 display_source; |
| 56 scoped_ptr<Notification> notification(new Notification( | 82 scoped_ptr<Notification> notification(new Notification( |
| 57 message_center::NOTIFICATION_TYPE_SIMPLE, | 83 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 58 kNotificationId, | 84 kNotificationId, |
| 59 title, | 85 title, |
| 60 l10n_util::GetStringUTF16(IDS_MULTI_PROFILES_WARNING), | 86 l10n_util::GetStringUTF16(IDS_MULTI_PROFILES_WARNING), |
| 61 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 87 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 62 IDR_NOTIFICATION_ALERT), | 88 IDR_NOTIFICATION_ALERT), |
| 63 display_source, | 89 display_source, |
| 64 message_center::NotifierId(), | 90 message_center::NotifierId( |
| 91 message_center::NotifierId::SYSTEM_COMPONENT, |
| 92 ash::system_notifier::kNotifierMultiProfileFirstRun), |
| 65 message_center::RichNotificationData(), | 93 message_center::RichNotificationData(), |
| 66 new message_center::HandleNotificationClickedDelegate( | 94 new MultiProfileFirstRunNotificationDelegate( |
| 67 base::Bind(&MultiProfileFirstRunNotification::OnDismissed, | 95 base::Bind(&MultiProfileFirstRunNotification::OnDismissed, |
| 68 weak_ptr_factory_.GetWeakPtr(), | 96 weak_ptr_factory_.GetWeakPtr(), |
| 69 user_profile)))); | 97 user_profile)))); |
| 70 notification->SetSystemPriority(); | 98 notification->SetSystemPriority(); |
| 71 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 99 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
| 72 } | 100 } |
| 73 | 101 |
| 74 void MultiProfileFirstRunNotification::OnDismissed(Profile* user_profile) { | 102 void MultiProfileFirstRunNotification::OnDismissed(Profile* user_profile) { |
| 75 user_profile->GetPrefs()->SetBoolean( | 103 user_profile->GetPrefs()->SetBoolean( |
| 76 prefs::kMultiProfileNotificationDismissed, true); | 104 prefs::kMultiProfileNotificationDismissed, true); |
| 77 } | 105 } |
| 78 | 106 |
| 79 } // namespace chromeos | 107 } // namespace chromeos |
| OLD | NEW |