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

Unified Diff: content/browser/browser_context.cc

Issue 2815913005: Switch to using scoped_ptr with UserData (Closed)
Patch Set: fixes Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_context.cc
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index b7a99d57813eadc0f76a539635140e6ba15cb509..8e02454f4847735d70f50bc322e616c0bbb9e58e 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -6,6 +6,7 @@
#include <stddef.h>
#include <stdint.h>
+
#include <algorithm>
#include <limits>
#include <memory>
@@ -16,6 +17,7 @@
#include "base/guid.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/rand_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
@@ -97,8 +99,11 @@ StoragePartitionImplMap* GetStoragePartitionMap(
static_cast<StoragePartitionImplMap*>(
browser_context->GetUserData(kStoragePartitionMapKeyName));
if (!partition_map) {
- partition_map = new StoragePartitionImplMap(browser_context);
- browser_context->SetUserData(kStoragePartitionMapKeyName, partition_map);
+ auto partition_map_owned =
+ base::MakeUnique<StoragePartitionImplMap>(browser_context);
+ partition_map = partition_map_owned.get();
+ browser_context->SetUserData(kStoragePartitionMapKeyName,
+ std::move(partition_map_owned));
}
return partition_map;
}
@@ -139,11 +144,12 @@ void ShutdownServiceWorkerContext(StoragePartition* partition) {
wrapper->process_manager()->Shutdown();
}
-void SetDownloadManager(BrowserContext* context,
- content::DownloadManager* download_manager) {
+void SetDownloadManager(
+ BrowserContext* context,
+ std::unique_ptr<content::DownloadManager> download_manager) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(download_manager);
- context->SetUserData(kDownloadManagerKeyName, download_manager);
+ context->SetUserData(kDownloadManagerKeyName, std::move(download_manager));
}
class BrowserContextServiceManagerConnectionHolder
@@ -194,7 +200,7 @@ DownloadManager* BrowserContext::GetDownloadManager(
new DownloadManagerImpl(
GetContentClient()->browser()->GetNetLog(), context);
- SetDownloadManager(context, download_manager);
+ SetDownloadManager(context, base::WrapUnique(download_manager));
download_manager->SetDelegate(context->GetDownloadManagerDelegate());
}
@@ -392,8 +398,8 @@ void BrowserContext::SaveSessionState(BrowserContext* browser_context) {
void BrowserContext::SetDownloadManagerForTesting(
BrowserContext* browser_context,
- DownloadManager* download_manager) {
- SetDownloadManager(browser_context, download_manager);
+ std::unique_ptr<content::DownloadManager> download_manager) {
+ SetDownloadManager(browser_context, std::move(download_manager));
}
// static
@@ -418,10 +424,10 @@ void BrowserContext::Initialize(
RemoveBrowserContextFromUserIdMap(browser_context);
g_user_id_to_context.Get()[new_id] = browser_context;
browser_context->SetUserData(kServiceUserId,
- new ServiceUserIdHolder(new_id));
+ base::MakeUnique<ServiceUserIdHolder>(new_id));
- browser_context->SetUserData(kMojoWasInitialized,
- new base::SupportsUserData::Data);
+ browser_context->SetUserData(
+ kMojoWasInitialized, base::MakeUnique<base::SupportsUserData::Data>());
ServiceManagerConnection* service_manager_connection =
ServiceManagerConnection::GetForProcess();
@@ -442,7 +448,8 @@ void BrowserContext::Initialize(
BrowserContextServiceManagerConnectionHolder* connection_holder =
new BrowserContextServiceManagerConnectionHolder(
std::move(service_request));
- browser_context->SetUserData(kServiceManagerConnection, connection_holder);
+ browser_context->SetUserData(kServiceManagerConnection,
+ base::WrapUnique(connection_holder));
ServiceManagerConnection* connection =
connection_holder->service_manager_connection();

Powered by Google App Engine
This is Rietveld 408576698