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

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

Issue 116543010: Remove the Value class names from the global namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 6 years, 12 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 | Annotate | Revision Log
« no previous file with comments | « base/values.h ('k') | chrome/browser/prefs/pref_hash_calculator.cc » ('j') | 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/extensions/external_pref_loader.h" 5 #include "chrome/browser/extensions/external_pref_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } while (true); 60 } while (true);
61 61
62 return external_extension_paths; 62 return external_extension_paths;
63 } 63 }
64 64
65 // Extracts extension information from a json file serialized by |serializer|. 65 // Extracts extension information from a json file serialized by |serializer|.
66 // |path| is only used for informational purposes (outputted when an error 66 // |path| is only used for informational purposes (outputted when an error
67 // occurs). An empty dictionary is returned in case of failure (e.g. invalid 67 // occurs). An empty dictionary is returned in case of failure (e.g. invalid
68 // path or json content). 68 // path or json content).
69 // Caller takes ownership of the returned dictionary. 69 // Caller takes ownership of the returned dictionary.
70 DictionaryValue* ExtractExtensionPrefs(base::ValueSerializer* serializer, 70 base::DictionaryValue* ExtractExtensionPrefs(base::ValueSerializer* serializer,
71 const base::FilePath& path) { 71 const base::FilePath& path) {
72 std::string error_msg; 72 std::string error_msg;
73 Value* extensions = serializer->Deserialize(NULL, &error_msg); 73 base::Value* extensions = serializer->Deserialize(NULL, &error_msg);
74 if (!extensions) { 74 if (!extensions) {
75 LOG(WARNING) << "Unable to deserialize json data: " << error_msg 75 LOG(WARNING) << "Unable to deserialize json data: " << error_msg
76 << " in file " << path.value() << "."; 76 << " in file " << path.value() << ".";
77 return new DictionaryValue; 77 return new base::DictionaryValue;
78 } 78 }
79 79
80 DictionaryValue* ext_dictionary = NULL; 80 base::DictionaryValue* ext_dictionary = NULL;
81 if (extensions->GetAsDictionary(&ext_dictionary)) 81 if (extensions->GetAsDictionary(&ext_dictionary))
82 return ext_dictionary; 82 return ext_dictionary;
83 83
84 LOG(WARNING) << "Expected a JSON dictionary in file " 84 LOG(WARNING) << "Expected a JSON dictionary in file "
85 << path.value() << "."; 85 << path.value() << ".";
86 return new DictionaryValue; 86 return new base::DictionaryValue;
87 } 87 }
88 88
89 } // namespace 89 } // namespace
90 90
91 namespace extensions { 91 namespace extensions {
92 92
93 ExternalPrefLoader::ExternalPrefLoader(int base_path_id, Options options) 93 ExternalPrefLoader::ExternalPrefLoader(int base_path_id, Options options)
94 : base_path_id_(base_path_id), options_(options) { 94 : base_path_id_(base_path_id), options_(options) {
95 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 95 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
96 } 96 }
97 97
98 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { 98 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() {
99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
100 100
101 // |base_path_| was set in LoadOnFileThread(). 101 // |base_path_| was set in LoadOnFileThread().
102 return base_path_; 102 return base_path_;
103 } 103 }
104 104
105 void ExternalPrefLoader::StartLoading() { 105 void ExternalPrefLoader::StartLoading() {
106 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 106 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107 BrowserThread::PostTask( 107 BrowserThread::PostTask(
108 BrowserThread::FILE, FROM_HERE, 108 BrowserThread::FILE, FROM_HERE,
109 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); 109 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this));
110 } 110 }
111 111
112 void ExternalPrefLoader::LoadOnFileThread() { 112 void ExternalPrefLoader::LoadOnFileThread() {
113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
114 114
115 scoped_ptr<DictionaryValue> prefs(new DictionaryValue); 115 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
116 116
117 // TODO(skerner): Some values of base_path_id_ will cause 117 // TODO(skerner): Some values of base_path_id_ will cause
118 // PathService::Get() to return false, because the path does 118 // PathService::Get() to return false, because the path does
119 // not exist. Find and fix the build/install scripts so that 119 // not exist. Find and fix the build/install scripts so that
120 // this can become a CHECK(). Known examples include chrome 120 // this can become a CHECK(). Known examples include chrome
121 // OS developer builds and linux install packages. 121 // OS developer builds and linux install packages.
122 // Tracked as crbug.com/70402 . 122 // Tracked as crbug.com/70402 .
123 if (PathService::Get(base_path_id_, &base_path_)) { 123 if (PathService::Get(base_path_id_, &base_path_)) {
124 ReadExternalExtensionPrefFile(prefs.get()); 124 ReadExternalExtensionPrefFile(prefs.get());
125 125
(...skipping 17 matching lines...) Expand all
143 // read at least one .json file. If so, then we should have 143 // read at least one .json file. If so, then we should have
144 // set |base_path_|. 144 // set |base_path_|.
145 if (!prefs_->empty()) 145 if (!prefs_->empty())
146 CHECK(!base_path_.empty()); 146 CHECK(!base_path_.empty());
147 147
148 BrowserThread::PostTask( 148 BrowserThread::PostTask(
149 BrowserThread::UI, FROM_HERE, 149 BrowserThread::UI, FROM_HERE,
150 base::Bind(&ExternalPrefLoader::LoadFinished, this)); 150 base::Bind(&ExternalPrefLoader::LoadFinished, this));
151 } 151 }
152 152
153 void ExternalPrefLoader::ReadExternalExtensionPrefFile(DictionaryValue* prefs) { 153 void ExternalPrefLoader::ReadExternalExtensionPrefFile(
154 base::DictionaryValue* prefs) {
154 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 155 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
155 CHECK(NULL != prefs); 156 CHECK(NULL != prefs);
156 157
157 base::FilePath json_file = base_path_.Append(kExternalExtensionJson); 158 base::FilePath json_file = base_path_.Append(kExternalExtensionJson);
158 159
159 if (!base::PathExists(json_file)) { 160 if (!base::PathExists(json_file)) {
160 // This is not an error. The file does not exist by default. 161 // This is not an error. The file does not exist by default.
161 return; 162 return;
162 } 163 }
163 164
(...skipping 10 matching lines...) Expand all
174 } 175 }
175 #else 176 #else
176 // The only platform that uses this check is Mac OS. If you add one, 177 // The only platform that uses this check is Mac OS. If you add one,
177 // you need to implement file_util::VerifyPathControlledByAdmin() for 178 // you need to implement file_util::VerifyPathControlledByAdmin() for
178 // that platform. 179 // that platform.
179 NOTREACHED(); 180 NOTREACHED();
180 #endif // defined(OS_MACOSX) 181 #endif // defined(OS_MACOSX)
181 } 182 }
182 183
183 JSONFileValueSerializer serializer(json_file); 184 JSONFileValueSerializer serializer(json_file);
184 scoped_ptr<DictionaryValue> ext_prefs( 185 scoped_ptr<base::DictionaryValue> ext_prefs(
185 ExtractExtensionPrefs(&serializer, json_file)); 186 ExtractExtensionPrefs(&serializer, json_file));
186 if (ext_prefs) 187 if (ext_prefs)
187 prefs->MergeDictionary(ext_prefs.get()); 188 prefs->MergeDictionary(ext_prefs.get());
188 } 189 }
189 190
190 void ExternalPrefLoader::ReadStandaloneExtensionPrefFiles( 191 void ExternalPrefLoader::ReadStandaloneExtensionPrefFiles(
191 DictionaryValue* prefs) { 192 base::DictionaryValue* prefs) {
192 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 193 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
193 CHECK(NULL != prefs); 194 CHECK(NULL != prefs);
194 195
195 // First list the potential .json candidates. 196 // First list the potential .json candidates.
196 std::set<base::FilePath> 197 std::set<base::FilePath>
197 candidates = GetPrefsCandidateFilesFromFolder(base_path_); 198 candidates = GetPrefsCandidateFilesFromFolder(base_path_);
198 if (candidates.empty()) { 199 if (candidates.empty()) {
199 DVLOG(1) << "Extension candidates list empty"; 200 DVLOG(1) << "Extension candidates list empty";
200 return; 201 return;
201 } 202 }
(...skipping 10 matching lines...) Expand all
212 WideToASCII( 213 WideToASCII(
213 extension_candidate_path.RemoveExtension().BaseName().value()); 214 extension_candidate_path.RemoveExtension().BaseName().value());
214 #elif defined(OS_POSIX) 215 #elif defined(OS_POSIX)
215 extension_candidate_path.RemoveExtension().BaseName().value().c_str(); 216 extension_candidate_path.RemoveExtension().BaseName().value().c_str();
216 #endif 217 #endif
217 218
218 DVLOG(1) << "Reading json file: " 219 DVLOG(1) << "Reading json file: "
219 << extension_candidate_path.LossyDisplayName().c_str(); 220 << extension_candidate_path.LossyDisplayName().c_str();
220 221
221 JSONFileValueSerializer serializer(extension_candidate_path); 222 JSONFileValueSerializer serializer(extension_candidate_path);
222 scoped_ptr<DictionaryValue> ext_prefs( 223 scoped_ptr<base::DictionaryValue> ext_prefs(
223 ExtractExtensionPrefs(&serializer, extension_candidate_path)); 224 ExtractExtensionPrefs(&serializer, extension_candidate_path));
224 if (ext_prefs) { 225 if (ext_prefs) {
225 DVLOG(1) << "Adding extension with id: " << id; 226 DVLOG(1) << "Adding extension with id: " << id;
226 prefs->Set(id, ext_prefs.release()); 227 prefs->Set(id, ext_prefs.release());
227 } 228 }
228 } 229 }
229 } 230 }
230 231
231 ExternalTestingLoader::ExternalTestingLoader( 232 ExternalTestingLoader::ExternalTestingLoader(
232 const std::string& json_data, 233 const std::string& json_data,
(...skipping 11 matching lines...) Expand all
244 LoadFinished(); 245 LoadFinished();
245 } 246 }
246 247
247 ExternalTestingLoader::~ExternalTestingLoader() {} 248 ExternalTestingLoader::~ExternalTestingLoader() {}
248 249
249 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { 250 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() {
250 return fake_base_path_; 251 return fake_base_path_;
251 } 252 }
252 253
253 } // extensions 254 } // extensions
OLDNEW
« no previous file with comments | « base/values.h ('k') | chrome/browser/prefs/pref_hash_calculator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698