Commit 9ccd64ff authored by avi's avatar avi Committed by Commit bot

Remove stl_util's STLDeleteContainerPairSecondPointers from extensions.

BUG=555865

Review-Url: https://codereview.chromium.org/2344273002
Cr-Commit-Position: refs/heads/master@{#419297}
parent 133105cf
......@@ -14,8 +14,8 @@
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/messaging/extension_message_port.h"
#include "chrome/browser/extensions/api/messaging/incognito_connectability.h"
......@@ -233,8 +233,6 @@ MessageService::MessageService(BrowserContext* context)
MessageService::~MessageService() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::STLDeleteContainerPairSecondPointers(channels_.begin(),
channels_.end());
channels_.clear();
}
......@@ -478,7 +476,7 @@ void MessageService::OpenChannelToNativeApp(
// Keep the opener alive until the channel is closed.
channel->opener->IncrementLazyKeepaliveCount();
AddChannel(channel.release(), receiver_port_id);
AddChannel(std::move(channel), receiver_port_id);
#else // !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX))
const char kNativeMessagingNotSupportedError[] =
"Native Messaging is not supported on this platform.";
......@@ -589,10 +587,12 @@ void MessageService::OpenChannelImpl(BrowserContext* browser_context,
return;
}
MessageChannel* channel(new MessageChannel());
std::unique_ptr<MessageChannel> channel_ptr =
base::MakeUnique<MessageChannel>();
MessageChannel* channel = channel_ptr.get();
channel->opener.reset(opener.release());
channel->receiver.reset(params->receiver.release());
AddChannel(channel, params->receiver_port_id);
AddChannel(std::move(channel_ptr), params->receiver_port_id);
// TODO(robwu): Could |guest_process_id| and |guest_render_frame_routing_id|
// be removed? In the past extension message routing was process-based, but
......@@ -653,12 +653,13 @@ void MessageService::OpenChannelImpl(BrowserContext* browser_context,
channel->receiver->IncrementLazyKeepaliveCount();
}
void MessageService::AddChannel(MessageChannel* channel, int receiver_port_id) {
void MessageService::AddChannel(std::unique_ptr<MessageChannel> channel,
int receiver_port_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
int channel_id = GET_CHANNEL_ID(receiver_port_id);
CHECK(channels_.find(channel_id) == channels_.end());
channels_[channel_id] = channel;
channels_[channel_id] = std::move(channel);
pending_lazy_background_page_channels_.erase(channel_id);
}
......@@ -727,7 +728,7 @@ void MessageService::CloseChannelImpl(
bool notify_other_port) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
MessageChannel* channel = channel_iter->second;
std::unique_ptr<MessageChannel> channel = std::move(channel_iter->second);
// Remove from map to make sure that it is impossible for CloseChannelImpl to
// run twice for the same channel.
channels_.erase(channel_iter);
......@@ -742,8 +743,6 @@ void MessageService::CloseChannelImpl(
// Balance the IncrementLazyKeepaliveCount() in OpenChannelImpl.
channel->opener->DecrementLazyKeepaliveCount();
channel->receiver->DecrementLazyKeepaliveCount();
delete channel;
}
void MessageService::PostMessage(int source_port_id, const Message& message) {
......@@ -758,7 +757,7 @@ void MessageService::PostMessage(int source_port_id, const Message& message) {
return;
}
DispatchMessage(source_port_id, iter->second, message);
DispatchMessage(source_port_id, iter->second.get(), message);
}
void MessageService::EnqueuePendingMessage(int source_port_id,
......@@ -1019,7 +1018,8 @@ void MessageService::DispatchPendingMessages(const PendingMessagesQueue& queue,
MessageChannelMap::iterator channel_iter = channels_.find(channel_id);
if (channel_iter != channels_.end()) {
for (const PendingMessage& message : queue) {
DispatchMessage(message.first, channel_iter->second, message.second);
DispatchMessage(message.first, channel_iter->second.get(),
message.second);
}
}
}
......
......@@ -185,21 +185,21 @@ class MessageService : public BrowserContextKeyedAPI {
struct OpenChannelParams;
// A map of channel ID to its channel object.
typedef std::map<int, MessageChannel*> MessageChannelMap;
using MessageChannelMap = std::map<int, std::unique_ptr<MessageChannel>>;
typedef std::pair<int, Message> PendingMessage;
typedef std::vector<PendingMessage> PendingMessagesQueue;
using PendingMessage = std::pair<int, Message>;
using PendingMessagesQueue = std::vector<PendingMessage>;
// A set of channel IDs waiting to complete opening, and any pending messages
// queued to be sent on those channels.
typedef std::map<int, PendingMessagesQueue> PendingChannelMap;
using PendingChannelMap = std::map<int, PendingMessagesQueue>;
// A map of channel ID to information about the extension that is waiting
// for that channel to open. Used for lazy background pages.
typedef std::string ExtensionID;
typedef std::pair<content::BrowserContext*, ExtensionID>
PendingLazyBackgroundPageChannel;
typedef std::map<int, PendingLazyBackgroundPageChannel>
PendingLazyBackgroundPageChannelMap;
using ExtensionID = std::string;
using PendingLazyBackgroundPageChannel =
std::pair<content::BrowserContext*, ExtensionID>;
using PendingLazyBackgroundPageChannelMap =
std::map<int, PendingLazyBackgroundPageChannel>;
// Common implementation for opening a channel configured by |params|.
//
......@@ -226,7 +226,8 @@ class MessageService : public BrowserContextKeyedAPI {
// Have MessageService take ownership of |channel|, and remove any pending
// channels with the same id.
void AddChannel(MessageChannel* channel, int receiver_port_id);
void AddChannel(std::unique_ptr<MessageChannel> channel,
int receiver_port_id);
// If the channel is being opened from an incognito tab the user must allow
// the connection.
......
......@@ -12,8 +12,8 @@
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "build/build_config.h"
......@@ -265,10 +265,9 @@ class PrefMapping {
PrefTransformerInterface* FindTransformerForBrowserPref(
const std::string& browser_pref) {
std::map<std::string, PrefTransformerInterface*>::iterator it =
transformers_.find(browser_pref);
auto it = transformers_.find(browser_pref);
if (it != transformers_.end())
return it->second;
return it->second.get();
else
return identity_transformer_.get();
}
......@@ -294,23 +293,22 @@ class PrefMapping {
DCHECK_EQ(arraysize(kPrefMapping), mapping_.size());
DCHECK_EQ(arraysize(kPrefMapping), event_mapping_.size());
RegisterPrefTransformer(proxy_config::prefs::kProxy,
new ProxyPrefTransformer());
base::MakeUnique<ProxyPrefTransformer>());
RegisterPrefTransformer(prefs::kBlockThirdPartyCookies,
new InvertBooleanTransformer());
base::MakeUnique<InvertBooleanTransformer>());
RegisterPrefTransformer(prefs::kNetworkPredictionOptions,
new NetworkPredictionTransformer());
base::MakeUnique<NetworkPredictionTransformer>());
}
~PrefMapping() {
base::STLDeleteContainerPairSecondPointers(transformers_.begin(),
transformers_.end());
}
void RegisterPrefTransformer(const std::string& browser_pref,
PrefTransformerInterface* transformer) {
void RegisterPrefTransformer(
const std::string& browser_pref,
std::unique_ptr<PrefTransformerInterface> transformer) {
DCHECK_EQ(0u, transformers_.count(browser_pref)) <<
"Trying to register pref transformer for " << browser_pref << " twice";
transformers_[browser_pref] = transformer;
transformers_[browser_pref] = std::move(transformer);
}
struct PrefMapData {
......@@ -344,7 +342,8 @@ class PrefMapping {
PrefMap event_mapping_;
// Mapping from browser pref keys to transformers.
std::map<std::string, PrefTransformerInterface*> transformers_;
std::map<std::string, std::unique_ptr<PrefTransformerInterface>>
transformers_;
std::unique_ptr<PrefTransformerInterface> identity_transformer_;
......
......@@ -16,7 +16,6 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -243,8 +242,6 @@ VpnService::~VpnService() {
network_configuration_handler_->RemoveObserver(this);
network_state_handler_->RemoveObserver(this, FROM_HERE);
extension_registry_->RemoveObserver(this);
base::STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(),
key_to_configuration_map_.end());
}
void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) {
......@@ -448,7 +445,7 @@ void VpnService::DestroyConfiguration(const std::string& extension_id,
return;
}
VpnConfiguration* configuration = key_to_configuration_map_[key];
VpnConfiguration* configuration = key_to_configuration_map_[key].get();
const std::string service_path = configuration->service_path();
if (service_path.empty()) {
failure.Run(std::string(), std::string("Pending create."));
......@@ -529,7 +526,7 @@ void VpnService::DestroyConfigurationsForExtension(
std::vector<VpnConfiguration*> to_be_destroyed;
for (const auto& iter : key_to_configuration_map_) {
if (iter.second->extension_id() == extension->id()) {
to_be_destroyed.push_back(iter.second);
to_be_destroyed.push_back(iter.second.get());
}
}
......@@ -630,12 +627,13 @@ VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal(
const std::string& key) {
VpnConfiguration* configuration = new VpnConfiguration(
extension_id, configuration_name, key, weak_factory_.GetWeakPtr());
// The object is owned by key_to_configuration_map_ henceforth.
key_to_configuration_map_[key] = configuration;
key_to_configuration_map_[key] = base::WrapUnique(configuration);
return configuration;
}
void VpnService::DestroyConfigurationInternal(VpnConfiguration* configuration) {
std::unique_ptr<VpnConfiguration> configuration_ptr =
std::move(key_to_configuration_map_[configuration->key()]);
key_to_configuration_map_.erase(configuration->key());
if (active_configuration_ == configuration) {
active_configuration_ = nullptr;
......@@ -645,7 +643,6 @@ void VpnService::DestroyConfigurationInternal(VpnConfiguration* configuration) {
configuration->object_path());
service_path_to_configuration_map_.erase(configuration->service_path());
}
delete configuration;
}
bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized(
......@@ -671,7 +668,7 @@ void VpnService::Bind(
return;
}
VpnConfiguration* configuration = key_to_configuration_map_[key];
VpnConfiguration* configuration = key_to_configuration_map_[key].get();
if (active_configuration_ != configuration) {
failure.Run(std::string(), std::string("Unauthorized access. "
"The configuration is not active."));
......
......@@ -173,6 +173,8 @@ class VpnService : public KeyedService,
class VpnServiceProxyImpl;
using StringToConfigurationMap = std::map<std::string, VpnConfiguration*>;
using StringToOwnedConfigurationMap =
std::map<std::string, std::unique_ptr<VpnConfiguration>>;
// Callback used to indicate that configuration was successfully created.
void OnCreateConfigurationSuccess(const SuccessCallback& callback,
......@@ -253,8 +255,7 @@ class VpnService : public KeyedService,
VpnConfiguration* active_configuration_;
// Key map owns the VpnConfigurations.
StringToConfigurationMap key_to_configuration_map_;
StringToOwnedConfigurationMap key_to_configuration_map_;
// Service path does not own the VpnConfigurations.
StringToConfigurationMap service_path_to_configuration_map_;
......
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