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

Side by Side Diff: chrome/browser/extensions/extension_action_storage_manager.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extension_action_storage_manager.h" 5 #include "chrome/browser/extensions/extension_action_storage_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8
9 #include <memory>
8 #include <utility> 10 #include <utility>
9 11
10 #include "base/base64.h" 12 #include "base/base64.h"
11 #include "base/bind.h" 13 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/extensions/extension_action.h" 16 #include "chrome/browser/extensions/extension_action.h"
16 #include "chrome/browser/extensions/extension_action_manager.h" 17 #include "chrome/browser/extensions/extension_action_manager.h"
17 #include "extensions/browser/extension_registry.h" 18 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/extension_system.h" 19 #include "extensions/browser/extension_system.h"
19 #include "extensions/browser/state_store.h" 20 #include "extensions/browser/state_store.h"
20 #include "extensions/common/constants.h" 21 #include "extensions/common/constants.h"
21 #include "ui/base/layout.h" 22 #include "ui/base/layout.h"
22 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/codec/png_codec.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 static_cast<float>(icon_size) / ExtensionAction::ActionIconSize(); 153 static_cast<float>(icon_size) / ExtensionAction::ActionIconSize();
153 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); 154 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
154 } 155 }
155 } 156 }
156 action->SetIcon(kDefaultTabId, gfx::Image(icon)); 157 action->SetIcon(kDefaultTabId, gfx::Image(icon));
157 } 158 }
158 } 159 }
159 160
160 // Store |action|'s default values in a DictionaryValue for use in storing to 161 // Store |action|'s default values in a DictionaryValue for use in storing to
161 // disk. 162 // disk.
162 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { 163 std::unique_ptr<base::DictionaryValue> DefaultsToValue(
164 ExtensionAction* action) {
163 const int kDefaultTabId = ExtensionAction::kDefaultTabId; 165 const int kDefaultTabId = ExtensionAction::kDefaultTabId;
164 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 166 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
165 167
166 dict->SetString(kPopupUrlStorageKey, 168 dict->SetString(kPopupUrlStorageKey,
167 action->GetPopupUrl(kDefaultTabId).spec()); 169 action->GetPopupUrl(kDefaultTabId).spec());
168 dict->SetString(kTitleStorageKey, action->GetTitle(kDefaultTabId)); 170 dict->SetString(kTitleStorageKey, action->GetTitle(kDefaultTabId));
169 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kDefaultTabId)); 171 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kDefaultTabId));
170 dict->SetString( 172 dict->SetString(
171 kBadgeBackgroundColorStorageKey, 173 kBadgeBackgroundColorStorageKey,
172 SkColorToRawString(action->GetBadgeBackgroundColor(kDefaultTabId))); 174 SkColorToRawString(action->GetBadgeBackgroundColor(kDefaultTabId)));
173 dict->SetString(kBadgeTextColorStorageKey, 175 dict->SetString(kBadgeTextColorStorageKey,
174 SkColorToRawString(action->GetBadgeTextColor(kDefaultTabId))); 176 SkColorToRawString(action->GetBadgeTextColor(kDefaultTabId)));
175 dict->SetInteger(kAppearanceStorageKey, 177 dict->SetInteger(kAppearanceStorageKey,
176 action->GetIsVisible(kDefaultTabId) ? ACTIVE : INVISIBLE); 178 action->GetIsVisible(kDefaultTabId) ? ACTIVE : INVISIBLE);
177 179
178 gfx::ImageSkia icon = 180 gfx::ImageSkia icon =
179 action->GetExplicitlySetIcon(kDefaultTabId).AsImageSkia(); 181 action->GetExplicitlySetIcon(kDefaultTabId).AsImageSkia();
180 if (!icon.isNull()) { 182 if (!icon.isNull()) {
181 scoped_ptr<base::DictionaryValue> icon_value(new base::DictionaryValue()); 183 std::unique_ptr<base::DictionaryValue> icon_value(
184 new base::DictionaryValue());
182 std::vector<gfx::ImageSkiaRep> image_reps = icon.image_reps(); 185 std::vector<gfx::ImageSkiaRep> image_reps = icon.image_reps();
183 for (const gfx::ImageSkiaRep& rep : image_reps) { 186 for (const gfx::ImageSkiaRep& rep : image_reps) {
184 int size = static_cast<int>(rep.scale() * icon.width()); 187 int size = static_cast<int>(rep.scale() * icon.width());
185 std::string size_string = base::IntToString(size); 188 std::string size_string = base::IntToString(size);
186 icon_value->SetString(size_string, BitmapToString(rep.sk_bitmap())); 189 icon_value->SetString(size_string, BitmapToString(rep.sk_bitmap()));
187 } 190 }
188 dict->Set(kIconStorageKey, std::move(icon_value)); 191 dict->Set(kIconStorageKey, std::move(icon_value));
189 } 192 }
190 return dict; 193 return dict;
191 } 194 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 240 }
238 241
239 void ExtensionActionStorageManager::OnExtensionActionAPIShuttingDown() { 242 void ExtensionActionStorageManager::OnExtensionActionAPIShuttingDown() {
240 extension_action_observer_.RemoveAll(); 243 extension_action_observer_.RemoveAll();
241 } 244 }
242 245
243 void ExtensionActionStorageManager::WriteToStorage( 246 void ExtensionActionStorageManager::WriteToStorage(
244 ExtensionAction* extension_action) { 247 ExtensionAction* extension_action) {
245 StateStore* store = GetStateStore(); 248 StateStore* store = GetStateStore();
246 if (store) { 249 if (store) {
247 scoped_ptr<base::DictionaryValue> defaults = 250 std::unique_ptr<base::DictionaryValue> defaults =
248 DefaultsToValue(extension_action); 251 DefaultsToValue(extension_action);
249 store->SetExtensionValue(extension_action->extension_id(), 252 store->SetExtensionValue(extension_action->extension_id(),
250 kBrowserActionStorageKey, std::move(defaults)); 253 kBrowserActionStorageKey, std::move(defaults));
251 } 254 }
252 } 255 }
253 256
254 void ExtensionActionStorageManager::ReadFromStorage( 257 void ExtensionActionStorageManager::ReadFromStorage(
255 const std::string& extension_id, scoped_ptr<base::Value> value) { 258 const std::string& extension_id,
259 std::unique_ptr<base::Value> value) {
256 const Extension* extension = ExtensionRegistry::Get(browser_context_)-> 260 const Extension* extension = ExtensionRegistry::Get(browser_context_)->
257 enabled_extensions().GetByID(extension_id); 261 enabled_extensions().GetByID(extension_id);
258 if (!extension) 262 if (!extension)
259 return; 263 return;
260 264
261 ExtensionAction* browser_action = 265 ExtensionAction* browser_action =
262 ExtensionActionManager::Get(browser_context_)->GetBrowserAction( 266 ExtensionActionManager::Get(browser_context_)->GetBrowserAction(
263 *extension); 267 *extension);
264 if (!browser_action) { 268 if (!browser_action) {
265 // This can happen if the extension is updated between startup and when the 269 // This can happen if the extension is updated between startup and when the
266 // storage read comes back, and the update removes the browser action. 270 // storage read comes back, and the update removes the browser action.
267 // http://crbug.com/349371 271 // http://crbug.com/349371
268 return; 272 return;
269 } 273 }
270 274
271 const base::DictionaryValue* dict = NULL; 275 const base::DictionaryValue* dict = NULL;
272 if (!value.get() || !value->GetAsDictionary(&dict)) 276 if (!value.get() || !value->GetAsDictionary(&dict))
273 return; 277 return;
274 278
275 SetDefaultsFromValue(dict, browser_action); 279 SetDefaultsFromValue(dict, browser_action);
276 } 280 }
277 281
278 StateStore* ExtensionActionStorageManager::GetStateStore() { 282 StateStore* ExtensionActionStorageManager::GetStateStore() {
279 return ExtensionSystem::Get(browser_context_)->state_store(); 283 return ExtensionSystem::Get(browser_context_)->state_store();
280 } 284 }
281 285
282 } // namespace extensions 286 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action_storage_manager.h ('k') | chrome/browser/extensions/extension_action_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698