OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return background_mode_data_.size(); | 277 return background_mode_data_.size(); |
278 } | 278 } |
279 | 279 |
280 /////////////////////////////////////////////////////////////////////////////// | 280 /////////////////////////////////////////////////////////////////////////////// |
281 // BackgroundModeManager, content::NotificationObserver overrides | 281 // BackgroundModeManager, content::NotificationObserver overrides |
282 void BackgroundModeManager::Observe( | 282 void BackgroundModeManager::Observe( |
283 int type, | 283 int type, |
284 const content::NotificationSource& source, | 284 const content::NotificationSource& source, |
285 const content::NotificationDetails& details) { | 285 const content::NotificationDetails& details) { |
286 switch (type) { | 286 switch (type) { |
287 case chrome::NOTIFICATION_PREF_CHANGED: | |
288 DCHECK(*content::Details<std::string>(details).ptr() == | |
289 prefs::kBackgroundModeEnabled); | |
290 OnBackgroundModeEnabledPrefChanged(); | |
291 break; | |
292 case chrome::NOTIFICATION_EXTENSIONS_READY: | 287 case chrome::NOTIFICATION_EXTENSIONS_READY: |
293 // Extensions are loaded, so we don't need to manually keep the browser | 288 // Extensions are loaded, so we don't need to manually keep the browser |
294 // process alive any more when running in no-startup-window mode. | 289 // process alive any more when running in no-startup-window mode. |
295 EndKeepAliveForStartup(); | 290 EndKeepAliveForStartup(); |
296 break; | 291 break; |
297 | 292 |
298 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 293 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
299 Extension* extension = content::Details<Extension>(details).ptr(); | 294 Extension* extension = content::Details<Extension>(details).ptr(); |
300 Profile* profile = content::Source<Profile>(source).ptr(); | 295 Profile* profile = content::Source<Profile>(source).ptr(); |
301 if (BackgroundApplicationListModel::IsBackgroundApp( | 296 if (BackgroundApplicationListModel::IsBackgroundApp( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 ++it) { | 329 ++it) { |
335 it->second->applications_->RemoveObserver(this); | 330 it->second->applications_->RemoveObserver(this); |
336 } | 331 } |
337 break; | 332 break; |
338 default: | 333 default: |
339 NOTREACHED(); | 334 NOTREACHED(); |
340 break; | 335 break; |
341 } | 336 } |
342 } | 337 } |
343 | 338 |
| 339 void BackgroundModeManager::OnPreferenceChanged(PrefServiceBase* service, |
| 340 const std::string& pref_name) { |
| 341 DCHECK(pref_name == prefs::kBackgroundModeEnabled); |
| 342 OnBackgroundModeEnabledPrefChanged(); |
| 343 } |
| 344 |
344 void BackgroundModeManager::OnBackgroundModeEnabledPrefChanged() { | 345 void BackgroundModeManager::OnBackgroundModeEnabledPrefChanged() { |
345 if (IsBackgroundModePrefEnabled()) | 346 if (IsBackgroundModePrefEnabled()) |
346 EnableBackgroundMode(); | 347 EnableBackgroundMode(); |
347 else | 348 else |
348 DisableBackgroundMode(); | 349 DisableBackgroundMode(); |
349 } | 350 } |
350 | 351 |
351 /////////////////////////////////////////////////////////////////////////////// | 352 /////////////////////////////////////////////////////////////////////////////// |
352 // BackgroundModeManager, BackgroundApplicationListModel::Observer overrides | 353 // BackgroundModeManager, BackgroundApplicationListModel::Observer overrides |
353 void BackgroundModeManager::OnApplicationDataChanged( | 354 void BackgroundModeManager::OnApplicationDataChanged( |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 } | 772 } |
772 } | 773 } |
773 return profile_it; | 774 return profile_it; |
774 } | 775 } |
775 | 776 |
776 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 777 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
777 PrefService* service = g_browser_process->local_state(); | 778 PrefService* service = g_browser_process->local_state(); |
778 DCHECK(service); | 779 DCHECK(service); |
779 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 780 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
780 } | 781 } |
OLD | NEW |