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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 syncer::StringOrdinal ExtensionSorting::GetNaturalAppPageOrdinal() const { | 357 syncer::StringOrdinal ExtensionSorting::GetNaturalAppPageOrdinal() const { |
358 const DictionaryValue* extensions = pref_service_->GetDictionary( | 358 const DictionaryValue* extensions = pref_service_->GetDictionary( |
359 ExtensionPrefs::kExtensionsPref); | 359 ExtensionPrefs::kExtensionsPref); |
360 CHECK(extensions); | 360 CHECK(extensions); |
361 | 361 |
362 if (ntp_ordinal_map_.empty()) | 362 if (ntp_ordinal_map_.empty()) |
363 return syncer::StringOrdinal::CreateInitialOrdinal(); | 363 return syncer::StringOrdinal::CreateInitialOrdinal(); |
364 | 364 |
365 for (PageOrdinalMap::const_iterator it = ntp_ordinal_map_.begin(); | 365 for (PageOrdinalMap::const_iterator it = ntp_ordinal_map_.begin(); |
366 it != ntp_ordinal_map_.end(); ++it) { | 366 it != ntp_ordinal_map_.end(); ++it) { |
367 if (it->second.size() < kNaturalAppPageSize) | 367 if (CountItemsVisibleOnNtp(it->second) < kNaturalAppPageSize) |
368 return it->first; | 368 return it->first; |
369 } | 369 } |
370 | 370 |
371 // Add a new page as all existing pages are full. | 371 // Add a new page as all existing pages are full. |
372 syncer::StringOrdinal last_element = ntp_ordinal_map_.rbegin()->first; | 372 syncer::StringOrdinal last_element = ntp_ordinal_map_.rbegin()->first; |
373 return last_element.CreateAfter(); | 373 return last_element.CreateAfter(); |
374 } | 374 } |
375 | 375 |
376 syncer::StringOrdinal ExtensionSorting::GetPageOrdinal( | 376 syncer::StringOrdinal ExtensionSorting::GetPageOrdinal( |
377 const std::string& extension_id) const { | 377 const std::string& extension_id) const { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 if (page_index < ntp_ordinal_map_.size()) { | 438 if (page_index < ntp_ordinal_map_.size()) { |
439 PageOrdinalMap::const_iterator it = ntp_ordinal_map_.begin(); | 439 PageOrdinalMap::const_iterator it = ntp_ordinal_map_.begin(); |
440 std::advance(it, page_index); | 440 std::advance(it, page_index); |
441 return it->first; | 441 return it->first; |
442 } | 442 } |
443 | 443 |
444 CreateOrdinalsIfNecessary(page_index + 1); | 444 CreateOrdinalsIfNecessary(page_index + 1); |
445 return ntp_ordinal_map_.rbegin()->first; | 445 return ntp_ordinal_map_.rbegin()->first; |
446 } | 446 } |
447 | 447 |
| 448 void ExtensionSorting::MarkExtensionAsHidden(const std::string& extension_id) { |
| 449 ntp_hidden_extensions_.insert(extension_id); |
| 450 } |
| 451 |
448 syncer::StringOrdinal ExtensionSorting::GetMinOrMaxAppLaunchOrdinalsOnPage( | 452 syncer::StringOrdinal ExtensionSorting::GetMinOrMaxAppLaunchOrdinalsOnPage( |
449 const syncer::StringOrdinal& target_page_ordinal, | 453 const syncer::StringOrdinal& target_page_ordinal, |
450 AppLaunchOrdinalReturn return_type) const { | 454 AppLaunchOrdinalReturn return_type) const { |
451 CHECK(target_page_ordinal.IsValid()); | 455 CHECK(target_page_ordinal.IsValid()); |
452 | 456 |
453 syncer::StringOrdinal return_value; | 457 syncer::StringOrdinal return_value; |
454 | 458 |
455 PageOrdinalMap::const_iterator page = | 459 PageOrdinalMap::const_iterator page = |
456 ntp_ordinal_map_.find(target_page_ordinal); | 460 ntp_ordinal_map_.find(target_page_ordinal); |
457 if (page != ntp_ordinal_map_.end()) { | 461 if (page != ntp_ordinal_map_.end()) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 ++app_it; | 607 ++app_it; |
604 | 608 |
605 // If there is no next after the collision, returns the next ordinal. | 609 // If there is no next after the collision, returns the next ordinal. |
606 if (app_it == page.end()) | 610 if (app_it == page.end()) |
607 return app_launch_ordinal.CreateAfter(); | 611 return app_launch_ordinal.CreateAfter(); |
608 | 612 |
609 // Otherwise, returns the ordinal between the collision and the next ordinal. | 613 // Otherwise, returns the ordinal between the collision and the next ordinal. |
610 return app_launch_ordinal.CreateBetween(app_it->first); | 614 return app_launch_ordinal.CreateBetween(app_it->first); |
611 } | 615 } |
612 | 616 |
| 617 size_t ExtensionSorting::CountItemsVisibleOnNtp( |
| 618 const AppLaunchOrdinalMap& m) const { |
| 619 size_t result = 0; |
| 620 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); |
| 621 ++it) { |
| 622 const std::string& id = it->second; |
| 623 if (ntp_hidden_extensions_.count(id) == 0) |
| 624 result++; |
| 625 } |
| 626 return result; |
| 627 } |
OLD | NEW |