| 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 #import "ios/chrome/browser/upgrade/upgrade_center.h" | 5 #import "ios/chrome/browser/upgrade/upgrade_center.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #include "base/mac/scoped_nsobject.h" | |
| 13 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 14 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/version.h" | 15 #include "base/version.h" |
| 17 #include "components/infobars/core/confirm_infobar_delegate.h" | 16 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 18 #include "components/infobars/core/infobar.h" | 17 #include "components/infobars/core/infobar.h" |
| 19 #include "components/infobars/core/infobar_manager.h" | 18 #include "components/infobars/core/infobar_manager.h" |
| 20 #include "components/version_info/version_info.h" | 19 #include "components/version_info/version_info.h" |
| 21 #import "ios/chrome/browser/open_url_util.h" | 20 #import "ios/chrome/browser/open_url_util.h" |
| 22 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 21 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 23 #import "ios/chrome/browser/ui/commands/open_url_command.h" | 22 #import "ios/chrome/browser/ui/commands/open_url_command.h" |
| 24 #include "ios/chrome/grit/ios_chromium_strings.h" | 23 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 25 #include "ios/chrome/grit/ios_strings.h" | 24 #include "ios/chrome/grit/ios_strings.h" |
| 26 #import "ios/web/public/url_scheme_util.h" | 25 #import "ios/web/public/url_scheme_util.h" |
| 27 #import "net/base/mac/url_conversions.h" | 26 #import "net/base/mac/url_conversions.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 30 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 31 | 30 |
| 31 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 32 #error "This file requires ARC support." |
| 33 #endif |
| 34 |
| 32 @interface UpgradeCenter () | 35 @interface UpgradeCenter () |
| 33 // Creates infobars on all tabs. | 36 // Creates infobars on all tabs. |
| 34 - (void)showUpgradeInfoBars; | 37 - (void)showUpgradeInfoBars; |
| 35 // Removes all the infobars. | 38 // Removes all the infobars. |
| 36 - (void)hideUpgradeInfoBars; | 39 - (void)hideUpgradeInfoBars; |
| 37 // Callback when an infobar is closed, for any reason. Perform upgrade is set to | 40 // Callback when an infobar is closed, for any reason. Perform upgrade is set to |
| 38 // YES if the user choose to upgrade. | 41 // YES if the user choose to upgrade. |
| 39 - (void)dismissedInfoBar:(NSString*)tabId performUpgrade:(BOOL)shouldUpgrade; | 42 - (void)dismissedInfoBar:(NSString*)tabId performUpgrade:(BOOL)shouldUpgrade; |
| 40 // Returns YES if the infobar should be shown. | 43 // Returns YES if the infobar should be shown. |
| 41 - (BOOL)shouldShowInfoBar; | 44 - (BOOL)shouldShowInfoBar; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 137 |
| 135 ~UpgradeInfoBarDismissObserver() override {} | 138 ~UpgradeInfoBarDismissObserver() override {} |
| 136 | 139 |
| 137 void RegisterObserver(infobars::InfoBarManager* infobar_manager, | 140 void RegisterObserver(infobars::InfoBarManager* infobar_manager, |
| 138 UpgradeInfoBarDelegate* infobar_delegate, | 141 UpgradeInfoBarDelegate* infobar_delegate, |
| 139 NSString* tab_id, | 142 NSString* tab_id, |
| 140 UpgradeCenter* dismiss_delegate) { | 143 UpgradeCenter* dismiss_delegate) { |
| 141 scoped_observer_.Add(infobar_manager); | 144 scoped_observer_.Add(infobar_manager); |
| 142 infobar_delegate_ = infobar_delegate; | 145 infobar_delegate_ = infobar_delegate; |
| 143 dismiss_delegate_ = dismiss_delegate; | 146 dismiss_delegate_ = dismiss_delegate; |
| 144 tab_id_.reset([tab_id copy]); | 147 tab_id_ = [tab_id copy]; |
| 145 } | 148 } |
| 146 | 149 |
| 147 UpgradeInfoBarDelegate* infobar_delegate() { return infobar_delegate_; } | 150 UpgradeInfoBarDelegate* infobar_delegate() { return infobar_delegate_; } |
| 148 | 151 |
| 149 private: | 152 private: |
| 150 // infobars::InfoBarManager::Observer implementation. | 153 // infobars::InfoBarManager::Observer implementation. |
| 151 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override { | 154 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override { |
| 152 if (infobar->delegate() == infobar_delegate_) { | 155 if (infobar->delegate() == infobar_delegate_) { |
| 153 [dismiss_delegate_ dismissedInfoBar:tab_id_.get() | 156 [dismiss_delegate_ dismissedInfoBar:tab_id_ |
| 154 performUpgrade:infobar_delegate_->AcceptPressed()]; | 157 performUpgrade:infobar_delegate_->AcceptPressed()]; |
| 155 } | 158 } |
| 156 } | 159 } |
| 157 | 160 |
| 158 void OnManagerShuttingDown( | 161 void OnManagerShuttingDown( |
| 159 infobars::InfoBarManager* infobar_manager) override { | 162 infobars::InfoBarManager* infobar_manager) override { |
| 160 scoped_observer_.Remove(infobar_manager); | 163 scoped_observer_.Remove(infobar_manager); |
| 161 } | 164 } |
| 162 | 165 |
| 163 UpgradeInfoBarDelegate* infobar_delegate_; | 166 UpgradeInfoBarDelegate* infobar_delegate_; |
| 164 UpgradeCenter* dismiss_delegate_; | 167 __weak UpgradeCenter* dismiss_delegate_; |
| 165 base::scoped_nsobject<NSString> tab_id_; | 168 __strong NSString* tab_id_; |
| 166 ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer> | 169 ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer> |
| 167 scoped_observer_; | 170 scoped_observer_; |
| 168 | 171 |
| 169 DISALLOW_COPY_AND_ASSIGN(UpgradeInfoBarDismissObserver); | 172 DISALLOW_COPY_AND_ASSIGN(UpgradeInfoBarDismissObserver); |
| 170 }; | 173 }; |
| 171 | 174 |
| 172 } // namespace | 175 } // namespace |
| 173 | 176 |
| 174 // The delegateHolder is a simple wrapper to be able to store all the | 177 // The delegateHolder is a simple wrapper to be able to store all the |
| 175 // infoBarDelegate related information in an object that can be put in | 178 // infoBarDelegate related information in an object that can be put in |
| (...skipping 27 matching lines...) Expand all Loading... |
| 203 - (UpgradeInfoBarDelegate*)infoBarDelegate { | 206 - (UpgradeInfoBarDelegate*)infoBarDelegate { |
| 204 return observer_.infobar_delegate(); | 207 return observer_.infobar_delegate(); |
| 205 } | 208 } |
| 206 | 209 |
| 207 @end | 210 @end |
| 208 | 211 |
| 209 @implementation UpgradeCenter { | 212 @implementation UpgradeCenter { |
| 210 // YES if the infobars are currently visible. | 213 // YES if the infobars are currently visible. |
| 211 BOOL upgradeInfoBarIsVisible_; | 214 BOOL upgradeInfoBarIsVisible_; |
| 212 // Used to store the visible upgrade infobars, indexed by tabId. | 215 // Used to store the visible upgrade infobars, indexed by tabId. |
| 213 base::scoped_nsobject<NSMutableDictionary> upgradeInfoBarDelegates_; | 216 __strong NSMutableDictionary<NSString*, DelegateHolder*>* |
| 217 upgradeInfoBarDelegates_; |
| 214 // Stores the clients of the upgrade center. These objectiveC objects are not | 218 // Stores the clients of the upgrade center. These objectiveC objects are not |
| 215 // retained. | 219 // retained. |
| 216 std::set<id<UpgradeCenterClientProtocol>> clients_; | 220 __strong NSHashTable<id<UpgradeCenterClientProtocol>>* clients_; |
| 217 #ifndef NDEBUG | 221 #ifndef NDEBUG |
| 218 bool inCallback_; | 222 BOOL inCallback_; |
| 219 #endif | 223 #endif |
| 220 } | 224 } |
| 221 | 225 |
| 222 + (UpgradeCenter*)sharedInstance { | 226 + (UpgradeCenter*)sharedInstance { |
| 223 static UpgradeCenter* obj; | 227 static UpgradeCenter* obj; |
| 224 static dispatch_once_t onceToken; | 228 static dispatch_once_t onceToken; |
| 225 dispatch_once(&onceToken, ^{ | 229 dispatch_once(&onceToken, ^{ |
| 226 obj = [[self alloc] init]; | 230 obj = [[self alloc] init]; |
| 227 }); | 231 }); |
| 228 return obj; | 232 return obj; |
| 229 } | 233 } |
| 230 | 234 |
| 231 - (instancetype)init { | 235 - (instancetype)init { |
| 232 self = [super init]; | 236 self = [super init]; |
| 233 if (self) { | 237 if (self) { |
| 234 upgradeInfoBarDelegates_.reset([[NSMutableDictionary alloc] init]); | 238 upgradeInfoBarDelegates_ = [[NSMutableDictionary alloc] init]; |
| 235 | 239 |
| 236 // There is no dealloc and no unregister as this class is a never | 240 // There is no dealloc and no unregister as this class is a never |
| 237 // deallocated singleton. | 241 // deallocated singleton. |
| 238 [[NSNotificationCenter defaultCenter] | 242 [[NSNotificationCenter defaultCenter] |
| 239 addObserver:self | 243 addObserver:self |
| 240 selector:@selector(applicationWillEnterForeground:) | 244 selector:@selector(applicationWillEnterForeground:) |
| 241 name:UIApplicationWillEnterForegroundNotification | 245 name:UIApplicationWillEnterForegroundNotification |
| 242 object:nil]; | 246 object:nil]; |
| 243 | 247 |
| 244 upgradeInfoBarIsVisible_ = [self shouldShowInfoBar]; | 248 upgradeInfoBarIsVisible_ = [self shouldShowInfoBar]; |
| 249 clients_ = [NSHashTable weakObjectsHashTable]; |
| 245 } | 250 } |
| 246 return self; | 251 return self; |
| 247 } | 252 } |
| 248 | 253 |
| 249 - (BOOL)shouldShowInfoBar { | 254 - (BOOL)shouldShowInfoBar { |
| 250 return [self isCurrentVersionObsolete] && ![self infoBarShownRecently]; | 255 return [self isCurrentVersionObsolete] && ![self infoBarShownRecently]; |
| 251 } | 256 } |
| 252 | 257 |
| 253 - (BOOL)isCurrentVersionObsolete { | 258 - (BOOL)isCurrentVersionObsolete { |
| 254 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 259 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 277 if (upgradeInfoBarIsVisible_) | 282 if (upgradeInfoBarIsVisible_) |
| 278 return; | 283 return; |
| 279 | 284 |
| 280 // When returning to active if the upgrade notification has been dismissed, | 285 // When returning to active if the upgrade notification has been dismissed, |
| 281 // bring it back. | 286 // bring it back. |
| 282 if ([self shouldShowInfoBar]) | 287 if ([self shouldShowInfoBar]) |
| 283 [self showUpgradeInfoBars]; | 288 [self showUpgradeInfoBars]; |
| 284 } | 289 } |
| 285 | 290 |
| 286 - (void)registerClient:(id<UpgradeCenterClientProtocol>)client { | 291 - (void)registerClient:(id<UpgradeCenterClientProtocol>)client { |
| 287 clients_.insert(client); | 292 [clients_ addObject:client]; |
| 288 if (upgradeInfoBarIsVisible_) | 293 if (upgradeInfoBarIsVisible_) |
| 289 [client showUpgrade:self]; | 294 [client showUpgrade:self]; |
| 290 } | 295 } |
| 291 | 296 |
| 292 - (void)unregisterClient:(id<UpgradeCenterClientProtocol>)client { | 297 - (void)unregisterClient:(id<UpgradeCenterClientProtocol>)client { |
| 293 #ifndef NDEBUG | 298 #ifndef NDEBUG |
| 294 DCHECK(!inCallback_); | 299 DCHECK(!inCallback_); |
| 295 #endif | 300 #endif |
| 296 clients_.erase(client); | 301 [clients_ removeObject:client]; |
| 297 } | 302 } |
| 298 | 303 |
| 299 - (void)addInfoBarToManager:(infobars::InfoBarManager*)infoBarManager | 304 - (void)addInfoBarToManager:(infobars::InfoBarManager*)infoBarManager |
| 300 forTabId:(NSString*)tabId { | 305 forTabId:(NSString*)tabId { |
| 301 DCHECK(tabId); | 306 DCHECK(tabId); |
| 302 DCHECK(infoBarManager); | 307 DCHECK(infoBarManager); |
| 303 | 308 |
| 304 // Nothing to do if the infobar are not visible at this point in time. | 309 // Nothing to do if the infobar are not visible at this point in time. |
| 305 if (!upgradeInfoBarIsVisible_) | 310 if (!upgradeInfoBarIsVisible_) |
| 306 return; | 311 return; |
| 307 | 312 |
| 308 // Nothing to do if the infobar is already there. | 313 // Nothing to do if the infobar is already there. |
| 309 if ([upgradeInfoBarDelegates_ objectForKey:tabId]) | 314 if ([upgradeInfoBarDelegates_ objectForKey:tabId]) |
| 310 return; | 315 return; |
| 311 | 316 |
| 312 auto infobarDelegate = base::MakeUnique<UpgradeInfoBarDelegate>(); | 317 auto infobarDelegate = base::MakeUnique<UpgradeInfoBarDelegate>(); |
| 313 base::scoped_nsobject<DelegateHolder> delegateHolder([[DelegateHolder alloc] | 318 DelegateHolder* delegateHolder = |
| 314 initWithInfoBarManager:infoBarManager | 319 [[DelegateHolder alloc] initWithInfoBarManager:infoBarManager |
| 315 infoBarDelegate:infobarDelegate.get() | 320 infoBarDelegate:infobarDelegate.get() |
| 316 upgradeCenter:self | 321 upgradeCenter:self |
| 317 tabId:tabId]); | 322 tabId:tabId]; |
| 318 | 323 |
| 319 [upgradeInfoBarDelegates_ setObject:delegateHolder forKey:tabId]; | 324 [upgradeInfoBarDelegates_ setObject:delegateHolder forKey:tabId]; |
| 320 infoBarManager->AddInfoBar( | 325 infoBarManager->AddInfoBar( |
| 321 infoBarManager->CreateConfirmInfoBar(std::move(infobarDelegate))); | 326 infoBarManager->CreateConfirmInfoBar(std::move(infobarDelegate))); |
| 322 } | 327 } |
| 323 | 328 |
| 324 - (void)tabWillClose:(NSString*)tabId { | 329 - (void)tabWillClose:(NSString*)tabId { |
| 325 [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; | 330 [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; |
| 326 } | 331 } |
| 327 | 332 |
| 328 - (void)dismissedInfoBar:(NSString*)tabId performUpgrade:(BOOL)shouldUpgrade { | 333 - (void)dismissedInfoBar:(NSString*)tabId performUpgrade:(BOOL)shouldUpgrade { |
| 329 // If the tabId is not in the upgradeInfoBarDelegates_ just ignore the | 334 // If the tabId is not in the upgradeInfoBarDelegates_ just ignore the |
| 330 // notification. In all likelyhood it was trigerred by calling | 335 // notification. In all likelyhood it was trigerred by calling |
| 331 // -hideUpgradeInfoBars. Or because a tab was closed without dismissing the | 336 // -hideUpgradeInfoBars. Or because a tab was closed without dismissing the |
| 332 // infobar. | 337 // infobar. |
| 333 base::scoped_nsobject<DelegateHolder> delegateHolder( | 338 DelegateHolder* delegateHolder = |
| 334 [[upgradeInfoBarDelegates_ objectForKey:tabId] retain]); | 339 [upgradeInfoBarDelegates_ objectForKey:tabId]; |
| 335 if (!delegateHolder.get()) | 340 if (!delegateHolder) |
| 336 return; | 341 return; |
| 337 | 342 |
| 338 // Forget about this dismissed infobar. | 343 // Forget about this dismissed infobar. |
| 339 [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; | 344 [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; |
| 340 | 345 |
| 341 // Get rid of all the infobars on the other tabs. | 346 // Get rid of all the infobars on the other tabs. |
| 342 [self hideUpgradeInfoBars]; | 347 [self hideUpgradeInfoBars]; |
| 343 | 348 |
| 344 if (shouldUpgrade) { | 349 if (shouldUpgrade) { |
| 345 NSString* urlString = | 350 NSString* urlString = |
| 346 [[NSUserDefaults standardUserDefaults] valueForKey:kUpgradeURLKey]; | 351 [[NSUserDefaults standardUserDefaults] valueForKey:kUpgradeURLKey]; |
| 347 if (!urlString) | 352 if (!urlString) |
| 348 return; // Missing URL, no upgrade possible. | 353 return; // Missing URL, no upgrade possible. |
| 349 | 354 |
| 350 GURL url = GURL(base::SysNSStringToUTF8(urlString)); | 355 GURL url = GURL(base::SysNSStringToUTF8(urlString)); |
| 351 if (!url.is_valid()) | 356 if (!url.is_valid()) |
| 352 return; | 357 return; |
| 353 | 358 |
| 354 if (web::UrlHasWebScheme(url)) { | 359 if (web::UrlHasWebScheme(url)) { |
| 355 // This URL can be opened in the application, just open in a new tab. | 360 // This URL can be opened in the application, just open in a new tab. |
| 356 base::scoped_nsobject<OpenUrlCommand> command( | 361 OpenUrlCommand* command = |
| 357 [[OpenUrlCommand alloc] initWithURLFromChrome:url]); | 362 [[OpenUrlCommand alloc] initWithURLFromChrome:url]; |
| 358 UIWindow* main_window = [[UIApplication sharedApplication] keyWindow]; | 363 UIWindow* main_window = [[UIApplication sharedApplication] keyWindow]; |
| 359 DCHECK(main_window); | 364 DCHECK(main_window); |
| 360 [main_window chromeExecuteCommand:command]; | 365 [main_window chromeExecuteCommand:command]; |
| 361 } else { | 366 } else { |
| 362 // This URL scheme is not understood, ask the system to open it. | 367 // This URL scheme is not understood, ask the system to open it. |
| 363 NSURL* nsurl = [NSURL URLWithString:urlString]; | 368 NSURL* nsurl = [NSURL URLWithString:urlString]; |
| 364 if (nsurl) { | 369 if (nsurl) { |
| 365 OpenUrlWithCompletionHandler(nsurl, nil); | 370 OpenUrlWithCompletionHandler(nsurl, nil); |
| 366 } | 371 } |
| 367 } | 372 } |
| 368 } | 373 } |
| 369 } | 374 } |
| 370 | 375 |
| 371 - (void)showUpgradeInfoBars { | 376 - (void)showUpgradeInfoBars { |
| 372 // Add an infobar on all the open tabs. | 377 // Add an infobar on all the open tabs. |
| 373 #ifndef NDEBUG | 378 #ifndef NDEBUG |
| 374 inCallback_ = YES; | 379 inCallback_ = YES; |
| 375 #endif | 380 #endif |
| 376 upgradeInfoBarIsVisible_ = YES; | 381 upgradeInfoBarIsVisible_ = YES; |
| 377 std::set<id<UpgradeCenterClientProtocol>>::iterator it; | 382 for (id<UpgradeCenterClientProtocol> upgradeClient in clients_) |
| 378 for (it = clients_.begin(); it != clients_.end(); ++it) | 383 [upgradeClient showUpgrade:self]; |
| 379 [*it showUpgrade:self]; | |
| 380 #ifndef NDEBUG | 384 #ifndef NDEBUG |
| 381 inCallback_ = NO; | 385 inCallback_ = NO; |
| 382 #endif | 386 #endif |
| 383 | 387 |
| 384 [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] | 388 [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] |
| 385 forKey:kLastInfobarDisplayTimeKey]; | 389 forKey:kLastInfobarDisplayTimeKey]; |
| 386 } | 390 } |
| 387 | 391 |
| 388 - (void)hideUpgradeInfoBars { | 392 - (void)hideUpgradeInfoBars { |
| 389 upgradeInfoBarIsVisible_ = NO; | 393 upgradeInfoBarIsVisible_ = NO; |
| 390 // It is important to call -allKeys here and not using a fast iteration on the | 394 // It is important to call -allKeys here and not using a fast iteration on the |
| 391 // dictionary directly: the dictionary is modified as we go... | 395 // dictionary directly: the dictionary is modified as we go... |
| 392 for (NSString* tabId in [upgradeInfoBarDelegates_ allKeys]) { | 396 for (NSString* tabId in [upgradeInfoBarDelegates_ allKeys]) { |
| 393 // It is important to retain the delegateHolder as otherwise it is | 397 // It is important to retain the delegateHolder as otherwise it is |
| 394 // deallocated as soon as it is removed from the dictionary. | 398 // deallocated as soon as it is removed from the dictionary. |
| 395 base::scoped_nsobject<DelegateHolder> delegateHolder( | 399 DelegateHolder* delegateHolder = |
| 396 [[upgradeInfoBarDelegates_ objectForKey:tabId] retain]); | 400 [upgradeInfoBarDelegates_ objectForKey:tabId]; |
| 397 if (delegateHolder.get()) { | 401 if (delegateHolder) { |
| 398 [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; | 402 [upgradeInfoBarDelegates_ removeObjectForKey:tabId]; |
| 399 UpgradeInfoBarDelegate* delegate = [delegateHolder infoBarDelegate]; | 403 UpgradeInfoBarDelegate* delegate = [delegateHolder infoBarDelegate]; |
| 400 DCHECK(delegate); | 404 DCHECK(delegate); |
| 401 delegate->RemoveSelf(); | 405 delegate->RemoveSelf(); |
| 402 } | 406 } |
| 403 } | 407 } |
| 404 } | 408 } |
| 405 | 409 |
| 406 - (void)upgradeNotificationDidOccur:(const UpgradeRecommendedDetails&)details { | 410 - (void)upgradeNotificationDidOccur:(const UpgradeRecommendedDetails&)details { |
| 407 const GURL& upgradeUrl = details.upgrade_url; | 411 const GURL& upgradeUrl = details.upgrade_url; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 if ([self shouldShowInfoBar]) | 443 if ([self shouldShowInfoBar]) |
| 440 [self showUpgradeInfoBars]; | 444 [self showUpgradeInfoBars]; |
| 441 } | 445 } |
| 442 | 446 |
| 443 - (void)resetForTests { | 447 - (void)resetForTests { |
| 444 [[UpgradeCenter sharedInstance] hideUpgradeInfoBars]; | 448 [[UpgradeCenter sharedInstance] hideUpgradeInfoBars]; |
| 445 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 449 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 446 [defaults removeObjectForKey:kNextVersionKey]; | 450 [defaults removeObjectForKey:kNextVersionKey]; |
| 447 [defaults removeObjectForKey:kUpgradeURLKey]; | 451 [defaults removeObjectForKey:kUpgradeURLKey]; |
| 448 [defaults removeObjectForKey:kLastInfobarDisplayTimeKey]; | 452 [defaults removeObjectForKey:kLastInfobarDisplayTimeKey]; |
| 449 clients_.clear(); | 453 [clients_ removeAllObjects]; |
| 450 } | 454 } |
| 451 | 455 |
| 452 - (void)setLastDisplayToPast { | 456 - (void)setLastDisplayToPast { |
| 453 NSDate* pastDate = | 457 NSDate* pastDate = |
| 454 [NSDate dateWithTimeIntervalSinceNow:-(kInfobarDisplayInterval + 1)]; | 458 [NSDate dateWithTimeIntervalSinceNow:-(kInfobarDisplayInterval + 1)]; |
| 455 [[NSUserDefaults standardUserDefaults] setObject:pastDate | 459 [[NSUserDefaults standardUserDefaults] setObject:pastDate |
| 456 forKey:kLastInfobarDisplayTimeKey]; | 460 forKey:kLastInfobarDisplayTimeKey]; |
| 457 } | 461 } |
| 458 | 462 |
| 459 @end | 463 @end |
| OLD | NEW |