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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 2152373003: [Extensions] Code Cleanup - Remove redundant smart-ptr get()s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 bool populate_tabs() { 129 bool populate_tabs() {
130 if (params_->get_info.get() && params_->get_info->populate.get()) 130 if (params_->get_info.get() && params_->get_info->populate.get())
131 return *params_->get_info->populate; 131 return *params_->get_info->populate;
132 return false; 132 return false;
133 } 133 }
134 134
135 WindowController::TypeFilter type_filters() { 135 WindowController::TypeFilter type_filters() {
136 if (params_->get_info.get() && params_->get_info->window_types.get()) 136 if (params_->get_info.get() && params_->get_info->window_types.get())
137 return WindowController::GetFilterFromWindowTypes( 137 return WindowController::GetFilterFromWindowTypes(
138 *params_->get_info->window_types.get()); 138 *params_->get_info->window_types);
139 return WindowController::kNoWindowFilter; 139 return WindowController::kNoWindowFilter;
140 } 140 }
141 141
142 private: 142 private:
143 T* params_; 143 T* params_;
144 }; 144 };
145 145
146 bool GetBrowserFromWindowID(ChromeUIThreadExtensionFunction* function, 146 bool GetBrowserFromWindowID(ChromeUIThreadExtensionFunction* function,
147 int window_id, 147 int window_id,
148 Browser** browser) { 148 Browser** browser) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // |value| are equal. This function is used to check if a tab's parameters match 202 // |value| are equal. This function is used to check if a tab's parameters match
203 // those of the browser. 203 // those of the browser.
204 bool MatchesBool(bool* boolean, bool value) { 204 bool MatchesBool(bool* boolean, bool value) {
205 return !boolean || *boolean == value; 205 return !boolean || *boolean == value;
206 } 206 }
207 207
208 template <typename T> 208 template <typename T>
209 void AssignOptionalValue(const std::unique_ptr<T>& source, 209 void AssignOptionalValue(const std::unique_ptr<T>& source,
210 std::unique_ptr<T>& destination) { 210 std::unique_ptr<T>& destination) {
211 if (source.get()) { 211 if (source.get()) {
212 destination.reset(new T(*source.get())); 212 destination.reset(new T(*source));
213 } 213 }
214 } 214 }
215 215
216 ui::WindowShowState ConvertToWindowShowState(windows::WindowState state) { 216 ui::WindowShowState ConvertToWindowShowState(windows::WindowState state) {
217 switch (state) { 217 switch (state) {
218 case windows::WINDOW_STATE_NORMAL: 218 case windows::WINDOW_STATE_NORMAL:
219 case windows::WINDOW_STATE_DOCKED: 219 case windows::WINDOW_STATE_DOCKED:
220 return ui::SHOW_STATE_NORMAL; 220 return ui::SHOW_STATE_NORMAL;
221 case windows::WINDOW_STATE_MINIMIZED: 221 case windows::WINDOW_STATE_MINIMIZED:
222 return ui::SHOW_STATE_MINIMIZED; 222 return ui::SHOW_STATE_MINIMIZED;
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 } 1452 }
1453 1453
1454 if (!has_callback()) 1454 if (!has_callback())
1455 return true; 1455 return true;
1456 1456
1457 if (num_tabs == 0) { 1457 if (num_tabs == 0) {
1458 error_ = "No tabs given."; 1458 error_ = "No tabs given.";
1459 return false; 1459 return false;
1460 } else if (num_tabs == 1) { 1460 } else if (num_tabs == 1) {
1461 std::unique_ptr<base::Value> value; 1461 std::unique_ptr<base::Value> value;
1462 CHECK(tab_values.get()->Remove(0, &value)); 1462 CHECK(tab_values->Remove(0, &value));
1463 SetResult(std::move(value)); 1463 SetResult(std::move(value));
1464 } else { 1464 } else {
1465 // Only return the results as an array if there are multiple tabs. 1465 // Only return the results as an array if there are multiple tabs.
1466 SetResult(std::move(tab_values)); 1466 SetResult(std::move(tab_values));
1467 } 1467 }
1468 1468
1469 return true; 1469 return true;
1470 } 1470 }
1471 1471
1472 bool TabsMoveFunction::MoveTab(int tab_id, 1472 bool TabsMoveFunction::MoveTab(int tab_id,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 EXTENSION_FUNCTION_VALIDATE(params.get()); 1632 EXTENSION_FUNCTION_VALIDATE(params.get());
1633 1633
1634 if (params->tab_ids.as_integers) { 1634 if (params->tab_ids.as_integers) {
1635 std::vector<int>& tab_ids = *params->tab_ids.as_integers; 1635 std::vector<int>& tab_ids = *params->tab_ids.as_integers;
1636 for (size_t i = 0; i < tab_ids.size(); ++i) { 1636 for (size_t i = 0; i < tab_ids.size(); ++i) {
1637 if (!RemoveTab(tab_ids[i])) 1637 if (!RemoveTab(tab_ids[i]))
1638 return false; 1638 return false;
1639 } 1639 }
1640 } else { 1640 } else {
1641 EXTENSION_FUNCTION_VALIDATE(params->tab_ids.as_integer); 1641 EXTENSION_FUNCTION_VALIDATE(params->tab_ids.as_integer);
1642 if (!RemoveTab(*params->tab_ids.as_integer.get())) 1642 if (!RemoveTab(*params->tab_ids.as_integer))
1643 return false; 1643 return false;
1644 } 1644 }
1645 return true; 1645 return true;
1646 } 1646 }
1647 1647
1648 bool TabsRemoveFunction::RemoveTab(int tab_id) { 1648 bool TabsRemoveFunction::RemoveTab(int tab_id) {
1649 Browser* browser = NULL; 1649 Browser* browser = NULL;
1650 WebContents* contents = NULL; 1650 WebContents* contents = NULL;
1651 if (!GetTabById(tab_id, 1651 if (!GetTabById(tab_id,
1652 GetProfile(), 1652 GetProfile(),
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace extensions 2171 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698