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/ui/startup/autolaunch_prompt.h" | 5 #include "chrome/browser/ui/startup/autolaunch_prompt.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/auto_launch_trial.h" | 11 #include "chrome/browser/auto_launch_trial.h" |
12 #include "chrome/browser/first_run/first_run.h" | 12 #include "chrome/browser/first_run/first_run.h" |
13 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
14 #include "chrome/browser/infobars/infobar.h" | |
15 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
22 #include "chrome/installer/util/auto_launch_util.h" | 21 #include "chrome/installer/util/auto_launch_util.h" |
23 #include "components/user_prefs/pref_registry_syncable.h" | 22 #include "components/user_prefs/pref_registry_syncable.h" |
24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/navigation_details.h" | 24 #include "content/public/browser/navigation_details.h" |
26 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
27 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
29 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
30 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
31 | 30 |
32 | 31 |
33 // AutolaunchInfoBarDelegate -------------------------------------------------- | 32 // AutolaunchInfoBarDelegate -------------------------------------------------- |
34 | 33 |
35 namespace { | 34 namespace { |
36 | 35 |
37 // The delegate for the infobar shown when Chrome is auto-launched. | 36 // The delegate for the infobar shown when Chrome is auto-launched. |
38 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { | 37 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { |
39 public: | 38 public: |
40 // Creates an autolaunch infobar and delegate and adds the infobar to | 39 // Creates an autolaunch infobar delegate and adds it to |infobar_service|. |
41 // |infobar_service|. | |
42 static void Create(InfoBarService* infobar_service, Profile* profile); | 40 static void Create(InfoBarService* infobar_service, Profile* profile); |
43 | 41 |
44 private: | 42 private: |
45 explicit AutolaunchInfoBarDelegate(Profile* profile); | 43 AutolaunchInfoBarDelegate(InfoBarService* infobar_service, |
| 44 Profile* profile); |
46 virtual ~AutolaunchInfoBarDelegate(); | 45 virtual ~AutolaunchInfoBarDelegate(); |
47 | 46 |
48 void set_should_expire() { should_expire_ = true; } | 47 void set_should_expire() { should_expire_ = true; } |
49 | 48 |
50 // ConfirmInfoBarDelegate: | 49 // ConfirmInfoBarDelegate: |
51 virtual int GetIconID() const OVERRIDE; | 50 virtual int GetIconID() const OVERRIDE; |
52 virtual string16 GetMessageText() const OVERRIDE; | 51 virtual string16 GetMessageText() const OVERRIDE; |
53 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 52 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
54 virtual bool Accept() OVERRIDE; | 53 virtual bool Accept() OVERRIDE; |
55 virtual bool Cancel() OVERRIDE; | 54 virtual bool Cancel() OVERRIDE; |
56 virtual bool ShouldExpireInternal( | 55 virtual bool ShouldExpireInternal( |
57 const content::LoadCommittedDetails& details) const OVERRIDE; | 56 const content::LoadCommittedDetails& details) const OVERRIDE; |
58 | 57 |
59 // Weak pointer to the profile, not owned by us. | 58 // Weak pointer to the profile, not owned by us. |
60 Profile* profile_; | 59 Profile* profile_; |
61 | 60 |
62 // Whether the info-bar should be dismissed on the next navigation. | 61 // Whether the info-bar should be dismissed on the next navigation. |
63 bool should_expire_; | 62 bool should_expire_; |
64 | 63 |
65 // Used to delay the expiration of the info-bar. | 64 // Used to delay the expiration of the info-bar. |
66 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; | 65 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; |
67 | 66 |
68 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); | 67 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); |
69 }; | 68 }; |
70 | 69 |
71 // static | 70 // static |
72 void AutolaunchInfoBarDelegate::Create(InfoBarService* infobar_service, | 71 void AutolaunchInfoBarDelegate::Create(InfoBarService* infobar_service, |
73 Profile* profile) { | 72 Profile* profile) { |
74 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 73 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
75 scoped_ptr<ConfirmInfoBarDelegate>( | 74 new AutolaunchInfoBarDelegate(infobar_service, profile))); |
76 new AutolaunchInfoBarDelegate(profile)))); | |
77 } | 75 } |
78 | 76 |
79 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( | 77 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( |
| 78 InfoBarService* infobar_service, |
80 Profile* profile) | 79 Profile* profile) |
81 : ConfirmInfoBarDelegate(), | 80 : ConfirmInfoBarDelegate(infobar_service), |
82 profile_(profile), | 81 profile_(profile), |
83 should_expire_(false), | 82 should_expire_(false), |
84 weak_factory_(this) { | 83 weak_factory_(this) { |
85 PrefService* prefs = profile->GetPrefs(); | 84 PrefService* prefs = profile->GetPrefs(); |
86 prefs->SetInteger(prefs::kShownAutoLaunchInfobar, | 85 prefs->SetInteger(prefs::kShownAutoLaunchInfobar, |
87 prefs->GetInteger(prefs::kShownAutoLaunchInfobar) + 1); | 86 prefs->GetInteger(prefs::kShownAutoLaunchInfobar) + 1); |
88 | 87 |
89 // We want the info-bar to stick-around for a few seconds and then be hidden | 88 // We want the info-bar to stick-around for a few seconds and then be hidden |
90 // on the next navigation after that. | 89 // on the next navigation after that. |
91 base::MessageLoop::current()->PostDelayedTask( | 90 base::MessageLoop::current()->PostDelayedTask( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return true; | 169 return true; |
171 } | 170 } |
172 | 171 |
173 void RegisterAutolaunchUserPrefs(user_prefs::PrefRegistrySyncable* registry) { | 172 void RegisterAutolaunchUserPrefs(user_prefs::PrefRegistrySyncable* registry) { |
174 registry->RegisterIntegerPref( | 173 registry->RegisterIntegerPref( |
175 prefs::kShownAutoLaunchInfobar, 0, | 174 prefs::kShownAutoLaunchInfobar, 0, |
176 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 175 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
177 } | 176 } |
178 | 177 |
179 } // namespace chrome | 178 } // namespace chrome |
OLD | NEW |