[email protected] | c149b919 | 2012-04-20 09:35:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 5 | #include "base/base_paths.h" |
[email protected] | bd2262e | 2011-11-23 22:21:23 | [diff] [blame] | 6 | #include "base/bind.h" |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 9 | #include "base/logging.h" |
Gabriel Charette | 1452023 | 2018-04-30 23:27:22 | [diff] [blame^] | 10 | #include "base/sequenced_task_runner.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
stanisc | af60565 | 2017-06-07 19:27:12 | [diff] [blame] | 12 | #include "base/task_scheduler/post_task.h" |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 13 | #include "base/win/registry.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 14 | #include "chrome/browser/background/background_mode_manager.h" |
[email protected] | 9938b170 | 2012-06-05 16:23:02 | [diff] [blame] | 15 | #include "chrome/common/chrome_switches.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 16 | #include "chrome/grit/chromium_strings.h" |
| 17 | #include "chrome/grit/generated_resources.h" |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 18 | #include "chrome/installer/util/auto_launch_util.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 19 | #include "content/public/browser/browser_thread.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 20 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 21 | #include "ui/gfx/image/image_skia.h" |
Evan Stade | 889ce471 | 2018-01-28 15:26:26 | [diff] [blame] | 22 | #include "ui/message_center/public/cpp/notifier_id.h" |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 23 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 24 | using content::BrowserThread; |
| 25 | |
johnme | 9295617 | 2015-10-15 16:54:12 | [diff] [blame] | 26 | const char kAppInstalledNotifierId[] = "background-mode.app-installed"; |
| 27 | |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 28 | void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { |
| 29 | // This functionality is only defined for default profile, currently. |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 30 | if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 31 | return; |
stanisc | af60565 | 2017-06-07 19:27:12 | [diff] [blame] | 32 | task_runner_->PostTask( |
| 33 | FROM_HERE, |
| 34 | should_launch |
| 35 | ? base::Bind(auto_launch_util::EnableBackgroundStartAtLogin) |
| 36 | : base::Bind(auto_launch_util::DisableBackgroundStartAtLogin)); |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 37 | } |
| 38 | |
mvanouwerkerk | 5abba42 | 2015-09-01 15:35:14 | [diff] [blame] | 39 | void BackgroundModeManager::DisplayClientInstalledNotification( |
| 40 | const base::string16& name) { |
| 41 | // Create a status tray notification balloon explaining to the user what has |
| 42 | // been installed. |
[email protected] | a034ef46 | 2011-06-10 20:08:23 | [diff] [blame] | 43 | CreateStatusTrayIcon(); |
| 44 | status_icon_->DisplayBalloon( |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 45 | gfx::ImageSkia(), |
[email protected] | 6f9eac9 | 2011-03-06 17:49:02 | [diff] [blame] | 46 | l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE), |
mvanouwerkerk | 5abba42 | 2015-09-01 15:35:14 | [diff] [blame] | 47 | l10n_util::GetStringFUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY, |
| 48 | name, |
johnme | 9295617 | 2015-10-15 16:54:12 | [diff] [blame] | 49 | l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)), |
| 50 | message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
| 51 | kAppInstalledNotifierId)); |
[email protected] | 6f9eac9 | 2011-03-06 17:49:02 | [diff] [blame] | 52 | } |
| 53 | |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 54 | base::string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
[email protected] | 70dd60b | 2010-12-09 00:36:17 | [diff] [blame] | 55 | return l10n_util::GetStringUTF16(IDS_OPTIONS); |
| 56 | } |
stanisc | af60565 | 2017-06-07 19:27:12 | [diff] [blame] | 57 | |
| 58 | scoped_refptr<base::SequencedTaskRunner> |
| 59 | BackgroundModeManager::CreateTaskRunner() { |
| 60 | return base::CreateSequencedTaskRunnerWithTraits( |
| 61 | {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 62 | base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); |
| 63 | } |