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 "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_util.h" | 9 #include "chrome/browser/extensions/extension_util.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/app_list/app_context_menu.h" | 11 #include "chrome/browser/ui/app_list/app_context_menu.h" |
12 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 12 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 13 #include "chrome/browser/ui/app_list/search/search_util.h" |
13 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 14 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
14 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 15 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
15 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
16 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
17 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
18 #include "extensions/browser/extension_system_provider.h" | 19 #include "extensions/browser/extension_system_provider.h" |
19 #include "extensions/browser/extensions_browser_client.h" | 20 #include "extensions/browser/extensions_browser_client.h" |
20 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_icon_set.h" | 23 #include "extensions/common/extension_icon_set.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 base::TimeDelta delta = current_time - last_launched; | 83 base::TimeDelta delta = current_time - last_launched; |
83 DCHECK_LE(0, delta.InSeconds()); | 84 DCHECK_LE(0, delta.InSeconds()); |
84 const int kSecondsInWeek = 60 * 60 * 24 * 7; | 85 const int kSecondsInWeek = 60 * 60 * 24 * 7; |
85 | 86 |
86 // Set the relevance to a value between 0 and 1. This function decays as the | 87 // Set the relevance to a value between 0 and 1. This function decays as the |
87 // time delta increases and reaches a value of 0.5 at 1 week. | 88 // time delta increases and reaches a value of 0.5 at 1 week. |
88 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); | 89 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); |
89 } | 90 } |
90 | 91 |
91 void AppResult::Open(int event_flags) { | 92 void AppResult::Open(int event_flags) { |
| 93 RecordHistogram(APP_SEARCH_RESULT); |
92 const extensions::Extension* extension = | 94 const extensions::Extension* extension = |
93 extensions::ExtensionSystem::Get(profile_)->extension_service() | 95 extensions::ExtensionSystem::Get(profile_)->extension_service() |
94 ->GetInstalledExtension(app_id_); | 96 ->GetInstalledExtension(app_id_); |
95 if (!extension) | 97 if (!extension) |
96 return; | 98 return; |
97 | 99 |
98 // Don't auto-enable apps that cannot be launched. | 100 // Don't auto-enable apps that cannot be launched. |
99 if (!extensions::util::IsAppLaunchable(app_id_, profile_)) | 101 if (!extensions::util::IsAppLaunchable(app_id_, profile_)) |
100 return; | 102 return; |
101 | 103 |
102 // Check if enable flow is already running or should be started | 104 // Check if enable flow is already running or should be started |
103 if (RunExtensionEnableFlow()) | 105 if (RunExtensionEnableFlow()) |
104 return; | 106 return; |
105 | 107 |
106 CoreAppLauncherHandler::RecordAppListSearchLaunch(extension); | 108 CoreAppLauncherHandler::RecordAppListSearchLaunch(extension); |
107 content::RecordAction( | 109 content::RecordAction( |
108 base::UserMetricsAction("AppList_ClickOnAppFromSearch")); | 110 base::UserMetricsAction("AppList_ClickOnAppFromSearch")); |
109 | 111 |
110 controller_->ActivateApp( | 112 controller_->ActivateApp( |
111 profile_, | 113 profile_, |
112 extension, | 114 extension, |
113 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH, | 115 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH, |
114 event_flags); | 116 event_flags); |
115 } | 117 } |
116 | 118 |
117 void AppResult::InvokeAction(int action_index, int event_flags) {} | 119 scoped_ptr<SearchResult> AppResult::Duplicate() { |
118 | 120 scoped_ptr<SearchResult> copy(new AppResult(profile_, app_id_, controller_)); |
119 scoped_ptr<ChromeSearchResult> AppResult::Duplicate() { | |
120 scoped_ptr<ChromeSearchResult> copy( | |
121 new AppResult(profile_, app_id_, controller_)); | |
122 copy->set_title(title()); | 121 copy->set_title(title()); |
123 copy->set_title_tags(title_tags()); | 122 copy->set_title_tags(title_tags()); |
124 | 123 |
125 return copy.Pass(); | 124 return copy.Pass(); |
126 } | 125 } |
127 | 126 |
128 ChromeSearchResultType AppResult::GetType() { | |
129 return APP_SEARCH_RESULT; | |
130 } | |
131 | |
132 ui::MenuModel* AppResult::GetContextMenuModel() { | 127 ui::MenuModel* AppResult::GetContextMenuModel() { |
133 if (!context_menu_) { | 128 if (!context_menu_) { |
134 context_menu_.reset(new AppContextMenu( | 129 context_menu_.reset(new AppContextMenu( |
135 this, profile_, app_id_, controller_)); | 130 this, profile_, app_id_, controller_)); |
136 context_menu_->set_is_platform_app(is_platform_app_); | 131 context_menu_->set_is_platform_app(is_platform_app_); |
137 context_menu_->set_is_search_result(true); | 132 context_menu_->set_is_search_result(true); |
138 } | 133 } |
139 | 134 |
140 return context_menu_->GetMenuModel(); | 135 return context_menu_->GetMenuModel(); |
141 } | 136 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 209 |
215 NotifyItemUninstalled(); | 210 NotifyItemUninstalled(); |
216 } | 211 } |
217 | 212 |
218 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { | 213 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { |
219 DCHECK_EQ(extension_registry_, registry); | 214 DCHECK_EQ(extension_registry_, registry); |
220 StopObservingExtensionRegistry(); | 215 StopObservingExtensionRegistry(); |
221 } | 216 } |
222 | 217 |
223 } // namespace app_list | 218 } // namespace app_list |
OLD | NEW |