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

Side by Side Diff: chrome/browser/chromeos/extensions/default_app_order.cc

Issue 1405083003: Fix memory leaks in chrome/browser/chromeos/extensions/default_app_order.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromeos/extensions/default_app_order.h" 5 #include "chrome/browser/chromeos/extensions/default_app_order.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 "gdijeikdkaembjbdobgfkoidjkpbmlkd", // Play Movies & TV 52 "gdijeikdkaembjbdobgfkoidjkpbmlkd", // Play Movies & TV
53 "fobcpibfeplaikcclojfdhfdmbbeofai", // Games 53 "fobcpibfeplaikcclojfdhfdmbbeofai", // Games
54 "joodangkbfjnajiiifokapkpmhfnpleo", // Calculator 54 "joodangkbfjnajiiifokapkpmhfnpleo", // Calculator
55 "hfhhnacclhffhdffklopdkcgdhifgngh", // Camera 55 "hfhhnacclhffhdffklopdkcgdhifgngh", // Camera
56 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop 56 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
57 }; 57 };
58 58
59 // Reads external ordinal json file and returned the parsed value. Returns NULL 59 // Reads external ordinal json file and returned the parsed value. Returns NULL
60 // if the file does not exist or could not be parsed properly. Caller takes 60 // if the file does not exist or could not be parsed properly. Caller takes
61 // ownership of the returned value. 61 // ownership of the returned value.
62 base::ListValue* ReadExternalOrdinalFile(const base::FilePath& path) { 62 scoped_ptr<base::ListValue> ReadExternalOrdinalFile(
63 const base::FilePath& path) {
63 if (!base::PathExists(path)) 64 if (!base::PathExists(path))
64 return NULL; 65 return NULL;
65 66
66 JSONFileValueDeserializer deserializer(path); 67 JSONFileValueDeserializer deserializer(path);
67 std::string error_msg; 68 std::string error_msg;
68 base::Value* value = deserializer.Deserialize(NULL, &error_msg).release(); 69 scoped_ptr<base::Value> value = deserializer.Deserialize(NULL, &error_msg);
69 if (!value) { 70 if (!value) {
70 LOG(WARNING) << "Unable to deserialize default app ordinals json data:" 71 LOG(WARNING) << "Unable to deserialize default app ordinals json data:"
71 << error_msg << ", file=" << path.value(); 72 << error_msg << ", file=" << path.value();
72 return NULL; 73 return NULL;
73 } 74 }
74 75
75 base::ListValue* ordinal_list_value = NULL; 76 scoped_ptr<base::ListValue> ordinal_list_value =
76 if (value->GetAsList(&ordinal_list_value)) 77 base::ListValue::From(value.Pass());
77 return ordinal_list_value; 78 if (!ordinal_list_value)
79 LOG(WARNING) << "Expect a JSON list in file " << path.value();
78 80
79 LOG(WARNING) << "Expect a JSON list in file " << path.value(); 81 return ordinal_list_value;
80 // TODO(Olli Raula) possible memory leak http://crbug.com/543015
81 return NULL;
82 } 82 }
83 83
84 std::string GetLocaleSpecificStringImpl( 84 std::string GetLocaleSpecificStringImpl(
85 const base::DictionaryValue* root, 85 const base::DictionaryValue* root,
86 const std::string& locale, 86 const std::string& locale,
87 const std::string& dictionary_name, 87 const std::string& dictionary_name,
88 const std::string& entry_name) { 88 const std::string& entry_name) {
89 const base::DictionaryValue* dictionary_content = NULL; 89 const base::DictionaryValue* dictionary_content = NULL;
90 if (!root || !root->GetDictionary(dictionary_name, &dictionary_content)) 90 if (!root || !root->GetDictionary(dictionary_name, &dictionary_content))
91 return std::string(); 91 return std::string();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 const std::string& ExternalLoader::GetOemAppsFolderName() { 145 const std::string& ExternalLoader::GetOemAppsFolderName() {
146 if (!loaded_.IsSignaled()) 146 if (!loaded_.IsSignaled())
147 LOG(ERROR) << "GetOemAppsFolderName() called before loaded."; 147 LOG(ERROR) << "GetOemAppsFolderName() called before loaded.";
148 return oem_apps_folder_name_; 148 return oem_apps_folder_name_;
149 } 149 }
150 150
151 void ExternalLoader::Load() { 151 void ExternalLoader::Load() {
152 base::FilePath ordinals_file; 152 base::FilePath ordinals_file;
153 CHECK(PathService::Get(chromeos::FILE_DEFAULT_APP_ORDER, &ordinals_file)); 153 CHECK(PathService::Get(chromeos::FILE_DEFAULT_APP_ORDER, &ordinals_file));
154 154
155 scoped_ptr<base::ListValue> ordinals_value( 155 scoped_ptr<base::ListValue> ordinals_value =
156 ReadExternalOrdinalFile(ordinals_file)); 156 ReadExternalOrdinalFile(ordinals_file);
157 if (ordinals_value) { 157 if (ordinals_value) {
158 std::string locale = g_browser_process->GetApplicationLocale(); 158 std::string locale = g_browser_process->GetApplicationLocale();
159 for (size_t i = 0; i < ordinals_value->GetSize(); ++i) { 159 for (size_t i = 0; i < ordinals_value->GetSize(); ++i) {
160 std::string app_id; 160 std::string app_id;
161 base::DictionaryValue* dict = NULL; 161 base::DictionaryValue* dict = NULL;
162 if (ordinals_value->GetString(i, &app_id)) { 162 if (ordinals_value->GetString(i, &app_id)) {
163 app_ids_.push_back(app_id); 163 app_ids_.push_back(app_id);
164 } else if (ordinals_value->GetDictionary(i, &dict)) { 164 } else if (ordinals_value->GetDictionary(i, &dict)) {
165 bool flag = false; 165 bool flag = false;
166 if (dict->GetBoolean(kOemAppsFolderAttr, &flag) && flag) { 166 if (dict->GetBoolean(kOemAppsFolderAttr, &flag) && flag) {
(...skipping 28 matching lines...) Expand all
195 std::string GetOemAppsFolderName() { 195 std::string GetOemAppsFolderName() {
196 // |loader_instance| could be NULL for test. 196 // |loader_instance| could be NULL for test.
197 if (!loader_instance) 197 if (!loader_instance)
198 return std::string(); 198 return std::string();
199 else 199 else
200 return loader_instance->GetOemAppsFolderName(); 200 return loader_instance->GetOemAppsFolderName();
201 } 201 }
202 202
203 } // namespace default_app_order 203 } // namespace default_app_order
204 } // namespace chromeos 204 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698