OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_sorting.h" | 5 #include "chrome/browser/extensions/extension_sorting.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_scoped_prefs.h" | 7 #include "chrome/browser/extensions/extension_scoped_prefs.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 ExtensionSorting::~ExtensionSorting() { | 38 ExtensionSorting::~ExtensionSorting() { |
39 } | 39 } |
40 | 40 |
41 void ExtensionSorting::SetExtensionService( | 41 void ExtensionSorting::SetExtensionService( |
42 ExtensionServiceInterface* extension_service) { | 42 ExtensionServiceInterface* extension_service) { |
43 extension_service_ = extension_service; | 43 extension_service_ = extension_service; |
44 } | 44 } |
45 | 45 |
46 void ExtensionSorting::Initialize( | 46 void ExtensionSorting::Initialize( |
47 const ExtensionPrefs::ExtensionIdSet& extension_ids) { | 47 const ExtensionPrefs::ExtensionIds& extension_ids) { |
48 InitializePageOrdinalMap(extension_ids); | 48 InitializePageOrdinalMap(extension_ids); |
49 | 49 |
50 MigrateAppIndex(extension_ids); | 50 MigrateAppIndex(extension_ids); |
51 } | 51 } |
52 | 52 |
53 void ExtensionSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { | 53 void ExtensionSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { |
54 // Create StringOrdinal values as required to ensure |ntp_ordinal_map_| has at | 54 // Create StringOrdinal values as required to ensure |ntp_ordinal_map_| has at |
55 // least |minimum_size| entries. | 55 // least |minimum_size| entries. |
56 if (ntp_ordinal_map_.empty() && minimum_size > 0) | 56 if (ntp_ordinal_map_.empty() && minimum_size > 0) |
57 ntp_ordinal_map_[StringOrdinal::CreateInitialOrdinal()]; | 57 ntp_ordinal_map_[StringOrdinal::CreateInitialOrdinal()]; |
58 | 58 |
59 while (ntp_ordinal_map_.size() < minimum_size) { | 59 while (ntp_ordinal_map_.size() < minimum_size) { |
60 StringOrdinal filler = ntp_ordinal_map_.rbegin()->first.CreateAfter(); | 60 StringOrdinal filler = ntp_ordinal_map_.rbegin()->first.CreateAfter(); |
61 AppLaunchOrdinalMap empty_ordinal_map; | 61 AppLaunchOrdinalMap empty_ordinal_map; |
62 ntp_ordinal_map_.insert(std::make_pair(filler, empty_ordinal_map)); | 62 ntp_ordinal_map_.insert(std::make_pair(filler, empty_ordinal_map)); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void ExtensionSorting::MigrateAppIndex( | 66 void ExtensionSorting::MigrateAppIndex( |
67 const ExtensionPrefs::ExtensionIdSet& extension_ids) { | 67 const ExtensionPrefs::ExtensionIds& extension_ids) { |
68 if (extension_ids.empty()) | 68 if (extension_ids.empty()) |
69 return; | 69 return; |
70 | 70 |
71 // Convert all the page index values to page ordinals. If there are any | 71 // Convert all the page index values to page ordinals. If there are any |
72 // app launch values that need to be migrated, inserted them into a sorted | 72 // app launch values that need to be migrated, inserted them into a sorted |
73 // set to be dealt with later. | 73 // set to be dealt with later. |
74 typedef std::map<StringOrdinal, std::map<int, const std::string*>, | 74 typedef std::map<StringOrdinal, std::map<int, const std::string*>, |
75 StringOrdinalLessThan> AppPositionToIdMapping; | 75 StringOrdinalLessThan> AppPositionToIdMapping; |
76 AppPositionToIdMapping app_launches_to_convert; | 76 AppPositionToIdMapping app_launches_to_convert; |
77 for (ExtensionPrefs::ExtensionIdSet::const_iterator ext_id = | 77 for (ExtensionPrefs::ExtensionIds::const_iterator ext_id = |
78 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { | 78 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { |
79 int old_page_index = 0; | 79 int old_page_index = 0; |
80 StringOrdinal page = GetPageOrdinal(*ext_id); | 80 StringOrdinal page = GetPageOrdinal(*ext_id); |
81 if (extension_scoped_prefs_->ReadExtensionPrefInteger( | 81 if (extension_scoped_prefs_->ReadExtensionPrefInteger( |
82 *ext_id, | 82 *ext_id, |
83 kPrefPageIndexDeprecated, | 83 kPrefPageIndexDeprecated, |
84 &old_page_index)) { | 84 &old_page_index)) { |
85 // Some extensions have invalid page index, so we don't | 85 // Some extensions have invalid page index, so we don't |
86 // attempt to convert them. | 86 // attempt to convert them. |
87 if (old_page_index < 0) { | 87 if (old_page_index < 0) { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (return_type == ExtensionSorting::MAX_ORDINAL) | 434 if (return_type == ExtensionSorting::MAX_ORDINAL) |
435 return_value = app_list.rbegin()->first; | 435 return_value = app_list.rbegin()->first; |
436 else if (return_type == ExtensionSorting::MIN_ORDINAL) | 436 else if (return_type == ExtensionSorting::MIN_ORDINAL) |
437 return_value = app_list.begin()->first; | 437 return_value = app_list.begin()->first; |
438 } | 438 } |
439 | 439 |
440 return return_value; | 440 return return_value; |
441 } | 441 } |
442 | 442 |
443 void ExtensionSorting::InitializePageOrdinalMap( | 443 void ExtensionSorting::InitializePageOrdinalMap( |
444 const ExtensionPrefs::ExtensionIdSet& extension_ids) { | 444 const ExtensionPrefs::ExtensionIds& extension_ids) { |
445 for (ExtensionPrefs::ExtensionIdSet::const_iterator ext_it = | 445 for (ExtensionPrefs::ExtensionIds::const_iterator ext_it = |
446 extension_ids.begin(); ext_it != extension_ids.end(); ++ext_it) { | 446 extension_ids.begin(); ext_it != extension_ids.end(); ++ext_it) { |
447 AddOrdinalMapping(*ext_it, | 447 AddOrdinalMapping(*ext_it, |
448 GetPageOrdinal(*ext_it), | 448 GetPageOrdinal(*ext_it), |
449 GetAppLaunchOrdinal(*ext_it)); | 449 GetAppLaunchOrdinal(*ext_it)); |
450 | 450 |
451 // Ensure that the web store app still isn't found in this list, since | 451 // Ensure that the web store app still isn't found in this list, since |
452 // it is added after this loop. | 452 // it is added after this loop. |
453 DCHECK(*ext_it != extension_misc::kWebStoreAppId); | 453 DCHECK(*ext_it != extension_misc::kWebStoreAppId); |
454 } | 454 } |
455 | 455 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 if (ext) { | 505 if (ext) { |
506 // It is possible for old extension to have ordinal values, but they | 506 // It is possible for old extension to have ordinal values, but they |
507 // shouldn't so we clear them. | 507 // shouldn't so we clear them. |
508 if (!ext->is_app()) | 508 if (!ext->is_app()) |
509 ClearOrdinals(extension_id); | 509 ClearOrdinals(extension_id); |
510 | 510 |
511 extension_service_->SyncExtensionChangeIfNeeded(*ext); | 511 extension_service_->SyncExtensionChangeIfNeeded(*ext); |
512 } | 512 } |
513 } | 513 } |
514 } | 514 } |
OLD | NEW |