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

Unified Diff: chrome/browser/ui/tabs/pinned_tab_service.cc

Issue 10829007: Revert 148281 - Remove details from BROWSER_CLOSING and BROWSER_CLOSED notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/tabs/pinned_tab_service.h ('k') | chrome/common/automation_messages_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/tabs/pinned_tab_service.cc
===================================================================
--- chrome/browser/ui/tabs/pinned_tab_service.cc (revision 148288)
+++ chrome/browser/ui/tabs/pinned_tab_service.cc (working copy)
@@ -11,9 +11,7 @@
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_service.h"
-namespace {
-
-bool IsOnlyNormalBrowser(Browser* browser) {
+static bool IsLastNormalBrowser(Browser* browser) {
for (BrowserList::const_iterator i = BrowserList::begin();
i != BrowserList::end(); ++i) {
if (*i != browser && (*i)->is_type_tabbed() &&
@@ -24,11 +22,9 @@
return true;
}
-} // namespace
-
PinnedTabService::PinnedTabService(Profile* profile)
: profile_(profile),
- save_pinned_tabs_(true),
+ got_exiting_(false),
has_normal_browser_(false) {
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllBrowserContextsAndSources());
@@ -36,30 +32,14 @@
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());
}
void PinnedTabService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- // Saving of tabs happens when saving is enabled, and when either the user
- // exits the application or closes the last browser window.
- // Saving is disabled when the user exits the application to prevent the
- // pin state of all the open browsers being overwritten by the state of the
- // last browser window to close.
- // Saving is re-enabled when a browser window or tab is opened again.
- // Note, cancelling a shutdown (via onbeforeunload) will not re-enable pinned
- // tab saving immediately, to prevent the following situation:
- // * two windows are open, one with pinned tabs
- // * user exits
- // * pinned tabs are saved
- // * window with pinned tabs is closed
- // * other window blocks close with onbeforeunload
- // * user saves work, etc. then closes the window
- // * pinned tabs are saved, without the window with the pinned tabs,
- // over-writing the correct state.
- // Saving is re-enabled if a new tab or window is opened.
+ if (got_exiting_)
+ return;
+
switch (type) {
case chrome::NOTIFICATION_BROWSER_OPENED: {
Browser* browser = content::Source<Browser>(source).ptr();
@@ -67,20 +47,15 @@
browser->profile() == profile_) {
has_normal_browser_ = true;
}
- save_pinned_tabs_ = true;
break;
}
- case chrome::NOTIFICATION_TAB_ADDED: {
- save_pinned_tabs_ = true;
- 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)) {
+ if (has_normal_browser_ && browser->profile() == profile_) {
+ if (*(content::Details<bool>(details)).ptr()) {
+ GotExit();
+ } else if (IsLastNormalBrowser(browser)) {
has_normal_browser_ = false;
PinnedTabCodec::WritePinnedTabs(profile_);
}
@@ -89,10 +64,8 @@
}
case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: {
- if (has_normal_browser_ && save_pinned_tabs_) {
- PinnedTabCodec::WritePinnedTabs(profile_);
- save_pinned_tabs_ = false;
- }
+ if (has_normal_browser_)
+ GotExit();
break;
}
@@ -100,3 +73,9 @@
NOTREACHED();
}
}
+
+void PinnedTabService::GotExit() {
+ DCHECK(!got_exiting_);
+ got_exiting_ = true;
+ PinnedTabCodec::WritePinnedTabs(profile_);
+}
« no previous file with comments | « chrome/browser/ui/tabs/pinned_tab_service.h ('k') | chrome/common/automation_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698