Chromium Code Reviews| 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..88f675678886163df1a0e37390e24343292bb3b7 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, |
|
sky
2016/08/04 16:34:38
While you're cleaning up it seems like session_id
Sidney San Martín
2016/08/09 04:10:52
Done! I also made a couple of other small changes
|
| @@ -167,11 +167,9 @@ SessionsGetRecentlyClosedFunction::CreateWindowModel( |
| int session_id) { |
| DCHECK(!window.tabs.empty()); |
| - 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, |
| - window.selected_tab_index)); |
| - } |
| + auto tabs = base::MakeUnique<std::vector<tabs::Tab>>(); |
| + for (const auto& tab : window.tabs) |
| + tabs->push_back(CreateTabModel(*tab, tab->id, window.selected_tab_index)); |
| return CreateWindowModelHelper(std::move(tabs), base::IntToString(session_id), |
| windows::WINDOW_TYPE_NORMAL, |
| @@ -180,24 +178,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 +225,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()) { |
| + result.push_back(std::move(*CreateSessionModel(*entry))); |
| } |
| results_ = GetRecentlyClosed::Results::Create(result); |
| @@ -437,14 +434,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 +465,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 +475,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; |
| } |
| } |