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_observer_(this) { |
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 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | |
56 } | 56 } |
57 | 57 |
58 AppResult::~AppResult() { | 58 AppResult::~AppResult() { |
59 StopObservingInstall(); | |
60 } | 59 } |
61 | 60 |
62 void AppResult::UpdateFromMatch(const TokenizedString& title, | 61 void AppResult::UpdateFromMatch(const TokenizedString& title, |
63 const TokenizedStringMatch& match) { | 62 const TokenizedStringMatch& match) { |
64 const TokenizedStringMatch::Hits& hits = match.hits(); | 63 const TokenizedStringMatch::Hits& hits = match.hits(); |
65 | 64 |
66 Tags tags; | 65 Tags tags; |
67 tags.reserve(hits.size()); | 66 tags.reserve(hits.size()); |
68 for (size_t i = 0; i < hits.size(); ++i) | 67 for (size_t i = 0; i < hits.size(); ++i) |
69 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); | 68 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_) { | 113 if (!context_menu_) { |
115 context_menu_.reset(new AppContextMenu( | 114 context_menu_.reset(new AppContextMenu( |
116 this, profile_, app_id_, controller_)); | 115 this, profile_, app_id_, controller_)); |
117 context_menu_->set_is_platform_app(is_platform_app_); | 116 context_menu_->set_is_platform_app(is_platform_app_); |
118 context_menu_->set_is_search_result(true); | 117 context_menu_->set_is_search_result(true); |
119 } | 118 } |
120 | 119 |
121 return context_menu_->GetMenuModel(); | 120 return context_menu_->GetMenuModel(); |
122 } | 121 } |
123 | 122 |
124 void AppResult::StartObservingInstall() { | |
125 DCHECK(!install_tracker_); | |
126 | |
127 install_tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_); | |
128 install_tracker_->AddObserver(this); | |
129 } | |
130 | |
131 void AppResult::StopObservingInstall() { | |
132 if (install_tracker_) | |
133 install_tracker_->RemoveObserver(this); | |
134 | |
135 install_tracker_ = NULL; | |
136 } | |
137 | |
138 bool AppResult::RunExtensionEnableFlow() { | 123 bool AppResult::RunExtensionEnableFlow() { |
139 if (extensions::util::IsAppLaunchableWithoutEnabling(app_id_, profile_)) | 124 if (extensions::util::IsAppLaunchableWithoutEnabling(app_id_, profile_)) |
140 return false; | 125 return false; |
141 | 126 |
142 if (!extension_enable_flow_) { | 127 if (!extension_enable_flow_) { |
143 controller_->OnShowChildDialog(); | 128 controller_->OnShowChildDialog(); |
144 | 129 |
145 extension_enable_flow_.reset(new ExtensionEnableFlow( | 130 extension_enable_flow_.reset(new ExtensionEnableFlow( |
146 profile_, app_id_, this)); | 131 profile_, app_id_, this)); |
147 extension_enable_flow_->StartForNativeWindow( | 132 extension_enable_flow_->StartForNativeWindow( |
(...skipping 28 matching lines...) Expand all Loading... | |
176 | 161 |
177 // Automatically open app after enabling. | 162 // Automatically open app after enabling. |
178 Open(ui::EF_NONE); | 163 Open(ui::EF_NONE); |
179 } | 164 } |
180 | 165 |
181 void AppResult::ExtensionEnableFlowAborted(bool user_initiated) { | 166 void AppResult::ExtensionEnableFlowAborted(bool user_initiated) { |
182 extension_enable_flow_.reset(); | 167 extension_enable_flow_.reset(); |
183 controller_->OnCloseChildDialog(); | 168 controller_->OnCloseChildDialog(); |
184 } | 169 } |
185 | 170 |
186 void AppResult::OnExtensionLoaded(const extensions::Extension* extension) { | 171 void AppResult::OnExtensionLoaded(content::BrowserContext* browser_context, |
172 const extensions::Extension* extension) { | |
187 UpdateIcon(); | 173 UpdateIcon(); |
188 } | 174 } |
189 | 175 |
190 void AppResult::OnExtensionUninstalled(const extensions::Extension* extension) { | 176 void AppResult::OnExtensionUninstalled(content::BrowserContext* browser_context, |
177 const extensions::Extension* extension) { | |
191 if (extension->id() != app_id_) | 178 if (extension->id() != app_id_) |
192 return; | 179 return; |
193 | 180 |
194 NotifyItemUninstalled(); | 181 NotifyItemUninstalled(); |
195 } | 182 } |
196 | 183 |
197 void AppResult::OnShutdown() { StopObservingInstall(); } | |
not at google - send to devlin
2014/05/29 18:09:29
hm, I'm a bit worried about losing this; the regis
limasdf
2014/05/30 21:00:49
Done.
I added only AppResult. perhaps I have to re
| |
198 | |
199 } // namespace app_list | 184 } // namespace app_list |
OLD | NEW |