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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
(...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 api::tabs::ZoomSettings zoom_settings; 2161 api::tabs::ZoomSettings zoom_settings;
2162 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 2162 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
2163 zoom_settings.default_zoom_factor.reset(new double( 2163 zoom_settings.default_zoom_factor.reset(new double(
2164 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 2164 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
2165 2165
2166 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 2166 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2167 SendResponse(true); 2167 SendResponse(true);
2168 return true; 2168 return true;
2169 } 2169 }
2170 2170
2171 ExtensionFunction::ResponseAction TabsDiscardFunction::Run() {
2172 std::unique_ptr<tabs::Discard::Params> params(
2173 tabs::Discard::Params::Create(*args_));
2174 EXTENSION_FUNCTION_VALIDATE(params);
2175
2176 WebContents* contents = nullptr;
2177 Profile* profile = Profile::FromBrowserContext(browser_context());
2178 // If |tab_id| is given, find the web_contents respective to it.
2179 // Otherwise invoke discard function in TabManager with null web_contents
2180 // that will discard the least important tab.
2181 if (params->tab_id) {
2182 int tab_id = *params->tab_id;
2183 if (!GetTabById(tab_id, profile, include_incognito(), nullptr, nullptr,
2184 &contents, nullptr, &error_)) {
2185 return RespondNow(Error(error_));
2186 }
2187 }
2188 // Discard the tab.
2189 contents =
2190 g_browser_process->GetTabManager()->DiscardTabByExtension(contents);
2191
2192 // Create result to be returned. We have to return the Tab object
2193 // in case of success (contents is not null) and undefined otherwise.
2194 if (contents) {
2195 return RespondNow(ArgumentList(tabs::Discard::Results::Create(
2196 *ExtensionTabUtil::CreateTabObject(contents))));
2197 } 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.
2198 return RespondNow(NoArguments());
2199 }
2200 }
2201
2202 TabsDiscardFunction::TabsDiscardFunction() {}
2203 TabsDiscardFunction::~TabsDiscardFunction() {}
2204
2171 } // namespace extensions 2205 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698