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

Side by Side Diff: chrome/browser/sessions/session_service.cc

Issue 12114034: Swap BrowserList::const_iterator for the multi-desktop aware BrowserIterator in many scenarios. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/sessions/session_service.h" 5 #include "chrome/browser/sessions/session_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/pickle.h" 18 #include "base/pickle.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "chrome/browser/extensions/tab_helper.h" 20 #include "chrome/browser/extensions/tab_helper.h"
21 #include "chrome/browser/prefs/session_startup_pref.h" 21 #include "chrome/browser/prefs/session_startup_pref.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/sessions/session_backend.h" 23 #include "chrome/browser/sessions/session_backend.h"
24 #include "chrome/browser/sessions/session_command.h" 24 #include "chrome/browser/sessions/session_command.h"
25 #include "chrome/browser/sessions/session_restore.h" 25 #include "chrome/browser/sessions/session_restore.h"
26 #include "chrome/browser/sessions/session_tab_helper.h" 26 #include "chrome/browser/sessions/session_tab_helper.h"
27 #include "chrome/browser/sessions/session_types.h" 27 #include "chrome/browser/sessions/session_types.h"
28 #include "chrome/browser/ui/browser_iterator.h"
28 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_tabstrip.h" 30 #include "chrome/browser/ui/browser_tabstrip.h"
30 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/host_desktop.h" 32 #include "chrome/browser/ui/host_desktop.h"
32 #include "chrome/browser/ui/startup/startup_browser_creator.h" 33 #include "chrome/browser/ui/startup/startup_browser_creator.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/chrome_notification_types.h" 35 #include "chrome/common/chrome_notification_types.h"
35 #include "chrome/common/extensions/extension.h" 36 #include "chrome/common/extensions/extension.h"
36 #include "chrome/common/startup_metric_utils.h" 37 #include "chrome/common/startup_metric_utils.h"
37 #include "content/public/browser/navigation_details.h" 38 #include "content/public/browser/navigation_details.h"
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 commands->push_back( 1380 commands->push_back(
1380 CreateSetSelectedTabInWindow(browser->session_id(), 1381 CreateSetSelectedTabInWindow(browser->session_id(),
1381 browser->tab_strip_model()->active_index())); 1382 browser->tab_strip_model()->active_index()));
1382 } 1383 }
1383 1384
1384 void SessionService::BuildCommandsFromBrowsers( 1385 void SessionService::BuildCommandsFromBrowsers(
1385 std::vector<SessionCommand*>* commands, 1386 std::vector<SessionCommand*>* commands,
1386 IdToRange* tab_to_available_range, 1387 IdToRange* tab_to_available_range,
1387 std::set<SessionID::id_type>* windows_to_track) { 1388 std::set<SessionID::id_type>* windows_to_track) {
1388 DCHECK(commands); 1389 DCHECK(commands);
1389 for (BrowserList::const_iterator i = BrowserList::begin(); 1390 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1390 i != BrowserList::end(); ++i) { 1391 Browser* browser = *it;
1391 Browser* browser = *i;
1392 // Make sure the browser has tabs and a window. Browser's destructor 1392 // Make sure the browser has tabs and a window. Browser's destructor
1393 // removes itself from the BrowserList. When a browser is closed the 1393 // removes itself from the BrowserList. When a browser is closed the
1394 // destructor is not necessarily run immediately. This means it's possible 1394 // destructor is not necessarily run immediately. This means it's possible
1395 // for us to get a handle to a browser that is about to be removed. If 1395 // for us to get a handle to a browser that is about to be removed. If
1396 // the tab count is 0 or the window is NULL, the browser is about to be 1396 // the tab count is 0 or the window is NULL, the browser is about to be
1397 // deleted, so we ignore it. 1397 // deleted, so we ignore it.
1398 if (ShouldTrackBrowser(browser) && browser->tab_strip_model()->count() && 1398 if (ShouldTrackBrowser(browser) && browser->tab_strip_model()->count() &&
1399 browser->window()) { 1399 browser->window()) {
1400 BuildCommandsForBrowser(browser, commands, tab_to_available_range, 1400 BuildCommandsForBrowser(browser, commands, tab_to_available_range,
1401 windows_to_track); 1401 windows_to_track);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 pending_window_close_ids_.clear(); 1503 pending_window_close_ids_.clear();
1504 } 1504 }
1505 1505
1506 bool SessionService::IsOnlyOneTabLeft() const { 1506 bool SessionService::IsOnlyOneTabLeft() const {
1507 if (!profile()) { 1507 if (!profile()) {
1508 // We're testing, always return false. 1508 // We're testing, always return false.
1509 return false; 1509 return false;
1510 } 1510 }
1511 1511
1512 int window_count = 0; 1512 int window_count = 0;
1513 for (BrowserList::const_iterator i = BrowserList::begin(); 1513 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1514 i != BrowserList::end(); ++i) { 1514 Browser* browser = *it;
1515 Browser* browser = *i;
1516 const SessionID::id_type window_id = browser->session_id().id(); 1515 const SessionID::id_type window_id = browser->session_id().id();
1517 if (ShouldTrackBrowser(browser) && 1516 if (ShouldTrackBrowser(browser) &&
1518 window_closing_ids_.find(window_id) == window_closing_ids_.end()) { 1517 window_closing_ids_.find(window_id) == window_closing_ids_.end()) {
1519 if (++window_count > 1) 1518 if (++window_count > 1)
1520 return false; 1519 return false;
1521 // By the time this is invoked the tab has been removed. As such, we use 1520 // By the time this is invoked the tab has been removed. As such, we use
1522 // > 0 here rather than > 1. 1521 // > 0 here rather than > 1.
1523 if ((*i)->tab_strip_model()->count() > 0) 1522 if (browser->tab_strip_model()->count() > 0)
1524 return false; 1523 return false;
1525 } 1524 }
1526 } 1525 }
1527 return true; 1526 return true;
1528 } 1527 }
1529 1528
1530 bool SessionService::HasOpenTrackableBrowsers( 1529 bool SessionService::HasOpenTrackableBrowsers(
1531 const SessionID& window_id) const { 1530 const SessionID& window_id) const {
1532 if (!profile()) { 1531 if (!profile()) {
1533 // We're testing, always return false. 1532 // We're testing, always return false.
1534 return true; 1533 return true;
1535 } 1534 }
1536 1535
1537 for (BrowserList::const_iterator i = BrowserList::begin(); 1536 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1538 i != BrowserList::end(); ++i) { 1537 Browser* browser = *it;
1539 Browser* browser = *i;
1540 const SessionID::id_type browser_id = browser->session_id().id(); 1538 const SessionID::id_type browser_id = browser->session_id().id();
1541 if (browser_id != window_id.id() && 1539 if (browser_id != window_id.id() &&
1542 window_closing_ids_.find(browser_id) == window_closing_ids_.end() && 1540 window_closing_ids_.find(browser_id) == window_closing_ids_.end() &&
1543 ShouldTrackBrowser(browser)) { 1541 ShouldTrackBrowser(browser)) {
1544 return true; 1542 return true;
1545 } 1543 }
1546 } 1544 }
1547 return false; 1545 return false;
1548 } 1546 }
1549 1547
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 contents->GetController().GetDefaultSessionStorageNamespace(); 1759 contents->GetController().GetDefaultSessionStorageNamespace();
1762 session_storage_namespace->SetShouldPersist(false); 1760 session_storage_namespace->SetShouldPersist(false);
1763 SessionTabHelper* session_tab_helper = 1761 SessionTabHelper* session_tab_helper =
1764 SessionTabHelper::FromWebContents(contents); 1762 SessionTabHelper::FromWebContents(contents);
1765 TabClosed(session_tab_helper->window_id(), 1763 TabClosed(session_tab_helper->window_id(),
1766 session_tab_helper->session_id(), 1764 session_tab_helper->session_id(),
1767 contents->GetClosedByUserGesture()); 1765 contents->GetClosedByUserGesture());
1768 RecordSessionUpdateHistogramData(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 1766 RecordSessionUpdateHistogramData(content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1769 &last_updated_tab_closed_time_); 1767 &last_updated_tab_closed_time_);
1770 } 1768 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698