Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_common_utils.h" | 5 #include "chrome/browser/sessions/session_common_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <string> | |
| 9 | |
| 7 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 11 #include "components/sessions/core/session_types.h" | |
| 8 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 9 | 13 |
| 10 bool ShouldTrackURLForRestore(const GURL& url) { | 14 bool ShouldTrackURLForRestore(const GURL& url) { |
| 11 return url.is_valid() && | 15 return url.is_valid() && |
| 12 !(url.SchemeIs(content::kChromeUIScheme) && | 16 !(url.SchemeIs(content::kChromeUIScheme) && |
| 13 (url.host() == chrome::kChromeUIQuitHost || | 17 (url.host() == chrome::kChromeUIQuitHost || |
| 14 url.host() == chrome::kChromeUIRestartHost)); | 18 url.host() == chrome::kChromeUIRestartHost)); |
| 15 } | 19 } |
| 20 | |
| 21 int GetSelectedIndexFromTab(const sessions::SessionTab& tab) { | |
| 22 int selected_index = tab.current_navigation_index; | |
| 23 selected_index = std::max( | |
|
sky
2016/11/11 00:32:17
optional: avoid multiple statements and do the ass
zmin
2016/11/11 22:54:01
Done.
| |
| 24 0, | |
| 25 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); | |
|
sky
2016/11/11 00:32:17
DCHECK !tab.navigations.empty() ? I realize the ch
zmin
2016/11/11 22:54:01
Done.
| |
| 26 | |
| 27 // After user sign out, Chrome may navigate to the setting page from the | |
| 28 // sign out page asynchronously. The browser may be closed before the | |
| 29 // navigation callback finished. | |
| 30 std::string setting_page_url = std::string(chrome::kChromeUISettingsURL); | |
| 31 std::string sign_out_page_url = | |
| 32 setting_page_url + std::string(chrome::kSignOutSubPage); | |
| 33 if (selected_index > 0 && | |
| 34 tab.navigations[selected_index].virtual_url().spec() == | |
| 35 sign_out_page_url && | |
| 36 tab.navigations[selected_index - 1].virtual_url().spec() == | |
| 37 setting_page_url) { | |
| 38 selected_index -= 1; | |
|
sky
2016/11/11 00:32:17
optional: I would early return at this point, e.g.
zmin
2016/11/11 22:54:01
Done.
| |
| 39 } | |
| 40 | |
| 41 return selected_index; | |
| 42 } | |
| OLD | NEW |