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_sync_service.h" | 11 #include "chrome/browser/extensions/extension_sync_service.h" |
12 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
14 #include "extensions/browser/extension_scoped_prefs.h" | 15 #include "extensions/browser/extension_scoped_prefs.h" |
16 #include "extensions/browser/extension_util.h" | |
15 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
16 | 18 |
17 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
18 #include "chrome/browser/chromeos/extensions/default_app_order.h" | 20 #include "chrome/browser/chromeos/extensions/default_app_order.h" |
19 #endif | 21 #endif |
20 | 22 |
21 namespace extensions { | 23 namespace extensions { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
(...skipping 15 matching lines...) Expand all Loading... | |
40 // ChromeAppSorting::AppOrdinals | 42 // ChromeAppSorting::AppOrdinals |
41 | 43 |
42 ChromeAppSorting::AppOrdinals::AppOrdinals() {} | 44 ChromeAppSorting::AppOrdinals::AppOrdinals() {} |
43 | 45 |
44 ChromeAppSorting::AppOrdinals::~AppOrdinals() {} | 46 ChromeAppSorting::AppOrdinals::~AppOrdinals() {} |
45 | 47 |
46 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
47 // ChromeAppSorting | 49 // ChromeAppSorting |
48 | 50 |
49 ChromeAppSorting::ChromeAppSorting() | 51 ChromeAppSorting::ChromeAppSorting() |
50 : extension_scoped_prefs_(NULL), | 52 : profile_(NULL), |
53 extension_scoped_prefs_(NULL), | |
51 extension_sync_service_(NULL), | 54 extension_sync_service_(NULL), |
52 default_ordinals_created_(false) { | 55 default_ordinals_created_(false) { |
53 } | 56 } |
54 | 57 |
55 ChromeAppSorting::~ChromeAppSorting() { | 58 ChromeAppSorting::~ChromeAppSorting() { |
56 } | 59 } |
57 | 60 |
58 void ChromeAppSorting::SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) { | 61 void ChromeAppSorting::SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) { |
59 extension_scoped_prefs_ = prefs; | 62 extension_scoped_prefs_ = prefs; |
60 } | 63 } |
61 | 64 |
62 void ChromeAppSorting::SetExtensionSyncService( | 65 void ChromeAppSorting::SetExtensionSyncService( |
63 ExtensionSyncService* extension_sync_service) { | 66 ExtensionSyncService* extension_sync_service) { |
64 extension_sync_service_ = extension_sync_service; | 67 extension_sync_service_ = extension_sync_service; |
68 profile_ = extension_sync_service->profile(); | |
65 } | 69 } |
66 | 70 |
67 void ChromeAppSorting::Initialize( | 71 void ChromeAppSorting::Initialize( |
68 const extensions::ExtensionIdList& extension_ids) { | 72 const extensions::ExtensionIdList& extension_ids) { |
69 InitializePageOrdinalMap(extension_ids); | 73 InitializePageOrdinalMap(extension_ids); |
70 | 74 |
71 MigrateAppIndex(extension_ids); | 75 MigrateAppIndex(extension_ids); |
72 } | 76 } |
73 | 77 |
74 void ChromeAppSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { | 78 void ChromeAppSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 | 223 |
220 content::NotificationService::current()->Notify( | 224 content::NotificationService::current()->Notify( |
221 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 225 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
222 content::Source<ChromeAppSorting>(this), | 226 content::Source<ChromeAppSorting>(this), |
223 content::NotificationService::NoDetails()); | 227 content::NotificationService::NoDetails()); |
224 } | 228 } |
225 | 229 |
226 void ChromeAppSorting::EnsureValidOrdinals( | 230 void ChromeAppSorting::EnsureValidOrdinals( |
227 const std::string& extension_id, | 231 const std::string& extension_id, |
228 const syncer::StringOrdinal& suggested_page) { | 232 const syncer::StringOrdinal& suggested_page) { |
233 // Although installed transiently, ephemeral apps are not visible in the UI. | |
234 if (profile_ && util::IsEphemeralApp(extension_id, profile_)) | |
235 return; | |
tapted
2014/07/16 05:03:38
It might not be safe to return early from here
"t
| |
236 | |
229 syncer::StringOrdinal page_ordinal = GetPageOrdinal(extension_id); | 237 syncer::StringOrdinal page_ordinal = GetPageOrdinal(extension_id); |
230 if (!page_ordinal.IsValid()) { | 238 if (!page_ordinal.IsValid()) { |
231 if (suggested_page.IsValid()) { | 239 if (suggested_page.IsValid()) { |
232 page_ordinal = suggested_page; | 240 page_ordinal = suggested_page; |
233 } else if (!GetDefaultOrdinals(extension_id, &page_ordinal, NULL) || | 241 } else if (!GetDefaultOrdinals(extension_id, &page_ordinal, NULL) || |
234 !page_ordinal.IsValid()) { | 242 !page_ordinal.IsValid()) { |
235 page_ordinal = GetNaturalAppPageOrdinal(); | 243 page_ordinal = GetNaturalAppPageOrdinal(); |
236 } | 244 } |
237 | 245 |
238 SetPageOrdinal(extension_id, page_ordinal); | 246 SetPageOrdinal(extension_id, page_ordinal); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); | 622 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); |
615 ++it) { | 623 ++it) { |
616 const std::string& id = it->second; | 624 const std::string& id = it->second; |
617 if (ntp_hidden_extensions_.count(id) == 0) | 625 if (ntp_hidden_extensions_.count(id) == 0) |
618 result++; | 626 result++; |
619 } | 627 } |
620 return result; | 628 return result; |
621 } | 629 } |
622 | 630 |
623 } // namespace extensions | 631 } // namespace extensions |
OLD | NEW |