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

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

Issue 3517004: Revert 60997 - o Add user customizable launch type for apps by adding options... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/prefs/pref_notifier.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 12
13 using base::Time; 13 using base::Time;
14 14
15 namespace { 15 namespace {
16 16
17 // Additional preferences keys 17 // Preferences keys
18
19 // A preference that keeps track of per-extension settings. This is a dictionary
20 // object read from the Preferences file, keyed off of extension id's.
21 const char kExtensionsPref[] = "extensions.settings";
18 22
19 // Where an extension was installed from. (see Extension::Location) 23 // Where an extension was installed from. (see Extension::Location)
20 const char kPrefLocation[] = "location"; 24 const char kPrefLocation[] = "location";
21 25
22 // Enabled, disabled, killed, etc. (see Extension::State) 26 // Enabled, disabled, killed, etc. (see Extension::State)
23 const char kPrefState[] = "state"; 27 const char kPrefState[] = "state";
24 28
25 // The path to the current version's manifest file. 29 // The path to the current version's manifest file.
26 const char kPrefPath[] = "path"; 30 const char kPrefPath[] = "path";
27 31
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const char kPrefIncognitoEnabled[] = "incognito"; 72 const char kPrefIncognitoEnabled[] = "incognito";
69 73
70 // A preference to control whether an extension is allowed to inject script in 74 // A preference to control whether an extension is allowed to inject script in
71 // pages with file URLs. 75 // pages with file URLs.
72 const char kPrefAllowFileAccess[] = "allowFileAccess"; 76 const char kPrefAllowFileAccess[] = "allowFileAccess";
73 77
74 // A preference set by the web store to indicate login information for 78 // A preference set by the web store to indicate login information for
75 // purchased apps. 79 // purchased apps.
76 const char kWebStoreLogin[] = "extensions.webstore_login"; 80 const char kWebStoreLogin[] = "extensions.webstore_login";
77 81
78 // A preference set by the the NTP to persist the desired launch container type
79 // used for apps.
80 const char kPrefLaunchType[] = "launchType";
81
82 } // namespace 82 } // namespace
83 83
84 //////////////////////////////////////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////////////
85 85
86 namespace { 86 namespace {
87 87
88 // TODO(asargent) - This is cleanup code for a key that was introduced into 88 // TODO(asargent) - This is cleanup code for a key that was introduced into
89 // the extensions.settings sub-dictionary which wasn't a valid extension 89 // the extensions.settings sub-dictionary which wasn't a valid extension
90 // id. We can remove this in a couple of months. (See http://crbug.com/40017 90 // id. We can remove this in a couple of months. (See http://crbug.com/40017
91 // and http://crbug.com/39745 for more details). 91 // and http://crbug.com/39745 for more details).
92 static void CleanupBadExtensionKeys(PrefService* prefs) { 92 static void CleanupBadExtensionKeys(PrefService* prefs) {
93 DictionaryValue* dictionary = 93 DictionaryValue* dictionary = prefs->GetMutableDictionary(kExtensionsPref);
94 prefs->GetMutableDictionary(ExtensionPrefs::kExtensionsPref);
95 std::set<std::string> bad_keys; 94 std::set<std::string> bad_keys;
96 for (DictionaryValue::key_iterator i = dictionary->begin_keys(); 95 for (DictionaryValue::key_iterator i = dictionary->begin_keys();
97 i != dictionary->end_keys(); ++i) { 96 i != dictionary->end_keys(); ++i) {
98 const std::string& key_name(*i); 97 const std::string& key_name(*i);
99 if (!Extension::IdIsValid(key_name)) { 98 if (!Extension::IdIsValid(key_name)) {
100 bad_keys.insert(key_name); 99 bad_keys.insert(key_name);
101 } 100 }
102 } 101 }
103 bool dirty = false; 102 bool dirty = false;
104 for (std::set<std::string>::iterator i = bad_keys.begin(); 103 for (std::set<std::string>::iterator i = bad_keys.begin();
(...skipping 10 matching lines...) Expand all
115 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) 114 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir)
116 : prefs_(prefs), 115 : prefs_(prefs),
117 install_directory_(root_dir) { 116 install_directory_(root_dir) {
118 // TODO(asargent) - Remove this in a couple of months. (See comment above 117 // TODO(asargent) - Remove this in a couple of months. (See comment above
119 // CleanupBadExtensionKeys). 118 // CleanupBadExtensionKeys).
120 CleanupBadExtensionKeys(prefs); 119 CleanupBadExtensionKeys(prefs);
121 120
122 MakePathsRelative(); 121 MakePathsRelative();
123 } 122 }
124 123
125 // static
126 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings";
127
128 static FilePath::StringType MakePathRelative(const FilePath& parent, 124 static FilePath::StringType MakePathRelative(const FilePath& parent,
129 const FilePath& child, 125 const FilePath& child,
130 bool *dirty) { 126 bool *dirty) {
131 if (!parent.IsParent(child)) 127 if (!parent.IsParent(child))
132 return child.value(); 128 return child.value();
133 129
134 if (dirty) 130 if (dirty)
135 *dirty = true; 131 *dirty = true;
136 FilePath::StringType retval = child.value().substr( 132 FilePath::StringType retval = child.value().substr(
137 parent.value().length()); 133 parent.value().length());
(...skipping 23 matching lines...) Expand all
161 FilePath::StringType path_string; 157 FilePath::StringType path_string;
162 if (!extension_dict->GetString(kPrefPath, &path_string)) 158 if (!extension_dict->GetString(kPrefPath, &path_string))
163 continue; 159 continue;
164 FilePath path(path_string); 160 FilePath path(path_string);
165 if (path.IsAbsolute()) { 161 if (path.IsAbsolute()) {
166 extension_dict->SetString(kPrefPath, 162 extension_dict->SetString(kPrefPath,
167 MakePathRelative(install_directory_, path, &dirty)); 163 MakePathRelative(install_directory_, path, &dirty));
168 } 164 }
169 } 165 }
170 if (dirty) 166 if (dirty)
171 SavePrefsAndNotify(); 167 prefs_->ScheduleSavePersistentPrefs();
172 } 168 }
173 169
174 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { 170 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) {
175 if (!dict || dict->empty()) 171 if (!dict || dict->empty())
176 return; 172 return;
177 173
178 for (DictionaryValue::key_iterator i = dict->begin_keys(); 174 for (DictionaryValue::key_iterator i = dict->begin_keys();
179 i != dict->end_keys(); ++i) { 175 i != dict->end_keys(); ++i) {
180 DictionaryValue* extension_dict; 176 DictionaryValue* extension_dict;
181 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { 177 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return false; 226 return false;
231 227
232 DictionaryValue* ext = NULL; 228 DictionaryValue* ext = NULL;
233 if (!extensions->GetDictionary(extension_id, &ext)) { 229 if (!extensions->GetDictionary(extension_id, &ext)) {
234 // No such extension yet. 230 // No such extension yet.
235 return false; 231 return false;
236 } 232 }
237 return ReadBooleanFromPref(ext, pref_key); 233 return ReadBooleanFromPref(ext, pref_key);
238 } 234 }
239 235
240 bool ExtensionPrefs::ReadIntegerFromPref(
241 DictionaryValue* ext, const std::string& pref_key, int* out_value) {
242 if (!ext->HasKey(pref_key)) return false;
243 if (!ext->GetInteger(pref_key, out_value)) {
244 NOTREACHED() << "Failed to fetch " << pref_key << " flag.";
245 // In case we could not fetch the flag, we treat it as false.
246 return false;
247 }
248 return out_value;
249 }
250
251 bool ExtensionPrefs::ReadExtensionPrefInteger(
252 const std::string& extension_id, const std::string& pref_key,
253 int* out_value) {
254 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
255 if (!extensions)
256 return false;
257 DictionaryValue* ext = NULL;
258 if (!extensions->GetDictionary(extension_id, &ext)) {
259 // No such extension yet.
260 return false;
261 }
262 return ReadIntegerFromPref(ext, pref_key, out_value);
263 }
264
265 void ExtensionPrefs::SavePrefsAndNotify() {
266 prefs_->ScheduleSavePersistentPrefs();
267 prefs_->pref_notifier()->OnUserPreferenceSet(kExtensionsPref);
268 }
269
270 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { 236 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) {
271 return ReadBooleanFromPref(ext, kPrefBlacklist); 237 return ReadBooleanFromPref(ext, kPrefBlacklist);
272 } 238 }
273 239
274 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { 240 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) {
275 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); 241 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist);
276 } 242 }
277 243
278 bool ExtensionPrefs::IsExtensionAllowedByPolicy( 244 bool ExtensionPrefs::IsExtensionAllowedByPolicy(
279 const std::string& extension_id) { 245 const std::string& extension_id) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 bool ExtensionPrefs::DidExtensionEscalatePermissions( 282 bool ExtensionPrefs::DidExtensionEscalatePermissions(
317 const std::string& extension_id) { 283 const std::string& extension_id) {
318 return ReadExtensionPrefBoolean(extension_id, 284 return ReadExtensionPrefBoolean(extension_id,
319 kExtensionDidEscalatePermissions); 285 kExtensionDidEscalatePermissions);
320 } 286 }
321 287
322 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 288 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
323 Extension* extension, bool did_escalate) { 289 Extension* extension, bool did_escalate) {
324 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, 290 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions,
325 Value::CreateBooleanValue(did_escalate)); 291 Value::CreateBooleanValue(did_escalate));
326 prefs_->ScheduleSavePersistentPrefs(); 292 prefs_->SavePersistentPrefs();
327 } 293 }
328 294
329 void ExtensionPrefs::UpdateBlacklist( 295 void ExtensionPrefs::UpdateBlacklist(
330 const std::set<std::string>& blacklist_set) { 296 const std::set<std::string>& blacklist_set) {
331 std::vector<std::string> remove_pref_ids; 297 std::vector<std::string> remove_pref_ids;
332 std::set<std::string> used_id_set; 298 std::set<std::string> used_id_set;
333 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 299 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
334 300
335 if (extensions) { 301 if (extensions) {
336 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 302 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); 336 std::set<std::string>::const_iterator set_itr = blacklist_set.begin();
371 for (; set_itr != blacklist_set.end(); ++set_itr) { 337 for (; set_itr != blacklist_set.end(); ++set_itr) {
372 if (used_id_set.find(*set_itr) == used_id_set.end()) { 338 if (used_id_set.find(*set_itr) == used_id_set.end()) {
373 UpdateExtensionPref(*set_itr, kPrefBlacklist, 339 UpdateExtensionPref(*set_itr, kPrefBlacklist,
374 Value::CreateBooleanValue(true)); 340 Value::CreateBooleanValue(true));
375 } 341 }
376 } 342 }
377 for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { 343 for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) {
378 DeleteExtensionPrefs(remove_pref_ids[i]); 344 DeleteExtensionPrefs(remove_pref_ids[i]);
379 } 345 }
380 SavePrefsAndNotify(); 346 // Update persistent registry
347 prefs_->ScheduleSavePersistentPrefs();
381 return; 348 return;
382 } 349 }
383 350
384 Time ExtensionPrefs::LastPingDayImpl(const DictionaryValue* dictionary) const { 351 Time ExtensionPrefs::LastPingDayImpl(const DictionaryValue* dictionary) const {
385 if (dictionary && dictionary->HasKey(kLastPingDay)) { 352 if (dictionary && dictionary->HasKey(kLastPingDay)) {
386 std::string string_value; 353 std::string string_value;
387 int64 value; 354 int64 value;
388 dictionary->GetString(kLastPingDay, &string_value); 355 dictionary->GetString(kLastPingDay, &string_value);
389 if (base::StringToInt64(string_value, &value)) { 356 if (base::StringToInt64(string_value, &value)) {
390 return Time::FromInternalValue(value); 357 return Time::FromInternalValue(value);
391 } 358 }
392 } 359 }
393 return Time(); 360 return Time();
394 } 361 }
395 362
396 void ExtensionPrefs::SetLastPingDayImpl(const Time& time, 363 void ExtensionPrefs::SetLastPingDayImpl(const Time& time,
397 DictionaryValue* dictionary) { 364 DictionaryValue* dictionary) {
398 if (!dictionary) { 365 if (!dictionary) {
399 NOTREACHED(); 366 NOTREACHED();
400 return; 367 return;
401 } 368 }
402 std::string value = base::Int64ToString(time.ToInternalValue()); 369 std::string value = base::Int64ToString(time.ToInternalValue());
403 dictionary->SetString(kLastPingDay, value); 370 dictionary->SetString(kLastPingDay, value);
404 SavePrefsAndNotify(); 371 prefs_->ScheduleSavePersistentPrefs();
405 } 372 }
406 373
407 Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { 374 Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const {
408 DCHECK(Extension::IdIsValid(extension_id)); 375 DCHECK(Extension::IdIsValid(extension_id));
409 return LastPingDayImpl(GetExtensionPref(extension_id)); 376 return LastPingDayImpl(GetExtensionPref(extension_id));
410 } 377 }
411 378
412 Time ExtensionPrefs::BlacklistLastPingDay() const { 379 Time ExtensionPrefs::BlacklistLastPingDay() const {
413 return LastPingDayImpl(prefs_->GetDictionary(kExtensionsBlacklistUpdate)); 380 return LastPingDayImpl(prefs_->GetDictionary(kExtensionsBlacklistUpdate));
414 } 381 }
(...skipping 10 matching lines...) Expand all
425 } 392 }
426 393
427 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { 394 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
428 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); 395 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled);
429 } 396 }
430 397
431 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, 398 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id,
432 bool enabled) { 399 bool enabled) {
433 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, 400 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled,
434 Value::CreateBooleanValue(enabled)); 401 Value::CreateBooleanValue(enabled));
435 SavePrefsAndNotify(); 402 prefs_->SavePersistentPrefs();
436 } 403 }
437 404
438 bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) { 405 bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) {
439 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess); 406 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess);
440 } 407 }
441 408
442 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, 409 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id,
443 bool allow) { 410 bool allow) {
444 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, 411 UpdateExtensionPref(extension_id, kPrefAllowFileAccess,
445 Value::CreateBooleanValue(allow)); 412 Value::CreateBooleanValue(allow));
446 SavePrefsAndNotify(); 413 prefs_->SavePersistentPrefs();
447 }
448
449 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType(
450 const std::string& extension_id) {
451 int value;
452 if (ReadExtensionPrefInteger(extension_id, kPrefLaunchType, &value) && (
453 value == LAUNCH_PINNED ||
454 value == LAUNCH_REGULAR ||
455 value == LAUNCH_FULLSCREEN)) {
456 return static_cast<LaunchType>(value);
457 }
458 return LAUNCH_PINNED;
459 }
460
461 void ExtensionPrefs::SetLaunchType(const std::string& extension_id,
462 LaunchType launch_type) {
463 UpdateExtensionPref(extension_id, kPrefLaunchType,
464 Value::CreateIntegerValue(static_cast<int>(launch_type)));
465 SavePrefsAndNotify();
466 } 414 }
467 415
468 void ExtensionPrefs::GetKilledExtensionIds(std::set<std::string>* killed_ids) { 416 void ExtensionPrefs::GetKilledExtensionIds(std::set<std::string>* killed_ids) {
469 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); 417 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref);
470 if (!dict || dict->empty()) 418 if (!dict || dict->empty())
471 return; 419 return;
472 420
473 for (DictionaryValue::key_iterator i = dict->begin_keys(); 421 for (DictionaryValue::key_iterator i = dict->begin_keys();
474 i != dict->end_keys(); ++i) { 422 i != dict->end_keys(); ++i) {
475 const std::string& key_name(*i); 423 const std::string& key_name(*i);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 455 }
508 456
509 void ExtensionPrefs::SetToolbarOrder( 457 void ExtensionPrefs::SetToolbarOrder(
510 const std::vector<std::string>& extension_ids) { 458 const std::vector<std::string>& extension_ids) {
511 ListValue* toolbar_order = prefs_->GetMutableList(kExtensionToolbar); 459 ListValue* toolbar_order = prefs_->GetMutableList(kExtensionToolbar);
512 toolbar_order->Clear(); 460 toolbar_order->Clear();
513 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); 461 for (std::vector<std::string>::const_iterator iter = extension_ids.begin();
514 iter != extension_ids.end(); ++iter) { 462 iter != extension_ids.end(); ++iter) {
515 toolbar_order->Append(new StringValue(*iter)); 463 toolbar_order->Append(new StringValue(*iter));
516 } 464 }
517 SavePrefsAndNotify(); 465 prefs_->ScheduleSavePersistentPrefs();
518 } 466 }
519 467
520 void ExtensionPrefs::OnExtensionInstalled( 468 void ExtensionPrefs::OnExtensionInstalled(
521 Extension* extension, Extension::State initial_state, 469 Extension* extension, Extension::State initial_state,
522 bool initial_incognito_enabled) { 470 bool initial_incognito_enabled) {
523 const std::string& id = extension->id(); 471 const std::string& id = extension->id();
524 UpdateExtensionPref(id, kPrefState, 472 UpdateExtensionPref(id, kPrefState,
525 Value::CreateIntegerValue(initial_state)); 473 Value::CreateIntegerValue(initial_state));
526 UpdateExtensionPref(id, kPrefIncognitoEnabled, 474 UpdateExtensionPref(id, kPrefIncognitoEnabled,
527 Value::CreateBooleanValue(initial_incognito_enabled)); 475 Value::CreateBooleanValue(initial_incognito_enabled));
528 UpdateExtensionPref(id, kPrefLocation, 476 UpdateExtensionPref(id, kPrefLocation,
529 Value::CreateIntegerValue(extension->location())); 477 Value::CreateIntegerValue(extension->location()));
530 FilePath::StringType path = MakePathRelative(install_directory_, 478 FilePath::StringType path = MakePathRelative(install_directory_,
531 extension->path(), NULL); 479 extension->path(), NULL);
532 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); 480 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path));
533 // We store prefs about LOAD extensions, but don't cache their manifest 481 // We store prefs about LOAD extensions, but don't cache their manifest
534 // since it may change on disk. 482 // since it may change on disk.
535 if (extension->location() != Extension::LOAD) { 483 if (extension->location() != Extension::LOAD) {
536 UpdateExtensionPref(id, kPrefManifest, 484 UpdateExtensionPref(id, kPrefManifest,
537 extension->manifest_value()->DeepCopy()); 485 extension->manifest_value()->DeepCopy());
538 } 486 }
539 SavePrefsAndNotify(); 487 prefs_->SavePersistentPrefs();
540 } 488 }
541 489
542 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 490 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
543 const Extension::Location& location, 491 const Extension::Location& location,
544 bool external_uninstall) { 492 bool external_uninstall) {
545 // For external extensions, we save a preference reminding ourself not to try 493 // For external extensions, we save a preference reminding ourself not to try
546 // and install the extension anymore (except when |external_uninstall| is 494 // and install the extension anymore (except when |external_uninstall| is
547 // true, which signifies that the registry key was deleted or the pref file 495 // true, which signifies that the registry key was deleted or the pref file
548 // no longer lists the extension). 496 // no longer lists the extension).
549 if (!external_uninstall && Extension::IsExternalLocation(location)) { 497 if (!external_uninstall && Extension::IsExternalLocation(location)) {
550 UpdateExtensionPref(extension_id, kPrefState, 498 UpdateExtensionPref(extension_id, kPrefState,
551 Value::CreateIntegerValue(Extension::KILLBIT)); 499 Value::CreateIntegerValue(Extension::KILLBIT));
552 SavePrefsAndNotify(); 500 prefs_->ScheduleSavePersistentPrefs();
553 } else { 501 } else {
554 DeleteExtensionPrefs(extension_id); 502 DeleteExtensionPrefs(extension_id);
555 } 503 }
556 } 504 }
557 505
558 Extension::State ExtensionPrefs::GetExtensionState( 506 Extension::State ExtensionPrefs::GetExtensionState(
559 const std::string& extension_id) { 507 const std::string& extension_id) {
560 DictionaryValue* extension = GetExtensionPref(extension_id); 508 DictionaryValue* extension = GetExtensionPref(extension_id);
561 509
562 // If the extension doesn't have a pref, it's a --load-extension. 510 // If the extension doesn't have a pref, it's a --load-extension.
563 if (!extension) 511 if (!extension)
564 return Extension::ENABLED; 512 return Extension::ENABLED;
565 513
566 int state = -1; 514 int state = -1;
567 if (!extension->GetInteger(kPrefState, &state) || 515 if (!extension->GetInteger(kPrefState, &state) ||
568 state < 0 || state >= Extension::NUM_STATES) { 516 state < 0 || state >= Extension::NUM_STATES) {
569 LOG(ERROR) << "Bad or missing pref 'state' for extension '" 517 LOG(ERROR) << "Bad or missing pref 'state' for extension '"
570 << extension_id << "'"; 518 << extension_id << "'";
571 return Extension::ENABLED; 519 return Extension::ENABLED;
572 } 520 }
573 return static_cast<Extension::State>(state); 521 return static_cast<Extension::State>(state);
574 } 522 }
575 523
576 void ExtensionPrefs::SetExtensionState(Extension* extension, 524 void ExtensionPrefs::SetExtensionState(Extension* extension,
577 Extension::State state) { 525 Extension::State state) {
578 UpdateExtensionPref(extension->id(), kPrefState, 526 UpdateExtensionPref(extension->id(), kPrefState,
579 Value::CreateIntegerValue(state)); 527 Value::CreateIntegerValue(state));
580 SavePrefsAndNotify(); 528 prefs_->SavePersistentPrefs();
581 } 529 }
582 530
583 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { 531 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) {
584 DictionaryValue* extension = GetExtensionPref(extension_id); 532 DictionaryValue* extension = GetExtensionPref(extension_id);
585 if (!extension) 533 if (!extension)
586 return std::string(); 534 return std::string();
587 535
588 std::string version; 536 std::string version;
589 if (!extension->GetString(kPrefVersion, &version)) { 537 if (!extension->GetString(kPrefVersion, &version)) {
590 LOG(ERROR) << "Bad or missing pref 'version' for extension '" 538 LOG(ERROR) << "Bad or missing pref 'version' for extension '"
591 << extension_id << "'"; 539 << extension_id << "'";
592 } 540 }
593 541
594 return version; 542 return version;
595 } 543 }
596 544
597 void ExtensionPrefs::UpdateManifest(Extension* extension) { 545 void ExtensionPrefs::UpdateManifest(Extension* extension) {
598 if (extension->location() != Extension::LOAD) { 546 if (extension->location() != Extension::LOAD) {
599 UpdateExtensionPref(extension->id(), kPrefManifest, 547 UpdateExtensionPref(extension->id(), kPrefManifest,
600 extension->manifest_value()->DeepCopy()); 548 extension->manifest_value()->DeepCopy());
601 SavePrefsAndNotify(); 549 prefs_->ScheduleSavePersistentPrefs();
602 } 550 }
603 } 551 }
604 552
605 FilePath ExtensionPrefs::GetExtensionPath(const std::string& extension_id) { 553 FilePath ExtensionPrefs::GetExtensionPath(const std::string& extension_id) {
606 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); 554 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref);
607 if (!dict || dict->empty()) 555 if (!dict || dict->empty())
608 return FilePath(); 556 return FilePath();
609 557
610 std::string path; 558 std::string path;
611 if (!dict->GetString(extension_id + "." + kPrefPath, &path)) 559 if (!dict->GetString(extension_id + "." + kPrefPath, &path))
(...skipping 10 matching lines...) Expand all
622 return; 570 return;
623 } 571 }
624 DictionaryValue* extension = GetOrCreateExtensionPref(extension_id); 572 DictionaryValue* extension = GetOrCreateExtensionPref(extension_id);
625 extension->Set(key, data_value); 573 extension->Set(key, data_value);
626 } 574 }
627 575
628 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { 576 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) {
629 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); 577 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref);
630 if (dict->HasKey(extension_id)) { 578 if (dict->HasKey(extension_id)) {
631 dict->Remove(extension_id, NULL); 579 dict->Remove(extension_id, NULL);
632 SavePrefsAndNotify(); 580 prefs_->ScheduleSavePersistentPrefs();
633 } 581 }
634 } 582 }
635 583
636 DictionaryValue* ExtensionPrefs::GetOrCreateExtensionPref( 584 DictionaryValue* ExtensionPrefs::GetOrCreateExtensionPref(
637 const std::string& extension_id) { 585 const std::string& extension_id) {
638 DCHECK(Extension::IdIsValid(extension_id)); 586 DCHECK(Extension::IdIsValid(extension_id));
639 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); 587 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref);
640 DictionaryValue* extension = NULL; 588 DictionaryValue* extension = NULL;
641 if (!dict->GetDictionary(extension_id, &extension)) { 589 if (!dict->GetDictionary(extension_id, &extension)) {
642 // Extension pref does not exist, create it. 590 // Extension pref does not exist, create it.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 NOTREACHED(); 710 NOTREACHED();
763 return; 711 return;
764 } 712 }
765 extension_prefs->Remove(kIdleInstallInfo, NULL); 713 extension_prefs->Remove(kIdleInstallInfo, NULL);
766 DictionaryValue* info = new DictionaryValue(); 714 DictionaryValue* info = new DictionaryValue();
767 info->SetString(kIdleInstallInfoCrxPath, crx_path.value()); 715 info->SetString(kIdleInstallInfoCrxPath, crx_path.value());
768 info->SetString(kIdleInstallInfoVersion, version); 716 info->SetString(kIdleInstallInfoVersion, version);
769 info->SetString(kIdleInstallInfoFetchTime, 717 info->SetString(kIdleInstallInfoFetchTime,
770 base::Int64ToString(fetch_time.ToInternalValue())); 718 base::Int64ToString(fetch_time.ToInternalValue()));
771 extension_prefs->Set(kIdleInstallInfo, info); 719 extension_prefs->Set(kIdleInstallInfo, info);
772 SavePrefsAndNotify(); 720 prefs_->ScheduleSavePersistentPrefs();
773 } 721 }
774 722
775 bool ExtensionPrefs::RemoveIdleInstallInfo(const std::string& extension_id) { 723 bool ExtensionPrefs::RemoveIdleInstallInfo(const std::string& extension_id) {
776 DictionaryValue* extension_prefs = GetExtensionPref(extension_id); 724 DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
777 if (!extension_prefs) 725 if (!extension_prefs)
778 return false; 726 return false;
779 bool result = extension_prefs->Remove(kIdleInstallInfo, NULL); 727 bool result = extension_prefs->Remove(kIdleInstallInfo, NULL);
780 SavePrefsAndNotify(); 728 prefs_->ScheduleSavePersistentPrefs();
781 return result; 729 return result;
782 } 730 }
783 731
784 bool ExtensionPrefs::GetIdleInstallInfo(const std::string& extension_id, 732 bool ExtensionPrefs::GetIdleInstallInfo(const std::string& extension_id,
785 FilePath* crx_path, 733 FilePath* crx_path,
786 std::string* version, 734 std::string* version,
787 base::Time* fetch_time) { 735 base::Time* fetch_time) {
788 DictionaryValue* extension_prefs = GetExtensionPref(extension_id); 736 DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
789 if (!extension_prefs) 737 if (!extension_prefs)
790 return false; 738 return false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 bool ExtensionPrefs::GetWebStoreLogin(std::string* result) { 800 bool ExtensionPrefs::GetWebStoreLogin(std::string* result) {
853 if (prefs_->HasPrefPath(kWebStoreLogin)) { 801 if (prefs_->HasPrefPath(kWebStoreLogin)) {
854 *result = prefs_->GetString(kWebStoreLogin); 802 *result = prefs_->GetString(kWebStoreLogin);
855 return true; 803 return true;
856 } 804 }
857 return false; 805 return false;
858 } 806 }
859 807
860 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { 808 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) {
861 prefs_->SetString(kWebStoreLogin, login); 809 prefs_->SetString(kWebStoreLogin, login);
862 SavePrefsAndNotify(); 810 prefs_->ScheduleSavePersistentPrefs();
863 } 811 }
864 812
865 // static 813 // static
866 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 814 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
867 prefs->RegisterDictionaryPref(kExtensionsPref); 815 prefs->RegisterDictionaryPref(kExtensionsPref);
868 prefs->RegisterListPref(kExtensionToolbar); 816 prefs->RegisterListPref(kExtensionToolbar);
869 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 817 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
870 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 818 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
871 prefs->RegisterListPref(kExtensionInstallAllowList); 819 prefs->RegisterListPref(kExtensionInstallAllowList);
872 prefs->RegisterListPref(kExtensionInstallDenyList); 820 prefs->RegisterListPref(kExtensionInstallDenyList);
873 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 821 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
874 } 822 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/prefs/pref_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698