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

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

Issue 174036: Get rid of the extension's "Current Version" file. (Closed)
Patch Set: merge conflicts Created 11 years, 4 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 9
10 namespace { 10 namespace {
11 11
12 // Preferences keys 12 // Preferences keys
13 13
14 // A preference that keeps track of per-extension settings. This is a dictionary 14 // A preference that keeps track of per-extension settings. This is a dictionary
15 // object read from the Preferences file, keyed off of extension id's. 15 // object read from the Preferences file, keyed off of extension id's.
16 const wchar_t kExtensionsPref[] = L"extensions.settings"; 16 const wchar_t kExtensionsPref[] = L"extensions.settings";
17 17
18 // Where an extension was installed from. (see Extension::Location) 18 // Where an extension was installed from. (see Extension::Location)
19 const wchar_t kPrefLocation[] = L"location"; 19 const wchar_t kPrefLocation[] = L"location";
20 20
21 // Enabled, disabled, killed, etc. (see Extension::State) 21 // Enabled, disabled, killed, etc. (see Extension::State)
22 const wchar_t kPrefState[] = L"state"; 22 const wchar_t kPrefState[] = L"state";
23 23
24 // The path to the current version's manifest file. 24 // The path to the current version's manifest file.
25 const wchar_t kPrefPath[] = L"path"; 25 const wchar_t kPrefPath[] = L"path";
26 26
27 // The dictionary containing the extension's manifest.
28 const wchar_t kPrefManifest[] = L"manifest";
29
30 // The version number.
31 const wchar_t kPrefVersion[] = L"manifest.version";
32
27 // Indicates if an extension is blacklisted: 33 // Indicates if an extension is blacklisted:
28 const wchar_t kPrefBlacklist[] = L"blacklist"; 34 const wchar_t kPrefBlacklist[] = L"blacklist";
29 35
30 // A preference that tracks extension shelf configuration. This is a list 36 // A preference that tracks extension shelf configuration. This is a list
31 // object read from the Preferences file, containing a list of toolstrip URLs. 37 // object read from the Preferences file, containing a list of toolstrip URLs.
32 const wchar_t kExtensionShelf[] = L"extensions.shelf"; 38 const wchar_t kExtensionShelf[] = L"extensions.shelf";
33 } 39 }
34 40
35 //////////////////////////////////////////////////////////////////////////////// 41 ////////////////////////////////////////////////////////////////////////////////
36 42
37 InstalledExtensions::InstalledExtensions(ExtensionPrefs* prefs) { 43 InstalledExtensions::InstalledExtensions(ExtensionPrefs* prefs) {
38 extension_data_.reset(prefs->CopyCurrentExtensions()); 44 extension_data_.reset(prefs->CopyCurrentExtensions());
39 } 45 }
40 46
41 InstalledExtensions::~InstalledExtensions() { 47 InstalledExtensions::~InstalledExtensions() {
42 } 48 }
43 49
44 void InstalledExtensions::VisitInstalledExtensions( 50 void InstalledExtensions::VisitInstalledExtensions(
45 InstalledExtensions::Callback *callback) { 51 InstalledExtensions::Callback *callback) {
52 scoped_ptr<InstalledExtensions::Callback> cleanup(callback);
46 DictionaryValue::key_iterator extension_id = extension_data_->begin_keys(); 53 DictionaryValue::key_iterator extension_id = extension_data_->begin_keys();
47 for (; extension_id != extension_data_->end_keys(); ++extension_id) { 54 for (; extension_id != extension_data_->end_keys(); ++extension_id) {
48 DictionaryValue* ext; 55 DictionaryValue* ext;
49 if (!extension_data_->GetDictionary(*extension_id, &ext)) { 56 if (!extension_data_->GetDictionary(*extension_id, &ext)) {
50 LOG(WARNING) << "Invalid pref for extension " << *extension_id; 57 LOG(WARNING) << "Invalid pref for extension " << *extension_id;
51 NOTREACHED(); 58 NOTREACHED();
52 continue; 59 continue;
53 } 60 }
54 if (ext->HasKey(kPrefBlacklist)) { 61 if (ext->HasKey(kPrefBlacklist)) {
55 bool is_blacklisted = false; 62 bool is_blacklisted = false;
(...skipping 11 matching lines...) Expand all
67 LOG(WARNING) << "Missing path pref for extension " << *extension_id; 74 LOG(WARNING) << "Missing path pref for extension " << *extension_id;
68 NOTREACHED(); 75 NOTREACHED();
69 continue; 76 continue;
70 } 77 }
71 int location_value; 78 int location_value;
72 if (!ext->GetInteger(kPrefLocation, &location_value)) { 79 if (!ext->GetInteger(kPrefLocation, &location_value)) {
73 LOG(WARNING) << "Missing location pref for extension " << *extension_id; 80 LOG(WARNING) << "Missing location pref for extension " << *extension_id;
74 NOTREACHED(); 81 NOTREACHED();
75 continue; 82 continue;
76 } 83 }
84 DictionaryValue* manifest = NULL;
85 if (!ext->GetDictionary(kPrefManifest, &manifest)) {
86 LOG(WARNING) << "Missing manifest for extension " << *extension_id;
87 // Just a warning for now.
88 }
89
77 Extension::Location location = 90 Extension::Location location =
78 static_cast<Extension::Location>(location_value); 91 static_cast<Extension::Location>(location_value);
79 callback->Run(WideToASCII(*extension_id), FilePath(path), location); 92 callback->Run(manifest, WideToASCII(*extension_id), FilePath(path),
93 location);
80 } 94 }
81 } 95 }
82 96
83 //////////////////////////////////////////////////////////////////////////////// 97 ////////////////////////////////////////////////////////////////////////////////
84 98
85 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) 99 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir)
86 : prefs_(prefs), 100 : prefs_(prefs),
87 install_directory_(root_dir) { 101 install_directory_(root_dir) {
88 if (!prefs_->FindPreference(kExtensionsPref)) 102 if (!prefs_->FindPreference(kExtensionsPref))
89 prefs_->RegisterDictionaryPref(kExtensionsPref); 103 prefs_->RegisterDictionaryPref(kExtensionsPref);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 toolstrip_urls->Clear(); 307 toolstrip_urls->Clear();
294 for (size_t i = 0; i < urls.size(); ++i) { 308 for (size_t i = 0; i < urls.size(); ++i) {
295 GURL url = urls[i]; 309 GURL url = urls[i];
296 toolstrip_urls->Append(new StringValue(url.spec())); 310 toolstrip_urls->Append(new StringValue(url.spec()));
297 } 311 }
298 prefs_->ScheduleSavePersistentPrefs(); 312 prefs_->ScheduleSavePersistentPrefs();
299 } 313 }
300 314
301 void ExtensionPrefs::OnExtensionInstalled(Extension* extension) { 315 void ExtensionPrefs::OnExtensionInstalled(Extension* extension) {
302 const std::string& id = extension->id(); 316 const std::string& id = extension->id();
303 UpdateExtensionPref(id, kPrefState, 317 // Make sure we don't enable a disabled extension.
304 Value::CreateIntegerValue(Extension::ENABLED)); 318 if (GetExtensionState(extension->id()) != Extension::DISABLED) {
319 UpdateExtensionPref(id, kPrefState,
320 Value::CreateIntegerValue(Extension::ENABLED));
321 }
305 UpdateExtensionPref(id, kPrefLocation, 322 UpdateExtensionPref(id, kPrefLocation,
306 Value::CreateIntegerValue(extension->location())); 323 Value::CreateIntegerValue(extension->location()));
307 FilePath::StringType path = MakePathRelative(install_directory_, 324 FilePath::StringType path = MakePathRelative(install_directory_,
308 extension->path(), NULL); 325 extension->path(), NULL);
309 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); 326 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path));
327 UpdateExtensionPref(id, kPrefManifest,
328 extension->manifest_value()->DeepCopy());
310 prefs_->SavePersistentPrefs(); 329 prefs_->SavePersistentPrefs();
311 } 330 }
312 331
313 void ExtensionPrefs::OnExtensionUninstalled(const Extension* extension, 332 void ExtensionPrefs::OnExtensionUninstalled(const Extension* extension,
314 bool external_uninstall) { 333 bool external_uninstall) {
315 // For external extensions, we save a preference reminding ourself not to try 334 // For external extensions, we save a preference reminding ourself not to try
316 // and install the extension anymore (except when |external_uninstall| is 335 // and install the extension anymore (except when |external_uninstall| is
317 // true, which signifies that the registry key was deleted or the pref file 336 // true, which signifies that the registry key was deleted or the pref file
318 // no longer lists the extension). 337 // no longer lists the extension).
319 if (!external_uninstall && 338 if (!external_uninstall &&
(...skipping 24 matching lines...) Expand all
344 return static_cast<Extension::State>(state); 363 return static_cast<Extension::State>(state);
345 } 364 }
346 365
347 void ExtensionPrefs::SetExtensionState(Extension* extension, 366 void ExtensionPrefs::SetExtensionState(Extension* extension,
348 Extension::State state) { 367 Extension::State state) {
349 UpdateExtensionPref(extension->id(), kPrefState, 368 UpdateExtensionPref(extension->id(), kPrefState,
350 Value::CreateIntegerValue(state)); 369 Value::CreateIntegerValue(state));
351 prefs_->SavePersistentPrefs(); 370 prefs_->SavePersistentPrefs();
352 } 371 }
353 372
373 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) {
374 DictionaryValue* extension = GetExtensionPref(extension_id);
375 if (!extension)
376 return std::string();
377
378 std::string version;
379 if (!extension->GetString(kPrefVersion, &version)) {
380 LOG(ERROR) << "Bad or missing pref 'version' for extension '"
381 << extension_id << "'";
382 }
383
384 return version;
385 }
386
387 void ExtensionPrefs::MigrateToPrefs(Extension* extension) {
388 UpdateExtensionPref(extension->id(), kPrefManifest,
389 extension->manifest_value()->DeepCopy());
390 }
391
354 bool ExtensionPrefs::UpdateExtensionPref(const std::string& extension_id, 392 bool ExtensionPrefs::UpdateExtensionPref(const std::string& extension_id,
355 const std::wstring& key, 393 const std::wstring& key,
356 Value* data_value) { 394 Value* data_value) {
357 DictionaryValue* extension = GetOrCreateExtensionPref(extension_id); 395 DictionaryValue* extension = GetOrCreateExtensionPref(extension_id);
358 if (!extension->Set(key, data_value)) { 396 if (!extension->Set(key, data_value)) {
359 NOTREACHED() << "Cannot modify key: '" << key.c_str() 397 NOTREACHED() << "Cannot modify key: '" << key.c_str()
360 << "' for extension: '" << extension_id.c_str() << "'"; 398 << "' for extension: '" << extension_id.c_str() << "'";
361 return false; 399 return false;
362 } 400 }
363 return true; 401 return true;
(...skipping 22 matching lines...) Expand all
386 } 424 }
387 425
388 DictionaryValue* ExtensionPrefs::GetExtensionPref( 426 DictionaryValue* ExtensionPrefs::GetExtensionPref(
389 const std::string& extension_id) { 427 const std::string& extension_id) {
390 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); 428 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref);
391 DictionaryValue* extension = NULL; 429 DictionaryValue* extension = NULL;
392 std::wstring id = ASCIIToWide(extension_id); 430 std::wstring id = ASCIIToWide(extension_id);
393 dict->GetDictionary(id, &extension); 431 dict->GetDictionary(id, &extension);
394 return extension; 432 return extension;
395 } 433 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698