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

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

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