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/ui/app_list/search/app_result.h" | 5 #include "chrome/browser/ui/app_list/search/app_result.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/extension_util.h" | 8 #include "chrome/browser/extensions/extension_util.h" |
9 #include "chrome/browser/extensions/install_tracker.h" | |
10 #include "chrome/browser/extensions/install_tracker_factory.h" | |
11 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/app_list/app_context_menu.h" | 10 #include "chrome/browser/ui/app_list/app_context_menu.h" |
13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 11 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
14 #include "chrome/browser/ui/app_list/search/tokenized_string.h" | 12 #include "chrome/browser/ui/app_list/search/tokenized_string.h" |
15 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" | 13 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" |
16 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 14 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
17 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 15 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
18 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
| 17 #include "extensions/browser/extension_registry.h" |
19 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
20 #include "extensions/browser/extension_system_provider.h" | 19 #include "extensions/browser/extension_system_provider.h" |
21 #include "extensions/browser/extensions_browser_client.h" | 20 #include "extensions/browser/extensions_browser_client.h" |
22 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
23 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
24 #include "extensions/common/extension_icon_set.h" | 23 #include "extensions/common/extension_icon_set.h" |
25 #include "extensions/common/manifest_handlers/icons_handler.h" | 24 #include "extensions/common/manifest_handlers/icons_handler.h" |
26 #include "ui/gfx/color_utils.h" | 25 #include "ui/gfx/color_utils.h" |
27 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
28 | 27 |
29 namespace app_list { | 28 namespace app_list { |
30 | 29 |
31 AppResult::AppResult(Profile* profile, | 30 AppResult::AppResult(Profile* profile, |
32 const std::string& app_id, | 31 const std::string& app_id, |
33 AppListControllerDelegate* controller) | 32 AppListControllerDelegate* controller) |
34 : profile_(profile), | 33 : profile_(profile), |
35 app_id_(app_id), | 34 app_id_(app_id), |
36 controller_(controller), | 35 controller_(controller), |
37 install_tracker_(NULL) { | 36 extension_registry_(NULL) { |
38 set_id(extensions::Extension::GetBaseURLFromExtensionId(app_id_).spec()); | 37 set_id(extensions::Extension::GetBaseURLFromExtensionId(app_id_).spec()); |
39 | 38 |
40 const extensions::Extension* extension = | 39 const extensions::Extension* extension = |
41 extensions::ExtensionSystem::Get(profile_)->extension_service() | 40 extensions::ExtensionSystem::Get(profile_)->extension_service() |
42 ->GetInstalledExtension(app_id_); | 41 ->GetInstalledExtension(app_id_); |
43 DCHECK(extension); | 42 DCHECK(extension); |
44 | 43 |
45 is_platform_app_ = extension->is_platform_app(); | 44 is_platform_app_ = extension->is_platform_app(); |
46 | 45 |
47 icon_.reset(new extensions::IconImage( | 46 icon_.reset(new extensions::IconImage( |
48 profile_, | 47 profile_, |
49 extension, | 48 extension, |
50 extensions::IconsInfo::GetIcons(extension), | 49 extensions::IconsInfo::GetIcons(extension), |
51 extension_misc::EXTENSION_ICON_SMALL, | 50 extension_misc::EXTENSION_ICON_SMALL, |
52 extensions::util::GetDefaultAppIcon(), | 51 extensions::util::GetDefaultAppIcon(), |
53 this)); | 52 this)); |
54 UpdateIcon(); | 53 UpdateIcon(); |
55 StartObservingInstall(); | 54 |
| 55 StartObservingExtensionRegistry(); |
56 } | 56 } |
57 | 57 |
58 AppResult::~AppResult() { | 58 AppResult::~AppResult() { |
59 StopObservingInstall(); | 59 StopObservingExtensionRegistry(); |
60 } | 60 } |
61 | 61 |
62 void AppResult::UpdateFromMatch(const TokenizedString& title, | 62 void AppResult::UpdateFromMatch(const TokenizedString& title, |
63 const TokenizedStringMatch& match) { | 63 const TokenizedStringMatch& match) { |
64 const TokenizedStringMatch::Hits& hits = match.hits(); | 64 const TokenizedStringMatch::Hits& hits = match.hits(); |
65 | 65 |
66 Tags tags; | 66 Tags tags; |
67 tags.reserve(hits.size()); | 67 tags.reserve(hits.size()); |
68 for (size_t i = 0; i < hits.size(); ++i) | 68 for (size_t i = 0; i < hits.size(); ++i) |
69 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); | 69 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (!context_menu_) { | 114 if (!context_menu_) { |
115 context_menu_.reset(new AppContextMenu( | 115 context_menu_.reset(new AppContextMenu( |
116 this, profile_, app_id_, controller_)); | 116 this, profile_, app_id_, controller_)); |
117 context_menu_->set_is_platform_app(is_platform_app_); | 117 context_menu_->set_is_platform_app(is_platform_app_); |
118 context_menu_->set_is_search_result(true); | 118 context_menu_->set_is_search_result(true); |
119 } | 119 } |
120 | 120 |
121 return context_menu_->GetMenuModel(); | 121 return context_menu_->GetMenuModel(); |
122 } | 122 } |
123 | 123 |
124 void AppResult::StartObservingInstall() { | 124 void AppResult::StartObservingExtensionRegistry() { |
125 DCHECK(!install_tracker_); | 125 DCHECK(!extension_registry_); |
126 | 126 |
127 install_tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_); | 127 extension_registry_ = extensions::ExtensionRegistry::Get(profile_); |
128 install_tracker_->AddObserver(this); | 128 extension_registry_->AddObserver(this); |
129 } | 129 } |
130 | 130 |
131 void AppResult::StopObservingInstall() { | 131 void AppResult::StopObservingExtensionRegistry() { |
132 if (install_tracker_) | 132 if (extension_registry_) |
133 install_tracker_->RemoveObserver(this); | 133 extension_registry_->RemoveObserver(this); |
134 | 134 extension_registry_ = NULL; |
135 install_tracker_ = NULL; | |
136 } | 135 } |
137 | 136 |
138 bool AppResult::RunExtensionEnableFlow() { | 137 bool AppResult::RunExtensionEnableFlow() { |
139 if (extensions::util::IsAppLaunchableWithoutEnabling(app_id_, profile_)) | 138 if (extensions::util::IsAppLaunchableWithoutEnabling(app_id_, profile_)) |
140 return false; | 139 return false; |
141 | 140 |
142 if (!extension_enable_flow_) { | 141 if (!extension_enable_flow_) { |
143 controller_->OnShowChildDialog(); | 142 controller_->OnShowChildDialog(); |
144 | 143 |
145 extension_enable_flow_.reset(new ExtensionEnableFlow( | 144 extension_enable_flow_.reset(new ExtensionEnableFlow( |
(...skipping 30 matching lines...) Expand all Loading... |
176 | 175 |
177 // Automatically open app after enabling. | 176 // Automatically open app after enabling. |
178 Open(ui::EF_NONE); | 177 Open(ui::EF_NONE); |
179 } | 178 } |
180 | 179 |
181 void AppResult::ExtensionEnableFlowAborted(bool user_initiated) { | 180 void AppResult::ExtensionEnableFlowAborted(bool user_initiated) { |
182 extension_enable_flow_.reset(); | 181 extension_enable_flow_.reset(); |
183 controller_->OnCloseChildDialog(); | 182 controller_->OnCloseChildDialog(); |
184 } | 183 } |
185 | 184 |
186 void AppResult::OnExtensionLoaded(const extensions::Extension* extension) { | 185 void AppResult::OnExtensionLoaded(content::BrowserContext* browser_context, |
| 186 const extensions::Extension* extension) { |
187 UpdateIcon(); | 187 UpdateIcon(); |
188 } | 188 } |
189 | 189 |
190 void AppResult::OnExtensionUninstalled(const extensions::Extension* extension) { | 190 void AppResult::OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 191 const extensions::Extension* extension) { |
191 if (extension->id() != app_id_) | 192 if (extension->id() != app_id_) |
192 return; | 193 return; |
193 | 194 |
194 NotifyItemUninstalled(); | 195 NotifyItemUninstalled(); |
195 } | 196 } |
196 | 197 |
197 void AppResult::OnShutdown() { StopObservingInstall(); } | 198 void AppResult::OnShutdown() { |
| 199 StopObservingExtensionRegistry(); |
| 200 } |
198 | 201 |
199 } // namespace app_list | 202 } // namespace app_list |
OLD | NEW |