Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 ExtensionSorting::AppOrdinals::~AppOrdinals() {} | 44 ExtensionSorting::AppOrdinals::~AppOrdinals() {} |
| 45 | 45 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 47 // ExtensionSorting | 47 // ExtensionSorting |
| 48 | 48 |
| 49 ExtensionSorting::ExtensionSorting(ExtensionScopedPrefs* extension_scoped_prefs, | 49 ExtensionSorting::ExtensionSorting(ExtensionScopedPrefs* extension_scoped_prefs, |
| 50 PrefService* pref_service) | 50 PrefService* pref_service) |
| 51 : extension_scoped_prefs_(extension_scoped_prefs), | 51 : extension_scoped_prefs_(extension_scoped_prefs), |
| 52 pref_service_(pref_service), | 52 pref_service_(pref_service), |
| 53 extension_service_(NULL) { | 53 extension_service_(NULL) { |
| 54 CreateDefaultOrdinals(); | |
| 55 } | 54 } |
| 56 | 55 |
| 57 ExtensionSorting::~ExtensionSorting() { | 56 ExtensionSorting::~ExtensionSorting() { |
| 58 } | 57 } |
| 59 | 58 |
| 60 void ExtensionSorting::SetExtensionService( | 59 void ExtensionSorting::SetExtensionService( |
| 61 ExtensionServiceInterface* extension_service) { | 60 ExtensionServiceInterface* extension_service) { |
| 62 extension_service_ = extension_service; | 61 extension_service_ = extension_service; |
| 63 } | 62 } |
| 64 | 63 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 // shouldn't so we clear them. | 539 // shouldn't so we clear them. |
| 541 if (!ext->is_app()) | 540 if (!ext->is_app()) |
| 542 ClearOrdinals(extension_id); | 541 ClearOrdinals(extension_id); |
| 543 | 542 |
| 544 extension_service_->SyncExtensionChangeIfNeeded(*ext); | 543 extension_service_->SyncExtensionChangeIfNeeded(*ext); |
| 545 } | 544 } |
| 546 } | 545 } |
| 547 } | 546 } |
| 548 | 547 |
| 549 void ExtensionSorting::CreateDefaultOrdinals() { | 548 void ExtensionSorting::CreateDefaultOrdinals() { |
| 549 static bool s_default_ordinales_created = false; | |
|
csharp
2013/05/24 18:06:22
Why isn't this a class variable?
xiyuan
2013/05/24 18:09:13
Right, this needs to be fixed. The flag has to be
stevenjb
2013/05/24 18:16:02
Ugh, I've been working too much with statics and a
| |
| 550 if (s_default_ordinales_created) | |
| 551 return; | |
| 552 s_default_ordinales_created = true; | |
| 553 | |
| 550 // The following defines the default order of apps. | 554 // The following defines the default order of apps. |
| 551 #if defined(OS_CHROMEOS) | 555 #if defined(OS_CHROMEOS) |
| 552 std::vector<std::string> app_ids; | 556 std::vector<std::string> app_ids; |
| 553 chromeos::default_app_order::Get(&app_ids); | 557 chromeos::default_app_order::Get(&app_ids); |
| 554 #else | 558 #else |
| 555 const char* kDefaultAppOrder[] = { | 559 const char* kDefaultAppOrder[] = { |
| 556 extension_misc::kWebStoreAppId, | 560 extension_misc::kWebStoreAppId, |
| 557 }; | 561 }; |
| 558 const std::vector<const char*> app_ids( | 562 const std::vector<const char*> app_ids( |
| 559 kDefaultAppOrder, kDefaultAppOrder + arraysize(kDefaultAppOrder)); | 563 kDefaultAppOrder, kDefaultAppOrder + arraysize(kDefaultAppOrder)); |
| 560 #endif | 564 #endif |
| 561 | 565 |
| 562 syncer::StringOrdinal page_ordinal = CreateFirstAppPageOrdinal(); | 566 syncer::StringOrdinal page_ordinal = CreateFirstAppPageOrdinal(); |
| 563 syncer::StringOrdinal app_launch_ordinal = | 567 syncer::StringOrdinal app_launch_ordinal = |
| 564 CreateFirstAppLaunchOrdinal(page_ordinal); | 568 CreateFirstAppLaunchOrdinal(page_ordinal); |
| 565 for (size_t i = 0; i < app_ids.size(); ++i) { | 569 for (size_t i = 0; i < app_ids.size(); ++i) { |
| 566 const std::string extension_id = app_ids[i]; | 570 const std::string extension_id = app_ids[i]; |
| 567 default_ordinals_[extension_id].page_ordinal = page_ordinal; | 571 default_ordinals_[extension_id].page_ordinal = page_ordinal; |
| 568 default_ordinals_[extension_id].app_launch_ordinal = app_launch_ordinal; | 572 default_ordinals_[extension_id].app_launch_ordinal = app_launch_ordinal; |
| 569 app_launch_ordinal = app_launch_ordinal.CreateAfter(); | 573 app_launch_ordinal = app_launch_ordinal.CreateAfter(); |
| 570 } | 574 } |
| 571 } | 575 } |
| 572 | 576 |
| 573 bool ExtensionSorting::GetDefaultOrdinals( | 577 bool ExtensionSorting::GetDefaultOrdinals( |
| 574 const std::string& extension_id, | 578 const std::string& extension_id, |
| 575 syncer::StringOrdinal* page_ordinal, | 579 syncer::StringOrdinal* page_ordinal, |
| 576 syncer::StringOrdinal* app_launch_ordinal) const { | 580 syncer::StringOrdinal* app_launch_ordinal) { |
| 581 CreateDefaultOrdinals(); | |
| 577 AppOrdinalsMap::const_iterator it = default_ordinals_.find(extension_id); | 582 AppOrdinalsMap::const_iterator it = default_ordinals_.find(extension_id); |
| 578 if (it == default_ordinals_.end()) | 583 if (it == default_ordinals_.end()) |
| 579 return false; | 584 return false; |
| 580 | 585 |
| 581 if (page_ordinal) | 586 if (page_ordinal) |
| 582 *page_ordinal = it->second.page_ordinal; | 587 *page_ordinal = it->second.page_ordinal; |
| 583 if (app_launch_ordinal) | 588 if (app_launch_ordinal) |
| 584 *app_launch_ordinal = it->second.app_launch_ordinal; | 589 *app_launch_ordinal = it->second.app_launch_ordinal; |
| 585 return true; | 590 return true; |
| 586 } | 591 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 const AppLaunchOrdinalMap& m) const { | 623 const AppLaunchOrdinalMap& m) const { |
| 619 size_t result = 0; | 624 size_t result = 0; |
| 620 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); | 625 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); |
| 621 ++it) { | 626 ++it) { |
| 622 const std::string& id = it->second; | 627 const std::string& id = it->second; |
| 623 if (ntp_hidden_extensions_.count(id) == 0) | 628 if (ntp_hidden_extensions_.count(id) == 0) |
| 624 result++; | 629 result++; |
| 625 } | 630 } |
| 626 return result; | 631 return result; |
| 627 } | 632 } |
| OLD | NEW |