| 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/protector/settings_change_global_error.h" | 5 #include "chrome/browser/protector/settings_change_global_error.h" |
| 6 | 6 |
| 7 #include <bitset> | 7 #include <bitset> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 DCHECK(menu_id_ >= 0) << "Out of command IDs for SettingsChangeGlobalError"; | 62 DCHECK(menu_id_ >= 0) << "Out of command IDs for SettingsChangeGlobalError"; |
| 63 } | 63 } |
| 64 | 64 |
| 65 SettingsChangeGlobalError::~SettingsChangeGlobalError() { | 65 SettingsChangeGlobalError::~SettingsChangeGlobalError() { |
| 66 if (profile_) | 66 if (profile_) |
| 67 RemoveFromProfile(); | 67 RemoveFromProfile(); |
| 68 if (menu_id_ >= 0) | 68 if (menu_id_ >= 0) |
| 69 menu_ids.Get().reset(menu_id_ - IDC_SHOW_SETTINGS_CHANGE_FIRST); | 69 menu_ids.Get().reset(menu_id_ - IDC_SHOW_SETTINGS_CHANGE_FIRST); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SettingsChangeGlobalError::AddToProfile(Profile* profile, | 72 void SettingsChangeGlobalError::AddToProfile( |
| 73 bool show_bubble) { | 73 Profile* profile, |
| 74 bool show_bubble, |
| 75 chrome::HostDesktopType desktop_type) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 profile_ = profile; | 77 profile_ = profile; |
| 76 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this); | 78 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this); |
| 77 BrowserList::AddObserver(this); | 79 BrowserList::AddObserver(this); |
| 78 if (show_bubble) { | 80 if (show_bubble) { |
| 79 ShowBubble(); | 81 ShowBubble(desktop_type); |
| 80 } else { | 82 } else { |
| 81 // Start inactivity timer. | 83 // Start inactivity timer. |
| 82 BrowserThread::PostDelayedTask( | 84 BrowserThread::PostDelayedTask( |
| 83 BrowserThread::UI, FROM_HERE, | 85 BrowserThread::UI, FROM_HERE, |
| 84 base::Bind(&SettingsChangeGlobalError::OnInactiveTimeout, | 86 base::Bind(&SettingsChangeGlobalError::OnInactiveTimeout, |
| 85 weak_factory_.GetWeakPtr()), | 87 weak_factory_.GetWeakPtr()), |
| 86 base::TimeDelta::FromMilliseconds(kMenuItemDisplayPeriodMs)); | 88 base::TimeDelta::FromMilliseconds(kMenuItemDisplayPeriodMs)); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 | 91 |
| 90 void SettingsChangeGlobalError::RemoveFromProfile() { | 92 void SettingsChangeGlobalError::RemoveFromProfile() { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 92 if (profile_) { | 94 if (profile_) { |
| 93 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); | 95 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); |
| 94 profile_ = NULL; | 96 profile_ = NULL; |
| 95 } | 97 } |
| 96 BrowserList::RemoveObserver(this); | 98 BrowserList::RemoveObserver(this); |
| 97 // This will delete |this|. | 99 // This will delete |this|. |
| 98 delegate_->OnRemovedFromProfile(this); | 100 delegate_->OnRemovedFromProfile(this); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void SettingsChangeGlobalError::ShowBubble() { | 103 void SettingsChangeGlobalError::ShowBubble( |
| 104 chrome::HostDesktopType desktop_type) { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 103 DCHECK(profile_); | 106 DCHECK(profile_); |
| 104 Browser* browser = browser::FindTabbedBrowser( | 107 Browser* browser = browser::FindTabbedBrowser(profile_, true, desktop_type); |
| 105 profile_, | |
| 106 // match incognito | |
| 107 true); | |
| 108 if (browser) | 108 if (browser) |
| 109 ShowBubbleInBrowser(browser); | 109 ShowBubbleInBrowser(browser); |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool SettingsChangeGlobalError::HasBadge() { | 112 bool SettingsChangeGlobalError::HasBadge() { |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 int SettingsChangeGlobalError::GetBadgeResourceID() { | 116 int SettingsChangeGlobalError::GetBadgeResourceID() { |
| 117 return change_->GetBadgeIconID(); | 117 return change_->GetBadgeIconID(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // A tabbed browser window got activated, show the error bubble again. | 210 // A tabbed browser window got activated, show the error bubble again. |
| 211 // Calling ShowBubble() immediately from here does not always work because | 211 // Calling ShowBubble() immediately from here does not always work because |
| 212 // the old browser window may still have focus. | 212 // the old browser window may still have focus. |
| 213 // Multiple posted ShowBubble() calls are fine since the first successful | 213 // Multiple posted ShowBubble() calls are fine since the first successful |
| 214 // one will invalidate all the weak pointers. | 214 // one will invalidate all the weak pointers. |
| 215 // Note that ShowBubble() will display the bubble in the last active browser | 215 // Note that ShowBubble() will display the bubble in the last active browser |
| 216 // (which may not be |browser| at the moment ShowBubble() is executed). | 216 // (which may not be |browser| at the moment ShowBubble() is executed). |
| 217 BrowserThread::PostTask( | 217 BrowserThread::PostTask( |
| 218 BrowserThread::UI, FROM_HERE, | 218 BrowserThread::UI, FROM_HERE, |
| 219 base::Bind(&SettingsChangeGlobalError::ShowBubble, | 219 base::Bind(&SettingsChangeGlobalError::ShowBubble, |
| 220 weak_factory_.GetWeakPtr())); | 220 weak_factory_.GetWeakPtr(), |
| 221 browser->host_desktop_type())); |
| 221 } | 222 } |
| 222 } | 223 } |
| 223 | 224 |
| 224 void SettingsChangeGlobalError::ShowBubbleInBrowser(Browser* browser) { | 225 void SettingsChangeGlobalError::ShowBubbleInBrowser(Browser* browser) { |
| 225 show_on_browser_activation_ = false; | 226 show_on_browser_activation_ = false; |
| 226 // Cancel any previously posted tasks so that the global error | 227 // Cancel any previously posted tasks so that the global error |
| 227 // does not get removed on timeout while still showing the bubble. | 228 // does not get removed on timeout while still showing the bubble. |
| 228 weak_factory_.InvalidateWeakPtrs(); | 229 weak_factory_.InvalidateWeakPtrs(); |
| 229 ShowBubbleView(browser); | 230 ShowBubbleView(browser); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void SettingsChangeGlobalError::OnInactiveTimeout() { | 233 void SettingsChangeGlobalError::OnInactiveTimeout() { |
| 233 delegate_->OnDecisionTimeout(this); | 234 delegate_->OnDecisionTimeout(this); |
| 234 RemoveFromProfile(); | 235 RemoveFromProfile(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 } // namespace protector | 238 } // namespace protector |
| OLD | NEW |