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

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: changed returned tab to optional plus tests 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..8c44c23e1e07fd0de241324a0cb2e4358f2f4bc0 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -2168,4 +2168,38 @@ bool TabsGetZoomSettingsFunction::RunAsync() {
return true;
}
+ExtensionFunction::ResponseAction TabsDiscardFunction::Run() {
+ std::unique_ptr<tabs::Discard::Params> params(
+ tabs::Discard::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ WebContents* contents = nullptr;
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ // 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, profile, include_incognito(), nullptr, nullptr,
+ &contents, nullptr, &error_)) {
+ return RespondNow(Error(error_));
+ }
+ }
+ // Discard the tab.
+ contents =
+ g_browser_process->GetTabManager()->DiscardTabByExtension(contents);
+
+ // Create result to be returned. We have to return the Tab object
+ // in case of success (contents is not null) and undefined otherwise.
+ if (contents) {
+ return RespondNow(ArgumentList(tabs::Discard::Results::Create(
+ *ExtensionTabUtil::CreateTabObject(contents))));
+ } else {
Devlin 2016/07/25 15:48:55 nit: no need for an else {} after a return.
Anderson Silva 2016/07/25 17:42:00 Done.
+ return RespondNow(NoArguments());
+ }
+}
+
+TabsDiscardFunction::TabsDiscardFunction() {}
+TabsDiscardFunction::~TabsDiscardFunction() {}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698