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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 2153943002: Implementing TabManager extensions API Discard Function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: first round of comments fixed Created 4 years, 5 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/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

Powered by Google App Engine
This is Rietveld 408576698