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

Side by Side Diff: chrome/browser/ui/tabs/pinned_tab_codec.cc

Issue 2051663003: base::ListValue::Append cleanup: pass unique_ptr instead of the released pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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/ui/tabs/pinned_tab_codec.h" 5 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility>
10
9 #include "base/values.h" 11 #include "base/values.h"
10 #include "chrome/browser/extensions/tab_helper.h" 12 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "components/pref_registry/pref_registry_syncable.h" 19 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
(...skipping 14 matching lines...) Expand all
33 if (tab_model->IsTabPinned(i)) 35 if (tab_model->IsTabPinned(i))
34 return true; 36 return true;
35 } 37 }
36 return false; 38 return false;
37 } 39 }
38 40
39 // Adds a DictionaryValue to |values| representing |tab|. 41 // Adds a DictionaryValue to |values| representing |tab|.
40 static void EncodeTab(const StartupTab& tab, base::ListValue* values) { 42 static void EncodeTab(const StartupTab& tab, base::ListValue* values) {
41 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); 43 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
42 value->SetString(kURL, tab.url.spec()); 44 value->SetString(kURL, tab.url.spec());
43 values->Append(value.release()); 45 values->Append(std::move(value));
44 } 46 }
45 47
46 // Adds a base::DictionaryValue to |values| representing the pinned tab at the 48 // Adds a base::DictionaryValue to |values| representing the pinned tab at the
47 // specified index. 49 // specified index.
48 static void EncodePinnedTab(TabStripModel* model, 50 static void EncodePinnedTab(TabStripModel* model,
49 int index, 51 int index,
50 base::ListValue* values) { 52 base::ListValue* values) {
51 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 53 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
52 54
53 content::WebContents* web_contents = model->GetWebContentsAt(index); 55 content::WebContents* web_contents = model->GetWebContentsAt(index);
54 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); 56 NavigationEntry* entry = web_contents->GetController().GetActiveEntry();
55 if (entry) { 57 if (entry) {
56 value->SetString(kURL, entry->GetURL().spec()); 58 value->SetString(kURL, entry->GetURL().spec());
57 values->Append(value.release()); 59 values->Append(std::move(value));
58 } 60 }
59 } 61 }
60 62
61 // Invokes EncodePinnedTab for each pinned tab in browser. 63 // Invokes EncodePinnedTab for each pinned tab in browser.
62 static void EncodePinnedTabs(Browser* browser, base::ListValue* values) { 64 static void EncodePinnedTabs(Browser* browser, base::ListValue* values) {
63 TabStripModel* tab_model = browser->tab_strip_model(); 65 TabStripModel* tab_model = browser->tab_strip_model();
64 for (int i = 0; i < tab_model->count() && tab_model->IsTabPinned(i); ++i) 66 for (int i = 0; i < tab_model->count() && tab_model->IsTabPinned(i); ++i)
65 EncodePinnedTab(tab_model, i, values); 67 EncodePinnedTab(tab_model, i, values);
66 } 68 }
67 69
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 for (size_t i = 0, max = tabs_list->GetSize(); i < max; ++i) { 133 for (size_t i = 0, max = tabs_list->GetSize(); i < max; ++i) {
132 const base::DictionaryValue* tab_values = NULL; 134 const base::DictionaryValue* tab_values = NULL;
133 if (tabs_list->GetDictionary(i, &tab_values)) { 135 if (tabs_list->GetDictionary(i, &tab_values)) {
134 StartupTab tab; 136 StartupTab tab;
135 if (DecodeTab(*tab_values, &tab)) 137 if (DecodeTab(*tab_values, &tab))
136 results.push_back(tab); 138 results.push_back(tab);
137 } 139 }
138 } 140 }
139 return results; 141 return results;
140 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698