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

Side by Side Diff: chrome/browser/ui/startup/autolaunch_prompt_win.cc

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

Powered by Google App Engine
This is Rietveld 408576698