Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / multi_profile_first_run_notification.cc
blob69bc537efb3d87a94f19d4c7386bd4110d5a9662
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/multi_profile_first_run_notification.h"
7 #include "ash/system/system_notifier.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string16.h"
10 #include "chrome/browser/chromeos/login/user_manager.h"
11 #include "chrome/browser/prefs/pref_service_syncable.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h"
14 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/notification.h"
20 #include "ui/message_center/notification_delegate.h"
22 using message_center::Notification;
24 namespace chromeos {
26 namespace {
28 const char kNotificationId[] = "chrome:://login/multiprofile";
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) {}
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();
44 virtual void Click() OVERRIDE {}
46 protected:
47 virtual ~MultiProfileFirstRunNotificationDelegate() {}
49 private:
50 base::Closure user_close_callback_;
52 DISALLOW_COPY_AND_ASSIGN(MultiProfileFirstRunNotificationDelegate);
55 } // namespace
57 MultiProfileFirstRunNotification::MultiProfileFirstRunNotification()
58 : weak_ptr_factory_(this) {}
60 MultiProfileFirstRunNotification::~MultiProfileFirstRunNotification() {}
62 // static
63 void MultiProfileFirstRunNotification::RegisterProfilePrefs(
64 user_prefs::PrefRegistrySyncable* registry) {
65 registry->RegisterBooleanPref(
66 prefs::kMultiProfileNotificationDismissed,
67 false,
68 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
69 registry->RegisterBooleanPref(
70 prefs::kMultiProfileNeverShowIntro,
71 false,
72 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
75 void MultiProfileFirstRunNotification::UserProfilePrepared(
76 Profile* user_profile) {
77 if (!UserManager::IsMultipleProfilesAllowed() ||
78 UserManager::Get()->GetLoggedInUsers().size() > 1 ||
79 user_profile->GetPrefs()->GetBoolean(
80 prefs::kMultiProfileNotificationDismissed)) {
81 return;
84 const base::string16 title;
85 const base::string16 display_source;
86 scoped_ptr<Notification> notification(new Notification(
87 message_center::NOTIFICATION_TYPE_SIMPLE,
88 kNotificationId,
89 title,
90 l10n_util::GetStringUTF16(IDS_MULTI_PROFILES_WARNING),
91 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
92 IDR_NOTIFICATION_ALERT),
93 display_source,
94 message_center::NotifierId(
95 message_center::NotifierId::SYSTEM_COMPONENT,
96 ash::system_notifier::kNotifierMultiProfileFirstRun),
97 message_center::RichNotificationData(),
98 new MultiProfileFirstRunNotificationDelegate(
99 base::Bind(&MultiProfileFirstRunNotification::OnDismissed,
100 weak_ptr_factory_.GetWeakPtr(),
101 user_profile))));
102 notification->SetSystemPriority();
103 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
106 void MultiProfileFirstRunNotification::OnDismissed(Profile* user_profile) {
107 user_profile->GetPrefs()->SetBoolean(
108 prefs::kMultiProfileNotificationDismissed, true);
111 } // namespace chromeos