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

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: nit on function description 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
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..067bff6104f81434fd93949c61bd2036fa2e2d54 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -2168,4 +2168,37 @@ 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 a Tab object,
+ // then a default object is created and replaced with the real
+ // tab in case of success (contents is not null).
+ std::unique_ptr<tabs::Tab> tab(new tabs::Tab);
Devlin 2016/07/22 18:39:19 This won't be undefined, then, it'll be a tab obje
Anderson Silva 2016/07/22 20:18:25 Yes, it's a tab object. I tested in an extension a
Devlin 2016/07/22 20:20:53 ^^ This. :) Marking the field as optional and the
Anderson Silva 2016/07/22 22:50:14 Done. Empty unique_ptr crashes but no arguments wo
+ if (contents)
+ tab = ExtensionTabUtil::CreateTabObject(contents);
+ return RespondNow(ArgumentList(tabs::Discard::Results::Create(*tab)));
+}
+
+TabsDiscardFunction::TabsDiscardFunction() {}
+TabsDiscardFunction::~TabsDiscardFunction() {}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698