Commit fe58d1a3 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Get rid of link_ptr usage in BackgroundModeManager.

BUG=556939

Change-Id: I96e2fc6f76cfb85e9dac760ab77e93b9a6a7a10e
Reviewed-on: https://chromium-review.googlesource.com/1053274
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDrew Wilson <atwilson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569449}
parent 508b19e8
......@@ -357,9 +357,10 @@ void BackgroundModeManager::RegisterPrefs(PrefRegistrySimple* registry) {
void BackgroundModeManager::RegisterProfile(Profile* profile) {
// We don't want to register multiple times for one profile.
DCHECK(!base::ContainsKey(background_mode_data_, profile));
BackgroundModeInfo bmd(
new BackgroundModeData(profile, &command_id_handler_vector_));
background_mode_data_[profile] = bmd;
auto bmd = std::make_unique<BackgroundModeData>(profile,
&command_id_handler_vector_);
BackgroundModeData* bmd_ptr = bmd.get();
background_mode_data_[profile] = std::move(bmd);
// Initially set the name for this background mode data.
base::string16 name = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME);
......@@ -368,7 +369,7 @@ void BackgroundModeManager::RegisterProfile(Profile* profile) {
profile->GetPath(), &entry)) {
name = entry->GetName();
}
bmd->SetName(name);
bmd_ptr->SetName(name);
// Check for the presence of background apps after all extensions have been
// loaded, to handle the case where an extension has been manually removed
......@@ -378,7 +379,7 @@ void BackgroundModeManager::RegisterProfile(Profile* profile) {
base::Bind(&BackgroundModeManager::OnExtensionsReady,
weak_factory_.GetWeakPtr(), profile));
bmd->applications()->AddObserver(this);
bmd_ptr->applications()->AddObserver(this);
// If we're adding a new profile and running in multi-profile mode, this new
// profile should be added to the status icon if one currently exists.
......
......@@ -13,7 +13,6 @@
#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "chrome/browser/background/background_application_list_model.h"
......@@ -262,16 +261,8 @@ class BackgroundModeManager : public content::NotificationObserver,
std::set<BackgroundTrigger*> registered_triggers_;
};
// Ideally we would want our BackgroundModeData to be scoped_ptrs,
// but since maps copy their entries, we can't used scoped_ptrs.
// Similarly, we can't just have a map of BackgroundModeData objects,
// since BackgroundModeData contains a scoped_ptr which once again
// can't be copied. So rather than using BackgroundModeData* which
// we'd have to remember to delete, we use the ref-counted linked_ptr
// which is similar to a shared_ptr.
using BackgroundModeInfo = linked_ptr<BackgroundModeData>;
using BackgroundModeInfoMap = std::map<const Profile*, BackgroundModeInfo>;
using BackgroundModeInfoMap =
std::map<const Profile*, std::unique_ptr<BackgroundModeData>>;
// content::NotificationObserver implementation.
void Observe(int type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment