Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chrome_app_sorting.h" | 5 #include "chrome/browser/extensions/chrome_app_sorting.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 11 #include "chrome/browser/extensions/extension_sync_service.h" | 12 #include "chrome/browser/extensions/extension_sync_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 14 #include "extensions/browser/extension_scoped_prefs.h" | 16 #include "extensions/browser/extension_scoped_prefs.h" |
| 17 #include "extensions/browser/extension_system.h" | |
| 15 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 16 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 17 | 20 |
| 18 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
| 19 #include "chrome/browser/chromeos/extensions/default_app_order.h" | 22 #include "chrome/browser/chromeos/extensions/default_app_order.h" |
| 20 #endif | 23 #endif |
| 21 | 24 |
| 22 namespace extensions { | 25 namespace extensions { |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 40 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 41 // ChromeAppSorting::AppOrdinals | 44 // ChromeAppSorting::AppOrdinals |
| 42 | 45 |
| 43 ChromeAppSorting::AppOrdinals::AppOrdinals() {} | 46 ChromeAppSorting::AppOrdinals::AppOrdinals() {} |
| 44 | 47 |
| 45 ChromeAppSorting::AppOrdinals::~AppOrdinals() {} | 48 ChromeAppSorting::AppOrdinals::~AppOrdinals() {} |
| 46 | 49 |
| 47 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
| 48 // ChromeAppSorting | 51 // ChromeAppSorting |
| 49 | 52 |
| 50 ChromeAppSorting::ChromeAppSorting() | 53 ChromeAppSorting::ChromeAppSorting(content::BrowserContext* browser_context) |
| 51 : extension_scoped_prefs_(NULL), | 54 : extension_scoped_prefs_(NULL), |
| 52 extension_sync_service_(NULL), | 55 browser_context_(browser_context), |
| 53 default_ordinals_created_(false) { | 56 default_ordinals_created_(false) { |
| 54 } | 57 } |
| 55 | 58 |
| 56 ChromeAppSorting::~ChromeAppSorting() { | 59 ChromeAppSorting::~ChromeAppSorting() { |
| 57 } | 60 } |
| 58 | 61 |
| 59 void ChromeAppSorting::SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) { | 62 void ChromeAppSorting::SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) { |
| 60 extension_scoped_prefs_ = prefs; | 63 extension_scoped_prefs_ = prefs; |
| 61 } | 64 } |
| 62 | 65 |
| 63 void ChromeAppSorting::CheckExtensionScopedPrefs() const { | 66 void ChromeAppSorting::CheckExtensionScopedPrefs() const { |
| 64 CHECK(extension_scoped_prefs_); | 67 CHECK(extension_scoped_prefs_); |
| 65 } | 68 } |
| 66 | 69 |
| 67 void ChromeAppSorting::SetExtensionSyncService( | |
| 68 ExtensionSyncService* extension_sync_service) { | |
| 69 extension_sync_service_ = extension_sync_service; | |
| 70 } | |
| 71 | |
| 72 void ChromeAppSorting::Initialize( | 70 void ChromeAppSorting::Initialize( |
| 73 const extensions::ExtensionIdList& extension_ids) { | 71 const extensions::ExtensionIdList& extension_ids) { |
| 74 CHECK(extension_scoped_prefs_); | 72 CHECK(extension_scoped_prefs_); |
| 75 InitializePageOrdinalMap(extension_ids); | 73 InitializePageOrdinalMap(extension_ids); |
| 76 | 74 |
| 77 MigrateAppIndex(extension_ids); | 75 MigrateAppIndex(extension_ids); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void ChromeAppSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { | 78 void ChromeAppSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { |
| 81 // Create StringOrdinal values as required to ensure |ntp_ordinal_map_| has at | 79 // Create StringOrdinal values as required to ensure |ntp_ordinal_map_| has at |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 page_map->second.find(app_launch_ordinal); | 534 page_map->second.find(app_launch_ordinal); |
| 537 it != page_map->second.end(); ++it) { | 535 it != page_map->second.end(); ++it) { |
| 538 if (it->second == extension_id) { | 536 if (it->second == extension_id) { |
| 539 page_map->second.erase(it); | 537 page_map->second.erase(it); |
| 540 break; | 538 break; |
| 541 } | 539 } |
| 542 } | 540 } |
| 543 } | 541 } |
| 544 | 542 |
| 545 void ChromeAppSorting::SyncIfNeeded(const std::string& extension_id) { | 543 void ChromeAppSorting::SyncIfNeeded(const std::string& extension_id) { |
| 546 if (extension_sync_service_) | 544 if (!browser_context_) |
|
not at google - send to devlin
2015/07/23 15:35:11
Comment // null for testing.
Marc Treib
2015/07/24 11:38:34
Done.
| |
| 547 extension_sync_service_->SyncOrderingChange(extension_id); | 545 return; |
| 546 | |
| 547 ExtensionService* service = | |
| 548 ExtensionSystem::Get(browser_context_)->extension_service(); | |
| 549 const Extension* extension = service->GetInstalledExtension(extension_id); | |
|
not at google - send to devlin
2015/07/23 15:35:11
Better:
ExtensionRegistry* registry = ExtensionRe
Marc Treib
2015/07/24 11:38:34
Done.
| |
| 550 if (extension) { | |
| 551 Profile* profile = Profile::FromBrowserContext(browser_context_); | |
| 552 ExtensionSyncService::Get(profile)->SyncExtensionChangeIfNeeded(*extension); | |
| 553 } | |
| 548 } | 554 } |
| 549 | 555 |
| 550 void ChromeAppSorting::CreateDefaultOrdinals() { | 556 void ChromeAppSorting::CreateDefaultOrdinals() { |
| 551 if (default_ordinals_created_) | 557 if (default_ordinals_created_) |
| 552 return; | 558 return; |
| 553 default_ordinals_created_ = true; | 559 default_ordinals_created_ = true; |
| 554 | 560 |
| 555 // The following defines the default order of apps. | 561 // The following defines the default order of apps. |
| 556 #if defined(OS_CHROMEOS) | 562 #if defined(OS_CHROMEOS) |
| 557 std::vector<std::string> app_ids; | 563 std::vector<std::string> app_ids; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); | 633 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); |
| 628 ++it) { | 634 ++it) { |
| 629 const std::string& id = it->second; | 635 const std::string& id = it->second; |
| 630 if (ntp_hidden_extensions_.count(id) == 0) | 636 if (ntp_hidden_extensions_.count(id) == 0) |
| 631 result++; | 637 result++; |
| 632 } | 638 } |
| 633 return result; | 639 return result; |
| 634 } | 640 } |
| 635 | 641 |
| 636 } // namespace extensions | 642 } // namespace extensions |
| OLD | NEW |