Chromium Code Reviews| Index: chrome/browser/extensions/api/tabs/tabs_api.cc |
| diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc |
| index 082822b843de360c5af776ec9653ec3abb9dad99..46b3e317d090d7e502b5e0be6deb6e1d9567e883 100644 |
| --- a/chrome/browser/extensions/api/tabs/tabs_api.cc |
| +++ b/chrome/browser/extensions/api/tabs/tabs_api.cc |
| @@ -2168,4 +2168,41 @@ bool TabsGetZoomSettingsFunction::RunAsync() { |
| return true; |
| } |
| +bool TabsDiscardFunction::RunSync() { |
| + std::unique_ptr<tabs::Discard::Params> params( |
| + tabs::Discard::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params); |
| + |
| + WebContents* contents = nullptr; |
| + // If |tab_id| is given, find the web_contents respective to it. |
| + // Otherwise invoke discard function in TabManager with null web_contents |
| + // that will discard the least important tab. |
| + if (params->tab_id) { |
| + int tab_id = *params->tab_id; |
| + if (!GetTabById(tab_id, GetProfile(), include_incognito(), nullptr, nullptr, |
| + &contents, nullptr, &error_)) { |
| + return false; |
| + } |
| + } |
| + // Discards the tab. |
|
Georges Khalil
2016/07/19 20:35:40
nit: discards -> discard.
Anderson Silva
2016/07/19 20:57:35
Done.
|
| + memory::TabManager* tab_manager = g_browser_process->GetTabManager(); |
| + if (!tab_manager) |
| + return false; |
| + contents = tab_manager->DiscardTabByExtension(contents); |
| + bool success = !!contents; |
|
Georges Khalil
2016/07/19 20:35:40
nit: move this lower (to where it's needed).
Anderson Silva
2016/07/19 20:57:35
Done.
|
| + |
| + if (!has_callback()) |
| + return true; |
| + |
| + // Create result to be returned if callback is present. |
| + // We have to return a Tab object and the success boolean, so create a |
| + // default object and replace it with the real tab in case of success |
| + // (contents is not null). |
| + std::unique_ptr<api::tabs::Tab> tab(new api::tabs::Tab); |
| + if (success) |
| + tab = ExtensionTabUtil::CreateTabObject(contents); |
| + results_ = api::tabs::Discard::Results::Create(*tab, success); |
| + return true; |
| +} |
| + |
| } // namespace extensions |