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

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: testcases 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..ff8e9390c82c74ea1fea43cc1857cd93b0762bcf 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -2168,4 +2168,39 @@ 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 invokes discard function in TabManager with null web_contents
Georges Khalil 2016/07/19 19:39:45 nit: invokes -> invoke
Anderson Silva 2016/07/19 20:28:42 Done.
+ // 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_))
Georges Khalil 2016/07/19 19:39:45 nit: braces.
Anderson Silva 2016/07/19 20:28:42 Done.
+ return false;
+ }
+
+ memory::TabManager* tab_manager = g_browser_process->GetTabManager();
+ if (!tab_manager)
+ return false;
+
+ bool success = true;
+ contents = tab_manager->DiscardTabByExtension(contents);
+ if (!contents)
+ success = false;
Georges Khalil 2016/07/19 19:39:45 This can be a single line: bool success = !!conte
Anderson Silva 2016/07/19 20:28:42 Done.
+
+ if (!has_callback())
+ return true;
+
+ std::unique_ptr<api::tabs::Tab> tab(new api::tabs::Tab);
Georges Khalil 2016/07/19 19:39:45 A small comment would be good here, to explain how
Anderson Silva 2016/07/19 20:28:42 Done.
+ 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