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/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/app_list/search/search_util.h" |
| 14 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 14 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
| 15 #include "chrome/common/extensions/extension_metrics.h" | 15 #include "chrome/common/extensions/extension_metrics.h" |
| 16 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
| 17 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 19 #include "extensions/browser/extension_system_provider.h" | 19 #include "extensions/browser/extension_system_provider.h" |
| 20 #include "extensions/browser/extensions_browser_client.h" | 20 #include "extensions/browser/extensions_browser_client.h" |
| 21 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
| 22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_icon_set.h" | 23 #include "extensions/common/extension_icon_set.h" |
| 24 #include "extensions/common/manifest_handlers/icons_handler.h" | 24 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 25 #include "ui/app_list/app_list_switches.h" | 25 #include "ui/app_list/app_list_switches.h" |
| 26 #include "ui/app_list/search/tokenized_string.h" | |
| 27 #include "ui/app_list/search/tokenized_string_match.h" | |
| 28 #include "ui/gfx/color_utils.h" | 26 #include "ui/gfx/color_utils.h" |
| 29 #include "ui/gfx/image/image_skia_operations.h" | 27 #include "ui/gfx/image/image_skia_operations.h" |
| 30 | 28 |
| 31 namespace app_list { | 29 namespace app_list { |
| 32 | 30 |
| 33 AppResult::AppResult(Profile* profile, | 31 AppResult::AppResult(Profile* profile, |
| 34 const std::string& app_id, | 32 const std::string& app_id, |
| 35 AppListControllerDelegate* controller, | 33 AppListControllerDelegate* controller, |
| 36 bool is_recommendation) | 34 bool is_recommendation) |
| 37 : profile_(profile), | 35 : profile_(profile), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 58 this)); | 56 this)); |
| 59 UpdateIcon(); | 57 UpdateIcon(); |
| 60 | 58 |
| 61 StartObservingExtensionRegistry(); | 59 StartObservingExtensionRegistry(); |
| 62 } | 60 } |
| 63 | 61 |
| 64 AppResult::~AppResult() { | 62 AppResult::~AppResult() { |
| 65 StopObservingExtensionRegistry(); | 63 StopObservingExtensionRegistry(); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void AppResult::UpdateFromMatch(const TokenizedString& title, | |
| 69 const TokenizedStringMatch& match) { | |
| 70 const TokenizedStringMatch::Hits& hits = match.hits(); | |
| 71 | |
| 72 Tags tags; | |
| 73 tags.reserve(hits.size()); | |
| 74 for (size_t i = 0; i < hits.size(); ++i) | |
| 75 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); | |
| 76 | |
| 77 set_title(title.text()); | |
| 78 set_title_tags(tags); | |
| 79 set_relevance(match.relevance()); | |
| 80 } | |
| 81 | |
| 82 void AppResult::UpdateFromLastLaunched(const base::Time& current_time, | 66 void AppResult::UpdateFromLastLaunched(const base::Time& current_time, |
| 83 const base::Time& last_launched) { | 67 const base::Time& last_launched) { |
| 84 base::TimeDelta delta = current_time - last_launched; | 68 base::TimeDelta delta = current_time - last_launched; |
| 85 // |current_time| can be before |last_launched| in weird cases such as users | 69 // |current_time| can be before |last_launched| in weird cases such as users |
| 86 // playing with their clocks. Handle this gracefully. | 70 // playing with their clocks. Handle this gracefully. |
| 87 if (current_time < last_launched) { | 71 if (current_time < last_launched) { |
| 88 set_relevance(1.0); | 72 set_relevance(1.0); |
| 89 return; | 73 return; |
| 90 } | 74 } |
| 91 | 75 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 122 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH, | 106 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH, |
| 123 event_flags); | 107 event_flags); |
| 124 } | 108 } |
| 125 | 109 |
| 126 scoped_ptr<SearchResult> AppResult::Duplicate() const { | 110 scoped_ptr<SearchResult> AppResult::Duplicate() const { |
| 127 scoped_ptr<SearchResult> copy( | 111 scoped_ptr<SearchResult> copy( |
| 128 new AppResult(profile_, app_id_, controller_, | 112 new AppResult(profile_, app_id_, controller_, |
| 129 display_type() == DISPLAY_RECOMMENDATION)); | 113 display_type() == DISPLAY_RECOMMENDATION)); |
| 130 copy->set_title(title()); | 114 copy->set_title(title()); |
| 131 copy->set_title_tags(title_tags()); | 115 copy->set_title_tags(title_tags()); |
| 116 copy->set_relevance(relevance()); | |
|
calamity
2015/04/30 06:36:06
Hmm... Why was this not here before...?
Matt Giuca
2015/05/11 04:53:21
Is not strictly necessary as the only caller of Du
| |
| 132 | 117 |
| 133 return copy.Pass(); | 118 return copy.Pass(); |
| 134 } | 119 } |
| 135 | 120 |
| 136 ui::MenuModel* AppResult::GetContextMenuModel() { | 121 ui::MenuModel* AppResult::GetContextMenuModel() { |
| 137 if (!context_menu_) { | 122 if (!context_menu_) { |
| 138 context_menu_.reset(new AppContextMenu( | 123 context_menu_.reset(new AppContextMenu( |
| 139 this, profile_, app_id_, controller_)); | 124 this, profile_, app_id_, controller_)); |
| 140 context_menu_->set_is_platform_app(is_platform_app_); | 125 context_menu_->set_is_platform_app(is_platform_app_); |
| 141 context_menu_->set_is_search_result(true); | 126 context_menu_->set_is_search_result(true); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 const extensions::Extension* extension) { | 194 const extensions::Extension* extension) { |
| 210 UpdateIcon(); | 195 UpdateIcon(); |
| 211 } | 196 } |
| 212 | 197 |
| 213 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { | 198 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 214 DCHECK_EQ(extension_registry_, registry); | 199 DCHECK_EQ(extension_registry_, registry); |
| 215 StopObservingExtensionRegistry(); | 200 StopObservingExtensionRegistry(); |
| 216 } | 201 } |
| 217 | 202 |
| 218 } // namespace app_list | 203 } // namespace app_list |
| OLD | NEW |