Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: chrome/browser/background/background_mode_manager.cc

Issue 1128033002: Avoiding use of NOTIFICATION_EXTENSION_READY_DEPRECATED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/background/background_mode_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/background/background_mode_manager.h" 5 #include "chrome/browser/background/background_mode_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/common/extensions/extension_constants.h" 43 #include "chrome/common/extensions/extension_constants.h"
44 #include "chrome/common/pref_names.h" 44 #include "chrome/common/pref_names.h"
45 #include "chrome/grit/chromium_strings.h" 45 #include "chrome/grit/chromium_strings.h"
46 #include "chrome/grit/generated_resources.h" 46 #include "chrome/grit/generated_resources.h"
47 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/user_metrics.h" 48 #include "content/public/browser/user_metrics.h"
49 #include "extensions/browser/extension_system.h" 49 #include "extensions/browser/extension_system.h"
50 #include "extensions/common/constants.h" 50 #include "extensions/common/constants.h"
51 #include "extensions/common/extension.h" 51 #include "extensions/common/extension.h"
52 #include "extensions/common/manifest_handlers/options_page_info.h" 52 #include "extensions/common/manifest_handlers/options_page_info.h"
53 #include "extensions/common/one_shot_event.h"
53 #include "extensions/common/permissions/permission_set.h" 54 #include "extensions/common/permissions/permission_set.h"
54 #include "grit/chrome_unscaled_resources.h" 55 #include "grit/chrome_unscaled_resources.h"
55 #include "ui/base/l10n/l10n_util.h" 56 #include "ui/base/l10n/l10n_util.h"
56 #include "ui/base/resource/resource_bundle.h" 57 #include "ui/base/resource/resource_bundle.h"
57 58
58 #if defined(OS_WIN) 59 #if defined(OS_WIN)
59 #include "components/browser_watcher/exit_funnel_win.h" 60 #include "components/browser_watcher/exit_funnel_win.h"
60 #endif 61 #endif
61 62
62 using base::UserMetricsAction; 63 using base::UserMetricsAction;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const base::CommandLine& command_line, 247 const base::CommandLine& command_line,
247 ProfileInfoCache* profile_cache) 248 ProfileInfoCache* profile_cache)
248 : profile_cache_(profile_cache), 249 : profile_cache_(profile_cache),
249 status_tray_(NULL), 250 status_tray_(NULL),
250 status_icon_(NULL), 251 status_icon_(NULL),
251 context_menu_(NULL), 252 context_menu_(NULL),
252 in_background_mode_(false), 253 in_background_mode_(false),
253 keep_alive_for_startup_(false), 254 keep_alive_for_startup_(false),
254 keep_alive_for_test_(false), 255 keep_alive_for_test_(false),
255 background_mode_suspended_(false), 256 background_mode_suspended_(false),
256 keeping_alive_(false) { 257 keeping_alive_(false),
258 weak_factory_(this) {
257 // We should never start up if there is no browser process or if we are 259 // We should never start up if there is no browser process or if we are
258 // currently quitting. 260 // currently quitting.
259 CHECK(g_browser_process != NULL); 261 CHECK(g_browser_process != NULL);
260 CHECK(!browser_shutdown::IsTryingToQuit()); 262 CHECK(!browser_shutdown::IsTryingToQuit());
261 263
262 // Add self as an observer for the profile info cache so we know when profiles 264 // Add self as an observer for the profile info cache so we know when profiles
263 // are deleted and their names change. 265 // are deleted and their names change.
264 profile_cache_->AddObserver(this); 266 profile_cache_->AddObserver(this);
265 267
266 RecordAutoLaunchState(command_line); 268 RecordAutoLaunchState(command_line);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // Initially set the name for this background mode data. 345 // Initially set the name for this background mode data.
344 size_t index = profile_cache_->GetIndexOfProfileWithPath(profile->GetPath()); 346 size_t index = profile_cache_->GetIndexOfProfileWithPath(profile->GetPath());
345 base::string16 name = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME); 347 base::string16 name = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME);
346 if (index != std::string::npos) 348 if (index != std::string::npos)
347 name = profile_cache_->GetNameOfProfileAtIndex(index); 349 name = profile_cache_->GetNameOfProfileAtIndex(index);
348 bmd->SetName(name); 350 bmd->SetName(name);
349 351
350 // Check for the presence of background apps after all extensions have been 352 // Check for the presence of background apps after all extensions have been
351 // loaded, to handle the case where an extension has been manually removed 353 // loaded, to handle the case where an extension has been manually removed
352 // while Chrome was not running. 354 // while Chrome was not running.
353 registrar_.Add(this, 355 extensions::ExtensionSystem::Get(profile)->ready().Post(
354 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 356 FROM_HERE,
355 content::Source<Profile>(profile)); 357 base::Bind(&BackgroundModeManager::OnExtensionsReady,
358 weak_factory_.GetWeakPtr()));
356 359
357 bmd->applications_->AddObserver(this); 360 bmd->applications_->AddObserver(this);
358 361
359 // If we're adding a new profile and running in multi-profile mode, this new 362 // If we're adding a new profile and running in multi-profile mode, this new
360 // profile should be added to the status icon if one currently exists. 363 // profile should be added to the status icon if one currently exists.
361 if (in_background_mode_ && status_icon_) 364 if (in_background_mode_ && status_icon_)
362 UpdateStatusTrayIconContextMenu(); 365 UpdateStatusTrayIconContextMenu();
363 } 366 }
364 367
365 // static 368 // static
(...skipping 12 matching lines...) Expand all
378 return background_mode_data_.size(); 381 return background_mode_data_.size();
379 } 382 }
380 383
381 /////////////////////////////////////////////////////////////////////////////// 384 ///////////////////////////////////////////////////////////////////////////////
382 // BackgroundModeManager, content::NotificationObserver overrides 385 // BackgroundModeManager, content::NotificationObserver overrides
383 void BackgroundModeManager::Observe( 386 void BackgroundModeManager::Observe(
384 int type, 387 int type,
385 const content::NotificationSource& source, 388 const content::NotificationSource& source,
386 const content::NotificationDetails& details) { 389 const content::NotificationDetails& details) {
387 switch (type) { 390 switch (type) {
388 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
389 // Extensions are loaded, so we don't need to manually keep the browser
390 // process alive any more when running in no-startup-window mode.
391 DecrementKeepAliveCountForStartup();
392 break;
393 case chrome::NOTIFICATION_APP_TERMINATING: 391 case chrome::NOTIFICATION_APP_TERMINATING:
394 // Make sure we aren't still keeping the app alive (only happens if we 392 // Make sure we aren't still keeping the app alive (only happens if we
395 // don't receive an EXTENSIONS_READY notification for some reason). 393 // don't receive an EXTENSIONS_READY notification for some reason).
396 DecrementKeepAliveCountForStartup(); 394 DecrementKeepAliveCountForStartup();
397 // Performing an explicit shutdown, so exit background mode (does nothing 395 // Performing an explicit shutdown, so exit background mode (does nothing
398 // if we aren't in background mode currently). 396 // if we aren't in background mode currently).
399 EndBackgroundMode(); 397 EndBackgroundMode();
400 // Shutting down, so don't listen for any more notifications so we don't 398 // Shutting down, so don't listen for any more notifications so we don't
401 // try to re-enter/exit background mode again. 399 // try to re-enter/exit background mode again.
402 registrar_.RemoveAll(); 400 registrar_.RemoveAll();
403 for (BackgroundModeInfoMap::iterator it = 401 for (BackgroundModeInfoMap::iterator it =
404 background_mode_data_.begin(); 402 background_mode_data_.begin();
405 it != background_mode_data_.end(); 403 it != background_mode_data_.end();
406 ++it) { 404 ++it) {
407 it->second->applications_->RemoveObserver(this); 405 it->second->applications_->RemoveObserver(this);
408 } 406 }
409 break; 407 break;
410 default: 408 default:
411 NOTREACHED(); 409 NOTREACHED();
412 break; 410 break;
413 } 411 }
414 } 412 }
415 413
414 void BackgroundModeManager::OnExtensionsReady() {
415 // Extensions are loaded, so we don't need to manually keep the browser
416 // process alive any more when running in no-startup-window mode.
417 DecrementKeepAliveCountForStartup();
418 }
419
416 void BackgroundModeManager::OnBackgroundModeEnabledPrefChanged() { 420 void BackgroundModeManager::OnBackgroundModeEnabledPrefChanged() {
417 if (IsBackgroundModePrefEnabled()) 421 if (IsBackgroundModePrefEnabled())
418 EnableBackgroundMode(); 422 EnableBackgroundMode();
419 else 423 else
420 DisableBackgroundMode(); 424 DisableBackgroundMode();
421 } 425 }
422 426
423 /////////////////////////////////////////////////////////////////////////////// 427 ///////////////////////////////////////////////////////////////////////////////
424 // BackgroundModeManager, BackgroundApplicationListModel::Observer overrides 428 // BackgroundModeManager, BackgroundApplicationListModel::Observer overrides
425 void BackgroundModeManager::OnApplicationDataChanged( 429 void BackgroundModeManager::OnApplicationDataChanged(
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 } 904 }
901 } 905 }
902 return profile_it; 906 return profile_it;
903 } 907 }
904 908
905 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { 909 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const {
906 PrefService* service = g_browser_process->local_state(); 910 PrefService* service = g_browser_process->local_state();
907 DCHECK(service); 911 DCHECK(service);
908 return service->GetBoolean(prefs::kBackgroundModeEnabled); 912 return service->GetBoolean(prefs::kBackgroundModeEnabled);
909 } 913 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698