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

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: 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 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 bool TabsDiscardFunction::RunSync() {
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 // If |tab_id| is given, find the web_contents respective to it.
2178 // Otherwise invoke discard function in TabManager with null web_contents
2179 // that will discard the least important tab.
2180 if (params->tab_id) {
2181 int tab_id = *params->tab_id;
2182 if (!GetTabById(tab_id, GetProfile(), include_incognito(), nullptr, nullptr,
2183 &contents, nullptr, &error_)) {
2184 return false;
2185 }
2186 }
2187 // Discards the tab.
Georges Khalil 2016/07/19 20:35:40 nit: discards -> discard.
Anderson Silva 2016/07/19 20:57:35 Done.
2188 memory::TabManager* tab_manager = g_browser_process->GetTabManager();
2189 if (!tab_manager)
2190 return false;
2191 contents = tab_manager->DiscardTabByExtension(contents);
2192 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.
2193
2194 if (!has_callback())
2195 return true;
2196
2197 // Create result to be returned if callback is present.
2198 // We have to return a Tab object and the success boolean, so create a
2199 // default object and replace it with the real tab in case of success
2200 // (contents is not null).
2201 std::unique_ptr<api::tabs::Tab> tab(new api::tabs::Tab);
2202 if (success)
2203 tab = ExtensionTabUtil::CreateTabObject(contents);
2204 results_ = api::tabs::Discard::Results::Create(*tab, success);
2205 return true;
2206 }
2207
2171 } // namespace extensions 2208 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698