Chromium Code Reviews| Index: chrome/browser/ui/tabs/pinned_tab_service.cc |
| diff --git a/chrome/browser/ui/tabs/pinned_tab_service.cc b/chrome/browser/ui/tabs/pinned_tab_service.cc |
| index 5f56a5ecf9a5c511250eb07a09b41f2f46188a2a..4e4223e8e9c0eb1cfccc826e40293d023d141f20 100644 |
| --- a/chrome/browser/ui/tabs/pinned_tab_service.cc |
| +++ b/chrome/browser/ui/tabs/pinned_tab_service.cc |
| @@ -30,17 +30,19 @@ bool IsOnlyNormalBrowser(Browser* browser) { |
| PinnedTabService::PinnedTabService(Profile* profile) |
| : profile_(profile), |
| save_pinned_tabs_(true), |
| - has_normal_browser_(false) { |
| + has_normal_browser_(false), |
| + browser_list_observer_(this) { |
| registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| content::NotificationService::AllBrowserContextsAndSources()); |
| - registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
| - content::NotificationService::AllSources()); |
| registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
| content::NotificationService::AllSources()); |
| registrar_.Add(this, chrome::NOTIFICATION_TAB_ADDED, |
| content::NotificationService::AllSources()); |
| + browser_list_observer_.Add(BrowserList::GetInstance()); |
| } |
| +PinnedTabService::~PinnedTabService() {} |
| + |
| void PinnedTabService::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| @@ -77,18 +79,6 @@ void PinnedTabService::Observe(int type, |
| break; |
| } |
| - case chrome::NOTIFICATION_BROWSER_CLOSING: { |
| - Browser* browser = content::Source<Browser>(source).ptr(); |
| - if (has_normal_browser_ && save_pinned_tabs_ && |
| - browser->profile() == profile_) { |
| - if (IsOnlyNormalBrowser(browser)) { |
| - has_normal_browser_ = false; |
| - PinnedTabCodec::WritePinnedTabs(profile_); |
| - } |
| - } |
| - break; |
| - } |
| - |
| case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { |
| if (has_normal_browser_ && save_pinned_tabs_) { |
| PinnedTabCodec::WritePinnedTabs(profile_); |
| @@ -101,3 +91,13 @@ void PinnedTabService::Observe(int type, |
| NOTREACHED(); |
| } |
| } |
| + |
| +void PinnedTabService::OnBrowserCloseStarted(Browser* browser) { |
| + if (has_normal_browser_ && save_pinned_tabs_ && |
| + browser->profile() == profile_) { |
| + if (IsOnlyNormalBrowser(browser)) { |
|
sky
2017/05/09 17:19:28
Combine conditionals.
Alexey Seren
2017/05/10 10:25:30
Acknowledged.
|
| + has_normal_browser_ = false; |
| + PinnedTabCodec::WritePinnedTabs(profile_); |
| + } |
| + } |
| +} |