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..efd7aebf5f06a18d2e8afbcd7d32a20f7be6bef9 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; |
| + } |
| + } |
| + // Discard the tab. |
| + memory::TabManager* tab_manager = g_browser_process->GetTabManager(); |
| + if (!tab_manager) |
|
Devlin
2016/07/19 22:49:12
When can this be null?
Anderson Silva
2016/07/20 16:24:01
It's null on non-supported platforms (Android, iOS
|
| + return false; |
| + contents = tab_manager->DiscardTabByExtension(contents); |
| + |
| + if (!has_callback()) |
|
Devlin
2016/07/19 22:49:11
I understand the motivation for this, but if/when
Anderson Silva
2016/07/20 16:24:01
Done.
|
| + 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). |
| + bool success = !!contents; |
| + 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 |