| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/app_list/app_list_switches.h" | 8 #include "ui/app_list/app_list_switches.h" |
| 9 | 9 |
| 10 namespace app_list { | 10 namespace app_list { |
| 11 | 11 |
| 12 AppResult::AppResult(Profile* profile, | 12 AppResult::AppResult(Profile* profile, |
| 13 const std::string& app_id, | 13 const std::string& app_id, |
| 14 AppListControllerDelegate* controller, | 14 AppListControllerDelegate* controller, |
| 15 bool is_recommendation) | 15 bool is_recommendation) |
| 16 : profile_(profile), | 16 : profile_(profile), |
| 17 app_id_(app_id), | 17 app_id_(app_id), |
| 18 controller_(controller) { | 18 controller_(controller) { |
| 19 if (app_list::switches::IsExperimentalAppListEnabled()) | 19 set_display_type(is_recommendation ? DISPLAY_RECOMMENDATION : DISPLAY_TILE); |
| 20 set_display_type(is_recommendation ? DISPLAY_RECOMMENDATION : DISPLAY_TILE); | |
| 21 } | 20 } |
| 22 | 21 |
| 23 AppResult::~AppResult() { | 22 AppResult::~AppResult() { |
| 24 } | 23 } |
| 25 | 24 |
| 26 void AppResult::UpdateFromLastLaunchedOrInstalledTime( | 25 void AppResult::UpdateFromLastLaunchedOrInstalledTime( |
| 27 const base::Time& current_time, | 26 const base::Time& current_time, |
| 28 const base::Time& old_time) { | 27 const base::Time& old_time) { |
| 29 // |current_time| can be before |old_time| in weird cases such as users | 28 // |current_time| can be before |old_time| in weird cases such as users |
| 30 // playing with their clocks. Handle this gracefully. | 29 // playing with their clocks. Handle this gracefully. |
| 31 if (current_time < old_time) { | 30 if (current_time < old_time) { |
| 32 set_relevance(1.0); | 31 set_relevance(1.0); |
| 33 return; | 32 return; |
| 34 } | 33 } |
| 35 | 34 |
| 36 base::TimeDelta delta = current_time - old_time; | 35 base::TimeDelta delta = current_time - old_time; |
| 37 const int kSecondsInWeek = 60 * 60 * 24 * 7; | 36 const int kSecondsInWeek = 60 * 60 * 24 * 7; |
| 38 | 37 |
| 39 // Set the relevance to a value between 0 and 1. This function decays as the | 38 // Set the relevance to a value between 0 and 1. This function decays as the |
| 40 // time delta increases and reaches a value of 0.5 at 1 week. | 39 // time delta increases and reaches a value of 0.5 at 1 week. |
| 41 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); | 40 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); |
| 42 } | 41 } |
| 43 | 42 |
| 44 } // namespace app_list | 43 } // namespace app_list |
| OLD | NEW |