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/search/hotword_service.h" | 5 #include "chrome/browser/search/hotword_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| 11 #include "base/location.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/thread_task_runner_handle.h" |
17 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" | 22 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/pending_extension_manager.h" | 24 #include "chrome/browser/extensions/pending_extension_manager.h" |
22 #include "chrome/browser/extensions/updater/extension_updater.h" | 25 #include "chrome/browser/extensions/updater/extension_updater.h" |
23 #include "chrome/browser/notifications/notification.h" | 26 #include "chrome/browser/notifications/notification.h" |
24 #include "chrome/browser/notifications/notification_ui_manager.h" | 27 #include "chrome/browser/notifications/notification_ui_manager.h" |
25 #include "chrome/browser/plugins/plugin_prefs.h" | 28 #include "chrome/browser/plugins/plugin_prefs.h" |
26 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( | 366 SetAudioHistoryHandler(new HotwordAudioHistoryHandler( |
364 profile_, base::MessageLoop::current()->task_runner())); | 367 profile_, base::MessageLoop::current()->task_runner())); |
365 | 368 |
366 if (HotwordServiceFactory::IsAlwaysOnAvailable() && | 369 if (HotwordServiceFactory::IsAlwaysOnAvailable() && |
367 IsHotwordAllowed()) { | 370 IsHotwordAllowed()) { |
368 // Show the hotword notification in 5 seconds if the experimental flag is | 371 // Show the hotword notification in 5 seconds if the experimental flag is |
369 // on, or in 10 minutes if not. We need to wait at least a few seconds | 372 // on, or in 10 minutes if not. We need to wait at least a few seconds |
370 // for the hotword extension to be installed. | 373 // for the hotword extension to be installed. |
371 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 374 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
372 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { | 375 if (command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware)) { |
373 base::MessageLoop::current()->PostDelayedTask( | 376 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
374 FROM_HERE, | 377 FROM_HERE, base::Bind(&HotwordService::ShowHotwordNotification, |
375 base::Bind(&HotwordService::ShowHotwordNotification, | 378 weak_factory_.GetWeakPtr()), |
376 weak_factory_.GetWeakPtr()), | |
377 base::TimeDelta::FromSeconds(5)); | 379 base::TimeDelta::FromSeconds(5)); |
378 } else if (!profile_->GetPrefs()->GetBoolean( | 380 } else if (!profile_->GetPrefs()->GetBoolean( |
379 prefs::kHotwordAlwaysOnNotificationSeen)) { | 381 prefs::kHotwordAlwaysOnNotificationSeen)) { |
380 base::MessageLoop::current()->PostDelayedTask( | 382 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
381 FROM_HERE, | 383 FROM_HERE, base::Bind(&HotwordService::ShowHotwordNotification, |
382 base::Bind(&HotwordService::ShowHotwordNotification, | 384 weak_factory_.GetWeakPtr()), |
383 weak_factory_.GetWeakPtr()), | |
384 base::TimeDelta::FromMinutes(10)); | 385 base::TimeDelta::FromMinutes(10)); |
385 } | 386 } |
386 } | 387 } |
387 | 388 |
388 #if defined(OS_CHROMEOS) | 389 #if defined(OS_CHROMEOS) |
389 if (user_manager::UserManager::IsInitialized()) { | 390 if (user_manager::UserManager::IsInitialized()) { |
390 session_observer_.reset(new HotwordUserSessionStateObserver(this)); | 391 session_observer_.reset(new HotwordUserSessionStateObserver(this)); |
391 user_manager::UserManager::Get()->AddSessionStateObserver( | 392 user_manager::UserManager::Get()->AddSessionStateObserver( |
392 session_observer_.get()); | 393 session_observer_.get()); |
393 } | 394 } |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // Only support multiple profiles and profile switching in ChromeOS. | 876 // Only support multiple profiles and profile switching in ChromeOS. |
876 if (user_manager::UserManager::IsInitialized()) { | 877 if (user_manager::UserManager::IsInitialized()) { |
877 user_manager::User* user = | 878 user_manager::User* user = |
878 user_manager::UserManager::Get()->GetActiveUser(); | 879 user_manager::UserManager::Get()->GetActiveUser(); |
879 if (user && user->is_profile_created()) | 880 if (user && user->is_profile_created()) |
880 return profile_ == ProfileManager::GetActiveUserProfile(); | 881 return profile_ == ProfileManager::GetActiveUserProfile(); |
881 } | 882 } |
882 #endif | 883 #endif |
883 return true; | 884 return true; |
884 } | 885 } |
OLD | NEW |