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/app_list_service_impl.h" | 5 #include "chrome/browser/ui/app_list/app_list_service_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | |
11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/single_thread_task_runner.h" | |
13 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/thread_task_runner_handle.h" | |
14 #include "base/time/time.h" | 17 #include "base/time/time.h" |
15 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/browser_shutdown.h" | 19 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | 21 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
19 #include "chrome/browser/ui/app_list/profile_loader.h" | 22 #include "chrome/browser/ui/app_list/profile_loader.h" |
20 #include "chrome/browser/ui/app_list/profile_store.h" | 23 #include "chrome/browser/ui/app_list/profile_store.h" |
21 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 base::Time app_list_enable_time = | 173 base::Time app_list_enable_time = |
171 base::Time::FromInternalValue(enable_time_value); | 174 base::Time::FromInternalValue(enable_time_value); |
172 if (is_startup_check) { | 175 if (is_startup_check) { |
173 // When checking at startup, only clear and record the "timeout" case, | 176 // When checking at startup, only clear and record the "timeout" case, |
174 // otherwise wait for a timeout. | 177 // otherwise wait for a timeout. |
175 base::TimeDelta time_remaining = | 178 base::TimeDelta time_remaining = |
176 app_list_enable_time + | 179 app_list_enable_time + |
177 base::TimeDelta::FromMinutes(kDiscoverabilityTimeoutMinutes) - | 180 base::TimeDelta::FromMinutes(kDiscoverabilityTimeoutMinutes) - |
178 base::Time::Now(); | 181 base::Time::Now(); |
179 if (time_remaining > base::TimeDelta()) { | 182 if (time_remaining > base::TimeDelta()) { |
180 base::MessageLoop::current()->PostDelayedTask( | 183 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
181 FROM_HERE, | 184 FROM_HERE, base::Bind(&RecordAppListDiscoverability, |
182 base::Bind(&RecordAppListDiscoverability, | 185 base::Unretained(local_state), false), |
183 base::Unretained(local_state), | |
184 false), | |
185 time_remaining); | 186 time_remaining); |
186 return; | 187 return; |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 local_state->SetInt64(prefs::kAppListEnableTime, 0); | 191 local_state->SetInt64(prefs::kAppListEnableTime, 0); |
191 | 192 |
192 AppListService::AppListEnableSource enable_source = | 193 AppListService::AppListEnableSource enable_source = |
193 static_cast<AppListService::AppListEnableSource>( | 194 static_cast<AppListService::AppListEnableSource>( |
194 local_state->GetInteger(prefs::kAppListEnableMethod)); | 195 local_state->GetInteger(prefs::kAppListEnableMethod)); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 return; | 411 return; |
411 } | 412 } |
412 | 413 |
413 local_state_->SetBoolean(prefs::kAppLauncherHasBeenEnabled, true); | 414 local_state_->SetBoolean(prefs::kAppLauncherHasBeenEnabled, true); |
414 CreateShortcut(); | 415 CreateShortcut(); |
415 | 416 |
416 // UMA for launcher discoverability. | 417 // UMA for launcher discoverability. |
417 local_state_->SetInt64(prefs::kAppListEnableTime, | 418 local_state_->SetInt64(prefs::kAppListEnableTime, |
418 base::Time::Now().ToInternalValue()); | 419 base::Time::Now().ToInternalValue()); |
419 local_state_->SetInteger(prefs::kAppListEnableMethod, enable_source); | 420 local_state_->SetInteger(prefs::kAppListEnableMethod, enable_source); |
420 if (base::MessageLoop::current()) { | 421 if (base::MessageLoop::current()) { |
msw
2015/06/09 00:51:56
Shouldn't this now check base::ThreadTaskRunnerHan
Sami
2015/06/09 10:20:08
Well spotted, thanks. Fixed here, below and in app
| |
421 // Ensure a value is recorded if the user "never" shows the app list. Note | 422 // Ensure a value is recorded if the user "never" shows the app list. Note |
422 // there is no message loop in unit tests. | 423 // there is no message loop in unit tests. |
423 base::MessageLoop::current()->PostDelayedTask( | 424 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
424 FROM_HERE, | 425 FROM_HERE, base::Bind(&RecordAppListDiscoverability, |
425 base::Bind(&RecordAppListDiscoverability, | 426 base::Unretained(local_state_), false), |
426 base::Unretained(local_state_), | |
427 false), | |
428 base::TimeDelta::FromMinutes(kDiscoverabilityTimeoutMinutes)); | 427 base::TimeDelta::FromMinutes(kDiscoverabilityTimeoutMinutes)); |
429 } | 428 } |
430 } | 429 } |
431 | 430 |
432 void AppListServiceImpl::InvalidatePendingProfileLoads() { | 431 void AppListServiceImpl::InvalidatePendingProfileLoads() { |
433 profile_loader_->InvalidatePendingProfileLoads(); | 432 profile_loader_->InvalidatePendingProfileLoads(); |
434 } | 433 } |
435 | 434 |
436 void AppListServiceImpl::PerformStartupChecks(Profile* initial_profile) { | 435 void AppListServiceImpl::PerformStartupChecks(Profile* initial_profile) { |
437 // Except in rare, once-off cases, this just checks that a pref is "0" and | 436 // Except in rare, once-off cases, this just checks that a pref is "0" and |
438 // returns. | 437 // returns. |
439 RecordAppListDiscoverability(local_state_, true); | 438 RecordAppListDiscoverability(local_state_, true); |
440 | 439 |
441 if (command_line_.HasSwitch(switches::kResetAppListInstallState)) | 440 if (command_line_.HasSwitch(switches::kResetAppListInstallState)) |
442 local_state_->SetBoolean(prefs::kAppLauncherHasBeenEnabled, false); | 441 local_state_->SetBoolean(prefs::kAppLauncherHasBeenEnabled, false); |
443 | 442 |
444 if (command_line_.HasSwitch(switches::kEnableAppList)) | 443 if (command_line_.HasSwitch(switches::kEnableAppList)) |
445 EnableAppList(initial_profile, ENABLE_VIA_COMMAND_LINE); | 444 EnableAppList(initial_profile, ENABLE_VIA_COMMAND_LINE); |
446 | 445 |
447 if (!base::MessageLoop::current()) | 446 if (!base::MessageLoop::current()) |
448 return; // In a unit test. | 447 return; // In a unit test. |
449 | 448 |
450 // Send app list usage stats after a delay. | 449 // Send app list usage stats after a delay. |
451 const int kSendUsageStatsDelay = 5; | 450 const int kSendUsageStatsDelay = 5; |
452 base::MessageLoop::current()->PostDelayedTask( | 451 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
453 FROM_HERE, | 452 FROM_HERE, base::Bind(&AppListServiceImpl::SendAppListStats), |
454 base::Bind(&AppListServiceImpl::SendAppListStats), | |
455 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); | 453 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); |
456 } | 454 } |
OLD | NEW |