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

Unified Diff: content/browser/browser_context.cc

Issue 2815913005: Switch to using scoped_ptr with UserData (Closed)
Patch Set: rebase 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 c5410b5d1d3ab860ae7d5161c5c5e1ba6e474db2..db0260b118a876e5d32c8dc90729fe7d8feb5962 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>
@@ -18,6 +19,7 @@
#include "base/lazy_instance.h"
#include "base/logging.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"
@@ -99,8 +101,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;
}
@@ -141,11 +146,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
@@ -196,7 +202,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());
}
@@ -394,8 +400,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
@@ -420,10 +426,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();
@@ -444,7 +450,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();
« no previous file with comments | « content/browser/blob_storage/chrome_blob_storage_context.cc ('k') | content/browser/download/download_request_core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698