OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 keep_alive_for_startup_ = true; | 61 keep_alive_for_startup_ = true; |
62 BrowserList::StartKeepAlive(); | 62 BrowserList::StartKeepAlive(); |
63 } | 63 } |
64 | 64 |
65 // If the -keep-alive-for-test flag is passed, then always keep chrome running | 65 // If the -keep-alive-for-test flag is passed, then always keep chrome running |
66 // in the background until the user explicitly terminates it, by acting as if | 66 // in the background until the user explicitly terminates it, by acting as if |
67 // we loaded a background app. | 67 // we loaded a background app. |
68 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) | 68 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) |
69 OnBackgroundAppLoaded(); | 69 OnBackgroundAppLoaded(); |
70 | 70 |
71 // When an extension is installed, make sure launch on startup is properly | |
72 // set if appropriate. Likewise, turn off launch on startup when the last | |
73 // background app is uninstalled. | |
74 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, | |
75 Source<Profile>(profile)); | |
76 registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED, | |
77 Source<Profile>(profile)); | |
78 // Listen for when extensions are loaded/unloaded so we can track the | 71 // Listen for when extensions are loaded/unloaded so we can track the |
79 // number of background apps. | 72 // number of background apps and modify our keep-alive and launch-on-startup |
| 73 // state appropriately. |
80 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 74 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
81 Source<Profile>(profile)); | 75 Source<Profile>(profile)); |
82 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 76 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
83 Source<Profile>(profile)); | 77 Source<Profile>(profile)); |
84 | 78 |
85 // Check for the presence of background apps after all extensions have been | 79 // Check for the presence of background apps after all extensions have been |
86 // loaded, to handle the case where an extension has been manually removed | 80 // loaded, to handle the case where an extension has been manually removed |
87 // while Chrome was not running. | 81 // while Chrome was not running. |
88 registrar_.Add(this, NotificationType::EXTENSIONS_READY, | 82 registrar_.Add(this, NotificationType::EXTENSIONS_READY, |
89 Source<Profile>(profile)); | 83 Source<Profile>(profile)); |
(...skipping 20 matching lines...) Expand all Loading... |
110 const NotificationSource& source, | 104 const NotificationSource& source, |
111 const NotificationDetails& details) { | 105 const NotificationDetails& details) { |
112 switch (type.value) { | 106 switch (type.value) { |
113 case NotificationType::EXTENSIONS_READY: | 107 case NotificationType::EXTENSIONS_READY: |
114 // Extensions are loaded, so we don't need to manually keep the browser | 108 // Extensions are loaded, so we don't need to manually keep the browser |
115 // process alive any more when running in no-startup-window mode. | 109 // process alive any more when running in no-startup-window mode. |
116 EndKeepAliveForStartup(); | 110 EndKeepAliveForStartup(); |
117 | 111 |
118 // On a Mac, we use 'login items' mechanism which has user-facing UI so we | 112 // On a Mac, we use 'login items' mechanism which has user-facing UI so we |
119 // don't want to stomp on user choice every time we start and load | 113 // don't want to stomp on user choice every time we start and load |
120 // registered extensions. | 114 // registered extensions. This means that if a background app is removed |
| 115 // or added while Chrome is not running, we could leave Chrome in the |
| 116 // wrong state, but this is better than constantly forcing Chrome to |
| 117 // launch on startup even after the user removes the LoginItem manually. |
121 #if !defined(OS_MACOSX) | 118 #if !defined(OS_MACOSX) |
122 EnableLaunchOnStartup(background_app_count_ > 0); | 119 EnableLaunchOnStartup(background_app_count_ > 0); |
123 #endif | 120 #endif |
124 break; | 121 break; |
125 case NotificationType::EXTENSION_LOADED: | 122 case NotificationType::EXTENSION_LOADED: |
126 if (BackgroundApplicationListModel::IsBackgroundApp( | 123 if (BackgroundApplicationListModel::IsBackgroundApp( |
127 *Details<Extension>(details).ptr())) { | 124 *Details<Extension>(details).ptr())) { |
| 125 // Extensions loaded after the ExtensionsService is ready should be |
| 126 // treated as new installs. |
| 127 if (profile_->GetExtensionService()->is_ready()) |
| 128 OnBackgroundAppInstalled(); |
128 OnBackgroundAppLoaded(); | 129 OnBackgroundAppLoaded(); |
129 } | 130 } |
130 break; | 131 break; |
131 case NotificationType::EXTENSION_UNLOADED: | 132 case NotificationType::EXTENSION_UNLOADED: |
132 if (BackgroundApplicationListModel::IsBackgroundApp( | 133 if (BackgroundApplicationListModel::IsBackgroundApp( |
133 *Details<UnloadedExtensionInfo>(details)->extension)) { | 134 *Details<UnloadedExtensionInfo>(details)->extension)) { |
134 OnBackgroundAppUnloaded(); | 135 OnBackgroundAppUnloaded(); |
135 } | |
136 break; | |
137 case NotificationType::EXTENSION_INSTALLED: | |
138 if (BackgroundApplicationListModel::IsBackgroundApp( | |
139 *Details<Extension>(details).ptr())) { | |
140 OnBackgroundAppInstalled(); | |
141 } | |
142 break; | |
143 case NotificationType::EXTENSION_UNINSTALLED: | |
144 if (Extension::HasApiPermission( | |
145 Details<UninstalledExtensionInfo>(details).ptr()-> | |
146 extension_api_permissions, | |
147 Extension::kBackgroundPermission)) { | |
148 OnBackgroundAppUninstalled(); | 136 OnBackgroundAppUninstalled(); |
149 } | 137 } |
150 break; | 138 break; |
151 case NotificationType::APP_TERMINATING: | 139 case NotificationType::APP_TERMINATING: |
152 // Make sure we aren't still keeping the app alive (only happens if we | 140 // Make sure we aren't still keeping the app alive (only happens if we |
153 // don't receive an EXTENSIONS_READY notification for some reason). | 141 // don't receive an EXTENSIONS_READY notification for some reason). |
154 EndKeepAliveForStartup(); | 142 EndKeepAliveForStartup(); |
155 // Performing an explicit shutdown, so exit background mode (does nothing | 143 // Performing an explicit shutdown, so exit background mode (does nothing |
156 // if we aren't in background mode currently). | 144 // if we aren't in background mode currently). |
157 EndBackgroundMode(); | 145 EndBackgroundMode(); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // is always running on that platform, making it superfluous. | 358 // is always running on that platform, making it superfluous. |
371 #if defined(OS_CHROMEOS) | 359 #if defined(OS_CHROMEOS) |
372 return false; | 360 return false; |
373 #else | 361 #else |
374 bool background_mode_enabled = | 362 bool background_mode_enabled = |
375 !command_line->HasSwitch(switches::kDisableBackgroundMode) && | 363 !command_line->HasSwitch(switches::kDisableBackgroundMode) && |
376 !command_line->HasSwitch(switches::kDisableExtensions); | 364 !command_line->HasSwitch(switches::kDisableExtensions); |
377 return background_mode_enabled; | 365 return background_mode_enabled; |
378 #endif | 366 #endif |
379 } | 367 } |
OLD | NEW |