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

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

Issue 8198003: Convert app_launch_index and page_index from int to StringOrdinal. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Changing strings to StringOrdinals Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_pref_store.h" 10 #include "chrome/browser/extensions/extension_pref_store.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // A preference set by the web store to indicate login information for 104 // A preference set by the web store to indicate login information for
105 // purchased apps. 105 // purchased apps.
106 const char kWebStoreLogin[] = "extensions.webstore_login"; 106 const char kWebStoreLogin[] = "extensions.webstore_login";
107 107
108 // A preference set by the the NTP to persist the desired launch container type 108 // A preference set by the the NTP to persist the desired launch container type
109 // used for apps. 109 // used for apps.
110 const char kPrefLaunchType[] = "launchType"; 110 const char kPrefLaunchType[] = "launchType";
111 111
112 // A preference determining the order of which the apps appear on the NTP. 112 // A preference determining the order of which the apps appear on the NTP.
113 const char kPrefAppLaunchIndex[] = "app_launcher_index"; 113 const char kPrefAppLaunchIndexDeprecated[] = "app_launcher_index";
114 const char kPrefAppLaunchIndex[] = "app_launcher_index_string_ordinal";
114 115
115 // A preference determining the page on which an app appears in the NTP. 116 // A preference determining the page on which an app appears in the NTP.
116 const char kPrefPageIndex[] = "page_index"; 117 const char kPrefPageIndexDeprecated[] = "page_index";
118 const char kPrefPageIndex[] = "page_index_string_ordinal";
117 119
118 // A preference specifying if the user dragged the app on the NTP. 120 // A preference specifying if the user dragged the app on the NTP.
119 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; 121 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp";
120 122
121 // A preference for storing extra data sent in update checks for an extension. 123 // A preference for storing extra data sent in update checks for an extension.
122 const char kUpdateUrlData[] = "update_url_data"; 124 const char kUpdateUrlData[] = "update_url_data";
123 125
124 // Whether the browser action is visible in the toolbar. 126 // Whether the browser action is visible in the toolbar.
125 const char kBrowserActionVisible[] = "browser_action_visible"; 127 const char kBrowserActionVisible[] = "browser_action_visible";
126 128
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 const std::string extension_id_; 234 const std::string extension_id_;
233 const std::string incognito_or_regular_path_; 235 const std::string incognito_or_regular_path_;
234 236
235 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionControlledPrefUpdate); 237 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionControlledPrefUpdate);
236 }; 238 };
237 239
238 std::string JoinPrefs(std::string parent, const char* child) { 240 std::string JoinPrefs(std::string parent, const char* child) {
239 return parent + "." + child; 241 return parent + "." + child;
240 } 242 }
241 243
244 // A simple structure used when sorting extension based on the order they
245 // appear on the NTP. This is used by the code that migrates the data
246 // from integers to StringOrdinals.
247 struct ExtensionNTPOldPosition {
248 const std::string* extension_id;
249 const int page_index;
250 const int app_launch_index;
251
252 ExtensionNTPOldPosition(const std::string& ext_id, int page, int app_launch)
253 : extension_id(&ext_id),
254 page_index(page),
255 app_launch_index(app_launch) {}
256 };
257
258 struct SortByNTPOldPosition {
259 bool operator() (const ExtensionNTPOldPosition& lhs,
260 const ExtensionNTPOldPosition& rhs) const {
261 if (lhs.page_index != rhs.page_index)
262 return lhs.page_index < rhs.page_index;
263
264 return lhs.app_launch_index < rhs.app_launch_index;
265 }
266 };
267
242 } // namespace 268 } // namespace
243 269
244 ExtensionPrefs::ExtensionPrefs( 270 ExtensionPrefs::ExtensionPrefs(
245 PrefService* prefs, 271 PrefService* prefs,
246 const FilePath& root_dir, 272 const FilePath& root_dir,
247 ExtensionPrefValueMap* extension_pref_value_map) 273 ExtensionPrefValueMap* extension_pref_value_map)
248 : prefs_(prefs), 274 : prefs_(prefs),
249 install_directory_(root_dir), 275 install_directory_(root_dir),
250 extension_pref_value_map_(extension_pref_value_map), 276 extension_pref_value_map_(extension_pref_value_map),
251 content_settings_store_(new ExtensionContentSettingsStore()) { 277 content_settings_store_(new ExtensionContentSettingsStore()) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 const DictionaryValue* ext = GetExtensionPref(extension_id); 434 const DictionaryValue* ext = GetExtensionPref(extension_id);
409 ListValue* out = NULL; 435 ListValue* out = NULL;
410 if (!ext || !ext->GetList(pref_key, &out)) 436 if (!ext || !ext->GetList(pref_key, &out))
411 return false; 437 return false;
412 if (out_value) 438 if (out_value)
413 *out_value = out; 439 *out_value = out;
414 440
415 return true; 441 return true;
416 } 442 }
417 443
444 bool ExtensionPrefs::ReadExtensionPrefString(
445 const std::string& extension_id, const std::string& pref_key,
446 std::string* out_value) {
447 const DictionaryValue* ext = GetExtensionPref(extension_id);
448
449 if (!ext || !ext->GetString(pref_key, out_value))
450 return false;
451
452 return true;
453 }
454
418 bool ExtensionPrefs::ReadExtensionPrefURLPatternSet( 455 bool ExtensionPrefs::ReadExtensionPrefURLPatternSet(
419 const std::string& extension_id, 456 const std::string& extension_id,
420 const std::string& pref_key, 457 const std::string& pref_key,
421 URLPatternSet* result, 458 URLPatternSet* result,
422 int valid_schemes) { 459 int valid_schemes) {
423 const ListValue* value = NULL; 460 const ListValue* value = NULL;
424 if (!ReadExtensionPrefList(extension_id, pref_key, &value)) 461 if (!ReadExtensionPrefList(extension_id, pref_key, &value))
425 return false; 462 return false;
426 463
427 result->ClearPatterns(); 464 result->ClearPatterns();
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 JoinPrefs(kPrefGrantedPermissions, kPrefExplicitHosts); 887 JoinPrefs(kPrefGrantedPermissions, kPrefExplicitHosts);
851 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { 888 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) {
852 UpdateExtensionPref( 889 UpdateExtensionPref(
853 *ext_id, explicit_hosts, hosts->DeepCopy()); 890 *ext_id, explicit_hosts, hosts->DeepCopy());
854 891
855 // We can get rid of the old one by setting it to an empty list. 892 // We can get rid of the old one by setting it to an empty list.
856 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue()); 893 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue());
857 } 894 }
858 } 895 }
859 } 896 }
860 897
Dan Beam 2011/11/12 02:28:30 When is the EOL of this migration code?
csharp 2011/11/14 16:22:28 I don't know what the EOL should be for this code.
898 void ExtensionPrefs::MigrateAppIndex(const ExtensionIdSet& extension_ids) {
899 if (extension_ids.begin() == extension_ids.end()) {
900 return;
901 }
902
903 // Create a sorted set of all the extensions that need either their page
904 // or launch index converted.
905 std::set<ExtensionNTPOldPosition, SortByNTPOldPosition> apps_to_convert;
906 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin();
907 ext_id != extension_ids.end(); ++ext_id) {
908 int old_page_index(0);
909 int old_app_launch_index(0);
910
911 bool has_old_values = ReadExtensionPrefInteger(*ext_id,
912 kPrefPageIndexDeprecated,
913 &old_page_index);
914 has_old_values |= ReadExtensionPrefInteger(*ext_id,
915 kPrefAppLaunchIndexDeprecated,
916 &old_app_launch_index);
917
918 if (has_old_values) {
919 // Its ok to use both values, even if they weren't read, because this
920 // only affects the sorting, which can handle apps with the default
921 // integer values.
922 apps_to_convert.insert(ExtensionNTPOldPosition(
923 *ext_id, old_page_index, old_app_launch_index));
924 }
925 }
926
927 if (apps_to_convert.empty())
928 return;
929
930 // Create the new values and remove the old preferences.
931 for (std::set<ExtensionNTPOldPosition, SortByNTPOldPosition>::iterator ext =
932 apps_to_convert.begin(); ext != apps_to_convert.end(); ++ext) {
933 int old_page_index;
934 if (ReadExtensionPrefInteger(*(ext->extension_id),
935 kPrefPageIndexDeprecated,
936 &old_page_index)) {
937 SetPageIndex(*(ext->extension_id),
938 PageIndexAsStringOrdinal(old_page_index));
939 UpdateExtensionPref(*(ext->extension_id), kPrefPageIndexDeprecated, NULL);
940 }
941
942 int old_app_launch_index;
943 if (ReadExtensionPrefInteger(*(ext->extension_id),
944 kPrefAppLaunchIndexDeprecated,
945 &old_app_launch_index)) {
946 StringOrdinal page = GetPageIndex(*(ext->extension_id));
947 SetAppLaunchIndex(*(ext->extension_id),
948 GetNextAppLaunchIndex(page));
949 UpdateExtensionPref(
950 *(ext->extension_id), kPrefAppLaunchIndexDeprecated, NULL);
951 }
952 }
953 }
954
861 ExtensionPermissionSet* ExtensionPrefs::GetGrantedPermissions( 955 ExtensionPermissionSet* ExtensionPrefs::GetGrantedPermissions(
862 const std::string& extension_id) { 956 const std::string& extension_id) {
863 CHECK(Extension::IdIsValid(extension_id)); 957 CHECK(Extension::IdIsValid(extension_id));
864 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); 958 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions);
865 } 959 }
866 960
867 void ExtensionPrefs::AddGrantedPermissions( 961 void ExtensionPrefs::AddGrantedPermissions(
868 const std::string& extension_id, 962 const std::string& extension_id,
869 const ExtensionPermissionSet* permissions) { 963 const ExtensionPermissionSet* permissions) {
870 CHECK(Extension::IdIsValid(extension_id)); 964 CHECK(Extension::IdIsValid(extension_id));
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 iter != extension_ids.end(); ++iter) { 1159 iter != extension_ids.end(); ++iter) {
1066 toolbar_order->Append(new StringValue(*iter)); 1160 toolbar_order->Append(new StringValue(*iter));
1067 } 1161 }
1068 SavePrefs(); 1162 SavePrefs();
1069 } 1163 }
1070 1164
1071 void ExtensionPrefs::OnExtensionInstalled( 1165 void ExtensionPrefs::OnExtensionInstalled(
1072 const Extension* extension, 1166 const Extension* extension,
1073 Extension::State initial_state, 1167 Extension::State initial_state,
1074 bool from_webstore, 1168 bool from_webstore,
1075 int page_index) { 1169 StringOrdinal page_index) {
1076 const std::string& id = extension->id(); 1170 const std::string& id = extension->id();
1077 CHECK(Extension::IdIsValid(id)); 1171 CHECK(Extension::IdIsValid(id));
1078 ScopedExtensionPrefUpdate update(prefs_, id); 1172 ScopedExtensionPrefUpdate update(prefs_, id);
1079 DictionaryValue* extension_dict = update.Get(); 1173 DictionaryValue* extension_dict = update.Get();
1080 const base::Time install_time = GetCurrentTime(); 1174 const base::Time install_time = GetCurrentTime();
1081 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); 1175 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state));
1082 extension_dict->Set(kPrefLocation, 1176 extension_dict->Set(kPrefLocation,
1083 Value::CreateIntegerValue(extension->location())); 1177 Value::CreateIntegerValue(extension->location()));
1084 extension_dict->Set(kPrefFromWebStore, 1178 extension_dict->Set(kPrefFromWebStore,
1085 Value::CreateBooleanValue(from_webstore)); 1179 Value::CreateBooleanValue(from_webstore));
(...skipping 11 matching lines...) Expand all
1097 extension->path()); 1191 extension->path());
1098 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); 1192 extension_dict->Set(kPrefPath, Value::CreateStringValue(path));
1099 // We store prefs about LOAD extensions, but don't cache their manifest 1193 // We store prefs about LOAD extensions, but don't cache their manifest
1100 // since it may change on disk. 1194 // since it may change on disk.
1101 if (extension->location() != Extension::LOAD) { 1195 if (extension->location() != Extension::LOAD) {
1102 extension_dict->Set(kPrefManifest, 1196 extension_dict->Set(kPrefManifest,
1103 extension->manifest_value()->DeepCopy()); 1197 extension->manifest_value()->DeepCopy());
1104 } 1198 }
1105 1199
1106 if (extension->is_app()) { 1200 if (extension->is_app()) {
1107 if (page_index == -1) 1201 if (!page_index.IsValid())
1108 page_index = GetNaturalAppPageIndex(); 1202 page_index = GetNaturalAppPageIndex();
1109 extension_dict->Set(kPrefPageIndex, 1203 extension_dict->Set(kPrefPageIndex,
1110 Value::CreateIntegerValue(page_index)); 1204 Value::CreateStringValue(page_index.ToString()));
1205 UpdatePageIndexMap(StringOrdinal(), page_index);
1206
1111 extension_dict->Set(kPrefAppLaunchIndex, 1207 extension_dict->Set(kPrefAppLaunchIndex,
1112 Value::CreateIntegerValue(GetNextAppLaunchIndex(page_index))); 1208 Value::CreateStringValue(
1209 GetNextAppLaunchIndex(page_index).ToString()));
1113 } 1210 }
1114 extension_pref_value_map_->RegisterExtension( 1211 extension_pref_value_map_->RegisterExtension(
1115 id, install_time, initial_state == Extension::ENABLED); 1212 id, install_time, initial_state == Extension::ENABLED);
1116 content_settings_store_->RegisterExtension( 1213 content_settings_store_->RegisterExtension(
1117 id, install_time, initial_state == Extension::ENABLED); 1214 id, install_time, initial_state == Extension::ENABLED);
1118 } 1215 }
1119 1216
1120 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 1217 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
1121 const Extension::Location& location, 1218 const Extension::Location& location,
1122 bool external_uninstall) { 1219 bool external_uninstall) {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 return true; 1532 return true;
1436 } 1533 }
1437 return false; 1534 return false;
1438 } 1535 }
1439 1536
1440 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { 1537 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) {
1441 prefs_->SetString(kWebStoreLogin, login); 1538 prefs_->SetString(kWebStoreLogin, login);
1442 SavePrefs(); 1539 SavePrefs();
1443 } 1540 }
1444 1541
1445 int ExtensionPrefs::GetAppLaunchIndex(const std::string& extension_id) { 1542 void ExtensionPrefs::GetAllAppsOnPageSorted(
1446 int value; 1543 const StringOrdinal& target_page_index,
1447 if (ReadExtensionPrefInteger(extension_id, kPrefAppLaunchIndex, &value)) 1544 std::set<StringOrdinal, StringOrdinal::Comparsion>* indexes_on_page) {
1448 return value; 1545 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1546 if (!extensions || !target_page_index.IsValid())
1547 return;
1449 1548
1450 return -1; 1549 for (DictionaryValue::key_iterator ext_it = extensions->begin_keys();
1550 ext_it != extensions->end_keys(); ++ext_it) {
1551 StringOrdinal page_index = GetPageIndex(*ext_it);
1552 if (page_index.IsValid() && page_index.Equal(target_page_index)) {
1553 StringOrdinal app_launch_index = GetAppLaunchIndex(*ext_it);
1554 if (app_launch_index.IsValid())
1555 indexes_on_page->insert(app_launch_index);
1556 }
1557 }
1558 }
1559
1560 StringOrdinal ExtensionPrefs::GetFirstAppPage() {
1561 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1562 if (!extensions)
1563 return StringOrdinal();
1564
1565 if (page_index_map_.size() == 0)
1566 return StringOrdinal::CreateValidOrdinal();
1567
1568 return page_index_map_.begin()->first;
1569 }
1570
1571 StringOrdinal ExtensionPrefs::CreateFirstAppLaunchIndex(
1572 const StringOrdinal& page_index) {
1573 std::set<StringOrdinal, StringOrdinal::Comparsion> apps_on_page;
1574 GetAllAppsOnPageSorted(page_index, &apps_on_page);
1575
1576 if (apps_on_page.empty()) {
1577 return StringOrdinal::CreateValidOrdinal();
1578 } else {
1579 return apps_on_page.begin()->CreateBefore();
1580 }
1581 }
1582
1583 StringOrdinal ExtensionPrefs::GetAppLaunchIndex(
1584 const std::string& extension_id) {
1585 std::string raw_value;
1586 ReadExtensionPrefString(extension_id, kPrefAppLaunchIndex, &raw_value);
1587 return StringOrdinal(raw_value);
1451 } 1588 }
1452 1589
1453 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id, 1590 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id,
1454 int index) { 1591 const StringOrdinal& index) {
1455 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex, 1592 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex,
1456 Value::CreateIntegerValue(index)); 1593 Value::CreateStringValue(index.ToString()));
1457 } 1594 }
1458 1595
1459 int ExtensionPrefs::GetNextAppLaunchIndex(int on_page) { 1596 StringOrdinal ExtensionPrefs::GetNextAppLaunchIndex(StringOrdinal on_page) {
1460 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1597 std::set<StringOrdinal, StringOrdinal::Comparsion> apps_on_page;
1461 if (!extensions) 1598 GetAllAppsOnPageSorted(on_page, &apps_on_page);
1462 return 0;
1463 1599
1464 int max_value = -1; 1600 if (apps_on_page.empty()) {
1465 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 1601 return StringOrdinal::CreateValidOrdinal();
1466 extension_id != extensions->end_keys(); ++extension_id) { 1602 } else {
1467 int value = GetAppLaunchIndex(*extension_id); 1603 return apps_on_page.rbegin()->CreateAfter();
1468 int page = GetPageIndex(*extension_id);
1469 if (page == on_page && value > max_value)
1470 max_value = value;
1471 }
1472 return max_value + 1;
1473 }
1474
1475 int ExtensionPrefs::GetNaturalAppPageIndex() {
1476 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1477 if (!extensions)
1478 return 0;
1479
1480 std::map<int, int> page_counts;
1481 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
1482 extension_id != extensions->end_keys(); ++extension_id) {
1483 int page_index = GetPageIndex(*extension_id);
1484 if (page_index >= 0)
1485 page_counts[page_index] = page_counts[page_index] + 1;
1486 }
1487 for (int i = 0; ; i++) {
1488 std::map<int, int>::const_iterator it = page_counts.find(i);
1489 if (it == page_counts.end() || it->second < kNaturalAppPageSize)
1490 return i;
1491 } 1604 }
1492 } 1605 }
1493 1606
1607 StringOrdinal ExtensionPrefs::GetNaturalAppPageIndex() {
1608 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1609 if (!extensions)
1610 return StringOrdinal();
1611
1612 if (page_index_map_.size() == 0) {
1613 return StringOrdinal::CreateValidOrdinal();
1614 }
1615
1616 std::map<StringOrdinal, int>::const_iterator it = page_index_map_.begin();
1617 for (; it != page_index_map_.end(); ++it) {
1618 if (it->second < kNaturalAppPageSize) {
1619 return it->first;
1620 }
1621 }
1622
1623 // Add a new page as all existing pages are full.
1624 StringOrdinal last_element = page_index_map_.rbegin()->first;
1625 return last_element.CreateAfter();
1626 }
1627
1494 void ExtensionPrefs::SetAppLauncherOrder( 1628 void ExtensionPrefs::SetAppLauncherOrder(
1495 const std::vector<std::string>& extension_ids) { 1629 const std::vector<std::string>& extension_ids,
1496 for (size_t i = 0; i < extension_ids.size(); ++i) 1630 const std::string& moved_extension_id) {
1497 SetAppLaunchIndex(extension_ids.at(i), i); 1631 std::vector<std::string>::const_iterator it =
1632 find(extension_ids.begin(), extension_ids.end(), moved_extension_id);
1633 size_t position = std::distance(extension_ids.begin(), it);
1634
Dan Beam 2011/11/12 02:28:30 Can you put some comments here? Wtfs/line ratio c
csharp 2011/11/14 16:22:28 Added some comments, let me know if they clear thi
1635 if (extension_ids.size() < 2) {
1636 SetAppLaunchIndex(moved_extension_id, StringOrdinal::CreateValidOrdinal());
1637 } else if (position == 0U) {
1638 ++it;
1639 SetAppLaunchIndex(moved_extension_id,
1640 GetAppLaunchIndex(*it).CreateBefore());
1641 } else if (position == extension_ids.size() - 1U) {
1642 --it;
1643 SetAppLaunchIndex(moved_extension_id, GetAppLaunchIndex(*it).CreateAfter());
1644 } else {
1645 ++it;
1646 StringOrdinal value_after = GetAppLaunchIndex(*it);
1647 advance(it, -2);
1648 StringOrdinal value_before = GetAppLaunchIndex(*it);
1649 SetAppLaunchIndex(moved_extension_id,
1650 value_before.CreateBetween(value_after));
1651 }
1498 1652
1499 content::NotificationService::current()->Notify( 1653 content::NotificationService::current()->Notify(
1500 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, 1654 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
1501 content::Source<ExtensionPrefs>(this), 1655 content::Source<ExtensionPrefs>(this),
1502 content::NotificationService::NoDetails()); 1656 content::NotificationService::NoDetails());
1503 } 1657 }
1504 1658
1505 int ExtensionPrefs::GetPageIndex(const std::string& extension_id) { 1659 StringOrdinal ExtensionPrefs::GetPageIndex(const std::string& extension_id) {
1506 int value = -1; 1660 std::string raw_string_data;
1507 ReadExtensionPrefInteger(extension_id, kPrefPageIndex, &value); 1661 ReadExtensionPrefString(extension_id, kPrefPageIndex, &raw_string_data);
1508 return value; 1662 return StringOrdinal(raw_string_data);
1509 } 1663 }
1510 1664
1511 void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index) { 1665 void ExtensionPrefs::SetPageIndex(const std::string& extension_id,
1666 const StringOrdinal& page_index) {
1667 UpdatePageIndexMap(GetPageIndex(extension_id), page_index);
1512 UpdateExtensionPref(extension_id, kPrefPageIndex, 1668 UpdateExtensionPref(extension_id, kPrefPageIndex,
1513 Value::CreateIntegerValue(index)); 1669 Value::CreateStringValue(page_index.ToString()));
1514 } 1670 }
1515 1671
1516 void ExtensionPrefs::ClearPageIndex(const std::string& extension_id) { 1672 void ExtensionPrefs::ClearPageIndex(const std::string& extension_id) {
1673 UpdatePageIndexMap(GetPageIndex(extension_id), StringOrdinal());
1517 UpdateExtensionPref(extension_id, kPrefPageIndex, NULL); 1674 UpdateExtensionPref(extension_id, kPrefPageIndex, NULL);
1518 } 1675 }
1519 1676
1677 void ExtensionPrefs::InitializePageIndexMap(
1678 const ExtensionIdSet& extension_ids) {
1679 for (ExtensionIdSet::const_iterator ext_it = extension_ids.begin();
1680 ext_it != extension_ids.end(); ++ext_it) {
1681 UpdatePageIndexMap(StringOrdinal(), GetPageIndex(*ext_it));
1682 }
1683 }
1684
1685 void ExtensionPrefs::UpdatePageIndexMap(const StringOrdinal& old_value,
1686 const StringOrdinal& new_value) {
1687 if (new_value.IsValid())
1688 ++page_index_map_[new_value];
1689
1690 if (old_value.IsValid()) {
1691 --page_index_map_[old_value];
1692
1693 if (page_index_map_[old_value] == 0)
1694 page_index_map_.erase(old_value);
1695 }
1696 }
1697
1698 int ExtensionPrefs::PageIndexAsInteger(const StringOrdinal& page_index) {
1699 if (!page_index.IsValid())
1700 return -1;
1701
1702 std::map<StringOrdinal, int>::iterator it = page_index_map_.find(page_index);
1703 if (it != page_index_map_.end()) {
1704 return std::distance(page_index_map_.begin(), it);
1705 } else {
1706 return -1;
1707 }
1708 }
1709
1710 StringOrdinal ExtensionPrefs::PageIndexAsStringOrdinal(size_t page_index) {
1711 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1712 if (!extensions)
1713 return StringOrdinal();
1714
1715 if (page_index_map_.size() == 0) {
1716 return StringOrdinal::CreateValidOrdinal();
1717 }
1718
1719 if (page_index < page_index_map_.size()) {
1720 std::map<StringOrdinal, int, StringOrdinal::Comparsion>::iterator it =
1721 page_index_map_.begin();
1722 advance(it, page_index);
1723
1724 return it->first;
1725 } else {
1726 // Create new pages until we reach the desired index.
1727 while (page_index >= page_index_map_.size()) {
1728 StringOrdinal new_page = page_index_map_.rbegin()->first.CreateAfter();
1729 page_index_map_[new_page] = 0;
1730 }
1731 return page_index_map_.rbegin()->first;
1732 }
1733 }
1734
1520 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { 1735 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
1521 return ReadExtensionPrefBoolean(extension_id, kPrefUserDraggedApp); 1736 return ReadExtensionPrefBoolean(extension_id, kPrefUserDraggedApp);
1522 } 1737 }
1523 1738
1524 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { 1739 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
1525 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, 1740 UpdateExtensionPref(extension_id, kPrefUserDraggedApp,
1526 Value::CreateBooleanValue(true)); 1741 Value::CreateBooleanValue(true));
1527 } 1742 }
1528 1743
1529 void ExtensionPrefs::SetUpdateUrlData(const std::string& extension_id, 1744 void ExtensionPrefs::SetUpdateUrlData(const std::string& extension_id,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 // Create empty preferences dictionary for each extension (these dictionaries 1869 // Create empty preferences dictionary for each extension (these dictionaries
1655 // are pruned when persisting the preferences to disk). 1870 // are pruned when persisting the preferences to disk).
1656 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); 1871 for (ExtensionIdSet::iterator ext_id = extension_ids.begin();
1657 ext_id != extension_ids.end(); ++ext_id) { 1872 ext_id != extension_ids.end(); ++ext_id) {
1658 ScopedExtensionPrefUpdate update(prefs_, *ext_id); 1873 ScopedExtensionPrefUpdate update(prefs_, *ext_id);
1659 // This creates an empty dictionary if none is stored. 1874 // This creates an empty dictionary if none is stored.
1660 update.Get(); 1875 update.Get();
1661 } 1876 }
1662 1877
1663 FixMissingPrefs(extension_ids); 1878 FixMissingPrefs(extension_ids);
1879 InitializePageIndexMap(extension_ids);
1664 MigratePermissions(extension_ids); 1880 MigratePermissions(extension_ids);
1881 MigrateAppIndex(extension_ids);
1665 1882
1666 // Store extension controlled preference values in the 1883 // Store extension controlled preference values in the
1667 // |extension_pref_value_map_|, which then informs the subscribers 1884 // |extension_pref_value_map_|, which then informs the subscribers
1668 // (ExtensionPrefStores) about the winning values. 1885 // (ExtensionPrefStores) about the winning values.
1669 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); 1886 for (ExtensionIdSet::iterator ext_id = extension_ids.begin();
1670 ext_id != extension_ids.end(); ++ext_id) { 1887 ext_id != extension_ids.end(); ++ext_id) {
1671 extension_pref_value_map_->RegisterExtension( 1888 extension_pref_value_map_->RegisterExtension(
1672 *ext_id, 1889 *ext_id,
1673 GetInstallTime(*ext_id), 1890 GetInstallTime(*ext_id),
1674 !IsExtensionDisabled(*ext_id)); 1891 !IsExtensionDisabled(*ext_id));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, 2047 prefs->RegisterListPref(prefs::kExtensionInstallAllowList,
1831 PrefService::UNSYNCABLE_PREF); 2048 PrefService::UNSYNCABLE_PREF);
1832 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, 2049 prefs->RegisterListPref(prefs::kExtensionInstallDenyList,
1833 PrefService::UNSYNCABLE_PREF); 2050 PrefService::UNSYNCABLE_PREF);
1834 prefs->RegisterListPref(prefs::kExtensionInstallForceList, 2051 prefs->RegisterListPref(prefs::kExtensionInstallForceList,
1835 PrefService::UNSYNCABLE_PREF); 2052 PrefService::UNSYNCABLE_PREF);
1836 prefs->RegisterStringPref(kWebStoreLogin, 2053 prefs->RegisterStringPref(kWebStoreLogin,
1837 std::string() /* default_value */, 2054 std::string() /* default_value */,
1838 PrefService::UNSYNCABLE_PREF); 2055 PrefService::UNSYNCABLE_PREF);
1839 } 2056 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698