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

Side by Side Diff: chrome/browser/ui/tabs/pinned_tab_service.cc

Issue 10800031: Remove details from BROWSER_CLOSING and BROWSER_CLOSED notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated logic / comment for pinned tabs 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/tabs/pinned_tab_service.h" 5 #include "chrome/browser/ui/tabs/pinned_tab_service.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 10 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 13
14 static bool IsLastNormalBrowser(Browser* browser) { 14 namespace {
15
16 bool IsOnlyNormalBrowser(Browser* browser) {
15 for (BrowserList::const_iterator i = BrowserList::begin(); 17 for (BrowserList::const_iterator i = BrowserList::begin();
16 i != BrowserList::end(); ++i) { 18 i != BrowserList::end(); ++i) {
17 if (*i != browser && (*i)->is_type_tabbed() && 19 if (*i != browser && (*i)->is_type_tabbed() &&
18 (*i)->profile() == browser->profile()) { 20 (*i)->profile() == browser->profile()) {
19 return false; 21 return false;
20 } 22 }
21 } 23 }
22 return true; 24 return true;
23 } 25 }
24 26
27 } // namespace
28
25 PinnedTabService::PinnedTabService(Profile* profile) 29 PinnedTabService::PinnedTabService(Profile* profile)
26 : profile_(profile), 30 : profile_(profile),
27 got_exiting_(false), 31 save_pinned_tabs_(true),
28 has_normal_browser_(false) { 32 has_normal_browser_(false) {
29 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, 33 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
30 content::NotificationService::AllBrowserContextsAndSources()); 34 content::NotificationService::AllBrowserContextsAndSources());
31 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, 35 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING,
32 content::NotificationService::AllSources()); 36 content::NotificationService::AllSources());
33 registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, 37 registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
34 content::NotificationService::AllSources()); 38 content::NotificationService::AllSources());
35 } 39 }
36 40
37 void PinnedTabService::Observe(int type, 41 void PinnedTabService::Observe(int type,
38 const content::NotificationSource& source, 42 const content::NotificationSource& source,
39 const content::NotificationDetails& details) { 43 const content::NotificationDetails& details) {
40 if (got_exiting_) 44 // Saving of tabs happens when saving is enabled, and when either the user
41 return; 45 // exits the application or closes the last browser window.
42 46 // Saving is disabled when the user exits the application to prevent the
47 // pin state of all the open browsers being overwritten by the state of the
48 // last browser window to close.
49 // Saving is re-enabled when the first browser window is opened again. So,
50 // if background mode or a packaged app keeps the process alive after a user
51 // exit, when a new window is opened pinned tab saving is restored.
52 // Note, cancelling a shutdown (via onbeforeunload) will not re-enable pinned
53 // tab saving, to prevent this situation:
54 // * two windows are open, one with pinned tabs
55 // * user exits
56 // * pinned tabs are saved
57 // * window with pinned tabs is closed
58 // * other window blocks close with onbeforeunload
59 // * user saves work, etc. then closes the window
60 // * pinned tabs are saved, without the window with the pinned tabs,
61 // over-writing the correct state.
sky 2012/07/20 16:06:40 The problem with this, and why I suggested NOTIFIC
benwells 2012/07/23 01:22:12 Yep, they won't always exit immediately. I've put
43 switch (type) { 62 switch (type) {
44 case chrome::NOTIFICATION_BROWSER_OPENED: { 63 case chrome::NOTIFICATION_BROWSER_OPENED: {
45 Browser* browser = content::Source<Browser>(source).ptr(); 64 Browser* browser = content::Source<Browser>(source).ptr();
46 if (!has_normal_browser_ && browser->is_type_tabbed() && 65 if (!has_normal_browser_ && browser->is_type_tabbed() &&
47 browser->profile() == profile_) { 66 browser->profile() == profile_) {
48 has_normal_browser_ = true; 67 has_normal_browser_ = true;
49 } 68 }
69 if (IsOnlyNormalBrowser(browser))
70 save_pinned_tabs_ = true;
50 break; 71 break;
51 } 72 }
52 73
53 case chrome::NOTIFICATION_BROWSER_CLOSING: { 74 case chrome::NOTIFICATION_BROWSER_CLOSING: {
54 Browser* browser = content::Source<Browser>(source).ptr(); 75 Browser* browser = content::Source<Browser>(source).ptr();
55 if (has_normal_browser_ && browser->profile() == profile_) { 76 if (has_normal_browser_ && save_pinned_tabs_ &&
56 if (*(content::Details<bool>(details)).ptr()) { 77 browser->profile() == profile_) {
57 GotExit(); 78 if (IsOnlyNormalBrowser(browser)) {
58 } else if (IsLastNormalBrowser(browser)) {
59 has_normal_browser_ = false; 79 has_normal_browser_ = false;
60 PinnedTabCodec::WritePinnedTabs(profile_); 80 PinnedTabCodec::WritePinnedTabs(profile_);
61 } 81 }
62 } 82 }
63 break; 83 break;
64 } 84 }
65 85
66 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { 86 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: {
67 if (has_normal_browser_) 87 if (has_normal_browser_ && save_pinned_tabs_) {
68 GotExit(); 88 PinnedTabCodec::WritePinnedTabs(profile_);
89 save_pinned_tabs_ = false;
90 }
69 break; 91 break;
70 } 92 }
71 93
72 default: 94 default:
73 NOTREACHED(); 95 NOTREACHED();
74 } 96 }
75 } 97 }
76
77 void PinnedTabService::GotExit() {
78 DCHECK(!got_exiting_);
79 got_exiting_ = true;
80 PinnedTabCodec::WritePinnedTabs(profile_);
81 }
OLDNEW
« 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