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/cocoa/keystone_infobar_delegate.h" | 5 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
33 | 33 |
34 class SkBitmap; | 34 class SkBitmap; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // KeystonePromotionInfoBarDelegate ------------------------------------------- | 38 // KeystonePromotionInfoBarDelegate ------------------------------------------- |
39 | 39 |
40 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { | 40 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { |
41 public: | 41 public: |
42 KeystonePromotionInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 42 KeystonePromotionInfoBarDelegate(InfoBarTabService* infobar_service, |
43 PrefService* prefs); | 43 PrefService* prefs); |
44 | 44 |
45 private: | 45 private: |
46 virtual ~KeystonePromotionInfoBarDelegate(); | 46 virtual ~KeystonePromotionInfoBarDelegate(); |
47 | 47 |
48 // Sets this info bar to be able to expire. Called a predetermined amount | 48 // Sets this info bar to be able to expire. Called a predetermined amount |
49 // of time after this object is created. | 49 // of time after this object is created. |
50 void SetCanExpire() { can_expire_ = true; } | 50 void SetCanExpire() { can_expire_ = true; } |
51 | 51 |
52 // ConfirmInfoBarDelegate | 52 // ConfirmInfoBarDelegate |
(...skipping 11 matching lines...) Expand all Loading... |
64 // Whether the info bar should be dismissed on the next navigation. | 64 // Whether the info bar should be dismissed on the next navigation. |
65 bool can_expire_; | 65 bool can_expire_; |
66 | 66 |
67 // Used to delay the expiration of the info bar. | 67 // Used to delay the expiration of the info bar. |
68 base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_; | 68 base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); |
71 }; | 71 }; |
72 | 72 |
73 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( | 73 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( |
74 InfoBarTabHelper* infobar_helper, | 74 InfoBarTabService* infobar_service, |
75 PrefService* prefs) | 75 PrefService* prefs) |
76 : ConfirmInfoBarDelegate(infobar_helper), | 76 : ConfirmInfoBarDelegate(infobar_service), |
77 prefs_(prefs), | 77 prefs_(prefs), |
78 can_expire_(false), | 78 can_expire_(false), |
79 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 79 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
80 const base::TimeDelta kCanExpireOnNavigationAfterDelay = | 80 const base::TimeDelta kCanExpireOnNavigationAfterDelay = |
81 base::TimeDelta::FromSeconds(8); | 81 base::TimeDelta::FromSeconds(8); |
82 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 82 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
83 base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire, | 83 base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire, |
84 weak_ptr_factory_.GetWeakPtr()), | 84 weak_ptr_factory_.GetWeakPtr()), |
85 kCanExpireOnNavigationAfterDelay); | 85 kCanExpireOnNavigationAfterDelay); |
86 } | 86 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 if (status != kAutoupdateRegisterFailed && | 191 if (status != kAutoupdateRegisterFailed && |
192 [[KeystoneGlue defaultKeystoneGlue] needsPromotion]) { | 192 [[KeystoneGlue defaultKeystoneGlue] needsPromotion]) { |
193 Browser* browser = browser::GetLastActiveBrowser(); | 193 Browser* browser = browser::GetLastActiveBrowser(); |
194 if (browser) { | 194 if (browser) { |
195 TabContents* tabContents = chrome::GetActiveTabContents(browser); | 195 TabContents* tabContents = chrome::GetActiveTabContents(browser); |
196 | 196 |
197 // Only show if no other info bars are showing, because that's how the | 197 // Only show if no other info bars are showing, because that's how the |
198 // default browser info bar works. | 198 // default browser info bar works. |
199 if (tabContents) { | 199 if (tabContents) { |
200 InfoBarTabHelper* infobar_helper = tabContents->infobar_tab_helper(); | 200 InfoBarTabHelper* infobar_helper = tabContents->infobar_tab_helper(); |
201 if (infobar_helper->infobar_count() == 0) { | 201 if (infobar_helper->GetInfoBarCount() == 0) { |
202 infobar_helper->AddInfoBar( | 202 infobar_helper->AddInfoBar( |
203 new KeystonePromotionInfoBarDelegate( | 203 new KeystonePromotionInfoBarDelegate( |
204 infobar_helper, | 204 infobar_helper, |
205 tabContents->profile()->GetPrefs())); | 205 tabContents->profile()->GetPrefs())); |
206 } | 206 } |
207 } | 207 } |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 [self release]; | 211 [self release]; |
212 } | 212 } |
213 | 213 |
214 - (void)removeObserver { | 214 - (void)removeObserver { |
215 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 215 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
216 } | 216 } |
217 | 217 |
218 @end // @implementation KeystonePromotionInfoBar | 218 @end // @implementation KeystonePromotionInfoBar |
219 | 219 |
220 // static | 220 // static |
221 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { | 221 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { |
222 KeystonePromotionInfoBar* promotionInfoBar = | 222 KeystonePromotionInfoBar* promotionInfoBar = |
223 [[[KeystonePromotionInfoBar alloc] init] autorelease]; | 223 [[[KeystonePromotionInfoBar alloc] init] autorelease]; |
224 | 224 |
225 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; | 225 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; |
226 } | 226 } |
OLD | NEW |