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

Unified Diff: chrome/browser/extensions/api/sessions/sessions_api.cc

Issue 2200993004: Make TabRestoreService::Entry noncopyable and fix up surrounding code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-test-cleanup
Patch Set: Add back NOTREACHED() and a return for gcc Created 4 years, 4 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
Index: chrome/browser/extensions/api/sessions/sessions_api.cc
diff --git a/chrome/browser/extensions/api/sessions/sessions_api.cc b/chrome/browser/extensions/api/sessions/sessions_api.cc
index e9e9d73158bf9ef14805247e08c4084efe120082..c44340877f36847a13a45a5421bab623365013a9 100644
--- a/chrome/browser/extensions/api/sessions/sessions_api.cc
+++ b/chrome/browser/extensions/api/sessions/sessions_api.cc
@@ -140,14 +140,14 @@ std::unique_ptr<api::sessions::Session> CreateSessionModelHelper(
return session_struct;
}
-bool is_tab_entry(const sessions::TabRestoreService::Entry* entry) {
- return entry->type == sessions::TabRestoreService::TAB;
-}
+namespace {
-bool is_window_entry(const sessions::TabRestoreService::Entry* entry) {
- return entry->type == sessions::TabRestoreService::WINDOW;
+bool is_window_entry(const sessions::TabRestoreService::Entry& entry) {
+ return entry.type() == sessions::TabRestoreService::WINDOW;
}
+} // namespace
+
tabs::Tab SessionsGetRecentlyClosedFunction::CreateTabModel(
const sessions::TabRestoreService::Tab& tab,
int session_id,
@@ -169,7 +169,7 @@ SessionsGetRecentlyClosedFunction::CreateWindowModel(
std::unique_ptr<std::vector<tabs::Tab>> tabs(new std::vector<tabs::Tab>());
for (size_t i = 0; i < window.tabs.size(); ++i) {
- tabs->push_back(CreateTabModel(window.tabs[i], window.tabs[i].id,
+ tabs->push_back(CreateTabModel(*window.tabs[i], window.tabs[i]->id,
window.selected_tab_index));
}
@@ -180,24 +180,24 @@ SessionsGetRecentlyClosedFunction::CreateWindowModel(
std::unique_ptr<api::sessions::Session>
SessionsGetRecentlyClosedFunction::CreateSessionModel(
- const sessions::TabRestoreService::Entry* entry) {
+ const sessions::TabRestoreService::Entry& entry) {
std::unique_ptr<tabs::Tab> tab;
std::unique_ptr<windows::Window> window;
- switch (entry->type) {
+ switch (entry.type()) {
case sessions::TabRestoreService::TAB:
tab.reset(new tabs::Tab(CreateTabModel(
- *static_cast<const sessions::TabRestoreService::Tab*>(entry),
- entry->id, -1)));
+ static_cast<const sessions::TabRestoreService::Tab&>(entry),
+ entry.id, -1)));
break;
case sessions::TabRestoreService::WINDOW:
window = CreateWindowModel(
- *static_cast<const sessions::TabRestoreService::Window*>(entry),
- entry->id);
+ static_cast<const sessions::TabRestoreService::Window&>(entry),
+ entry.id);
break;
default:
NOTREACHED();
}
- return CreateSessionModelHelper(entry->timestamp.ToTimeT(), std::move(tab),
+ return CreateSessionModelHelper(entry.timestamp.ToTimeT(), std::move(tab),
std::move(window));
}
@@ -227,9 +227,8 @@ bool SessionsGetRecentlyClosedFunction::RunSync() {
// List of entries. They are ordered from most to least recent.
// We prune the list to contain max 25 entries at any time and removes
// uninteresting entries.
- for (const sessions::TabRestoreService::Entry* entry :
- tab_restore_service->entries()) {
- result.push_back(std::move(*CreateSessionModel(entry)));
+ for (const auto &entry : tab_restore_service->entries()) {
sky 2016/08/02 23:12:30 'auto &' -> 'auto&'
Sidney San Martín 2016/08/03 14:35:31 Done. Sorry about these, I ran `git cl format` thi
+ result.push_back(std::move(*CreateSessionModel(*entry)));
}
results_ = GetRecentlyClosed::Results::Create(result);
@@ -437,14 +436,15 @@ bool SessionsRestoreFunction::SetResultRestoredWindow(int window_id) {
bool SessionsRestoreFunction::RestoreMostRecentlyClosed(Browser* browser) {
sessions::TabRestoreService* tab_restore_service =
TabRestoreServiceFactory::GetForProfile(GetProfile());
- sessions::TabRestoreService::Entries entries = tab_restore_service->entries();
+ const sessions::TabRestoreService::Entries& entries =
+ tab_restore_service->entries();
if (entries.empty()) {
SetError(kNoRecentlyClosedSessionsError);
return false;
}
- bool is_window = is_window_entry(entries.front());
+ bool is_window = is_window_entry(*entries.front());
sessions::LiveTabContext* context =
BrowserLiveTabContext::FindContextForWebContents(
browser->tab_strip_model()->GetActiveWebContents());
@@ -467,7 +467,8 @@ bool SessionsRestoreFunction::RestoreLocalSession(const SessionId& session_id,
Browser* browser) {
sessions::TabRestoreService* tab_restore_service =
TabRestoreServiceFactory::GetForProfile(GetProfile());
- sessions::TabRestoreService::Entries entries = tab_restore_service->entries();
+ const sessions::TabRestoreService::Entries& entries =
+ tab_restore_service->entries();
if (entries.empty()) {
SetInvalidIdError(session_id.ToString());
@@ -476,12 +477,11 @@ bool SessionsRestoreFunction::RestoreLocalSession(const SessionId& session_id,
// Check if the recently closed list contains an entry with the provided id.
bool is_window = false;
- for (sessions::TabRestoreService::Entries::iterator it = entries.begin();
- it != entries.end(); ++it) {
- if ((*it)->id == session_id.id()) {
- // The only time a full window is being restored is if the entry ID
+ for (const auto& entry : entries) {
+ if (entry->id == session_id.id()) {
+ // A full window is being restored only if the entry ID
// matches the provided ID and the entry type is Window.
- is_window = is_window_entry(*it);
+ is_window = is_window_entry(*entry);
break;
}
}

Powered by Google App Engine
This is Rietveld 408576698