Commit 770e2a61 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Simplify map::emplace() usage in chrome/.

Just call emplace(k, v), instead of emplace(std::make_pair(k, v)). Also
fix lint errors.

Change-Id: Ib9ae69f3e21604daf1bcd2297bee960833db5290
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2005088Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732556}
parent 8b4ed17d
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/arc/print_spooler/print_session_impl.h" #include "chrome/browser/chromeos/arc/print_spooler/print_session_impl.h"
#include <limits> #include <limits>
#include <string>
#include <utility> #include <utility>
#include "ash/public/cpp/arc_custom_tab.h" #include "ash/public/cpp/arc_custom_tab.h"
...@@ -309,9 +310,7 @@ void PrintSessionImpl::OnPreviewDocumentRead( ...@@ -309,9 +310,7 @@ void PrintSessionImpl::OnPreviewDocumentRead(
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
bool inserted = bool inserted = callbacks_.emplace(request_id, std::move(callback)).second;
callbacks_.emplace(std::make_pair(request_id, std::move(callback)))
.second;
DCHECK(inserted); DCHECK(inserted);
pdf_flattener_->FlattenPdf( pdf_flattener_->FlattenPdf(
......
...@@ -138,9 +138,9 @@ void ArcScreenCaptureBridge::PermissionPromptCallback( ...@@ -138,9 +138,9 @@ void ArcScreenCaptureBridge::PermissionPromptCallback(
// This is OK since these persist forever and this may be requested again with // This is OK since these persist forever and this may be requested again with
// a different desktop. // a different desktop.
granted_permissions_map_.erase(package_name); granted_permissions_map_.erase(package_name);
granted_permissions_map_.emplace(std::make_pair( granted_permissions_map_.emplace(
package_name, GrantedCaptureParams(found->second.display_name, desktop_id, package_name, GrantedCaptureParams(found->second.display_name, desktop_id,
true /* enable notification */))); true /* enable notification */));
std::move(found->second.callback).Run(true); std::move(found->second.callback).Run(true);
pending_permissions_map_.erase(found); pending_permissions_map_.erase(found);
} }
...@@ -163,13 +163,13 @@ void ArcScreenCaptureBridge::TestModeAcceptPermission( ...@@ -163,13 +163,13 @@ void ArcScreenCaptureBridge::TestModeAcceptPermission(
return; return;
} }
granted_permissions_map_.erase(package_name); granted_permissions_map_.erase(package_name);
granted_permissions_map_.emplace(std::make_pair( granted_permissions_map_.emplace(
package_name, package_name,
GrantedCaptureParams(found->second.display_name, GrantedCaptureParams(found->second.display_name,
content::DesktopMediaID::RegisterNativeWindow( content::DesktopMediaID::RegisterNativeWindow(
content::DesktopMediaID::TYPE_SCREEN, content::DesktopMediaID::TYPE_SCREEN,
ash::Shell::GetPrimaryRootWindow()), ash::Shell::GetPrimaryRootWindow()),
false /* enable notification */))); false /* enable notification */));
std::move(found->second.callback).Run(true); std::move(found->second.callback).Run(true);
pending_permissions_map_.erase(found); pending_permissions_map_.erase(found);
// The dialog will be closed when 'found' goes out of scope and is // The dialog will be closed when 'found' goes out of scope and is
......
...@@ -403,7 +403,7 @@ ProcessDataCollector::ProcessSampleMap ProcessDataCollector::GetValidProcesses( ...@@ -403,7 +403,7 @@ ProcessDataCollector::ProcessSampleMap ProcessDataCollector::GetValidProcesses(
// iteration of this loop, |proc| will correspond to the PID of a different // iteration of this loop, |proc| will correspond to the PID of a different
// process. Thus, this call to |std::unordered_map::emplace| should never be // process. Thus, this call to |std::unordered_map::emplace| should never be
// called with the same key twice. // called with the same key twice.
procs.emplace(std::make_pair(proc, std::move(psample))); procs.emplace(proc, std::move(psample));
} }
return procs; return procs;
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include "chrome/browser/navigation_predictor/navigation_predictor.h" #include "chrome/browser/navigation_predictor/navigation_predictor.h"
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <utility>
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -54,7 +56,7 @@ class TestNavigationPredictor : public NavigationPredictor { ...@@ -54,7 +56,7 @@ class TestNavigationPredictor : public NavigationPredictor {
double CalculateAnchorNavigationScore( double CalculateAnchorNavigationScore(
const blink::mojom::AnchorElementMetrics& metrics, const blink::mojom::AnchorElementMetrics& metrics,
int area_rank) const override { int area_rank) const override {
area_rank_map_.emplace(std::make_pair(metrics.target_url, area_rank)); area_rank_map_.emplace(metrics.target_url, area_rank);
return 100 * metrics.ratio_area; return 100 * metrics.ratio_area;
} }
...@@ -474,7 +476,6 @@ TEST_F(NavigationPredictorTest, ActionTaken_SameOrigin_Prefetch_NotSameOrigin) { ...@@ -474,7 +476,6 @@ TEST_F(NavigationPredictorTest, ActionTaken_SameOrigin_Prefetch_NotSameOrigin) {
predictor_service()->ReportAnchorElementMetricsOnClick( predictor_service()->ReportAnchorElementMetricsOnClick(
std::move(metrics_clicked)); std::move(metrics_clicked));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
TEST_F(NavigationPredictorTest, TEST_F(NavigationPredictorTest,
...@@ -871,7 +872,6 @@ TEST_F(NavigationPredictorPrefetchDisabledTest, ...@@ -871,7 +872,6 @@ TEST_F(NavigationPredictorPrefetchDisabledTest,
predictor_service()->ReportAnchorElementMetricsOnClick( predictor_service()->ReportAnchorElementMetricsOnClick(
std::move(metrics_clicked)); std::move(metrics_clicked));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
// Framework for testing cases where preconnect and prefetch are effectively // Framework for testing cases where preconnect and prefetch are effectively
...@@ -917,5 +917,4 @@ TEST_F(NavigationPredictorPreconnectPrefetchDisabledTest, ...@@ -917,5 +917,4 @@ TEST_F(NavigationPredictorPreconnectPrefetchDisabledTest,
predictor_service()->ReportAnchorElementMetricsOnClick( predictor_service()->ReportAnchorElementMetricsOnClick(
std::move(metrics_clicked)); std::move(metrics_clicked));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -142,11 +142,10 @@ void SiteDataCacheFactory::ReplaceCacheForTesting( ...@@ -142,11 +142,10 @@ void SiteDataCacheFactory::ReplaceCacheForTesting(
DCHECK(base::Contains(data_cache_map_, browser_context_id)); DCHECK(base::Contains(data_cache_map_, browser_context_id));
data_cache_map_.erase(browser_context_id); data_cache_map_.erase(browser_context_id);
data_cache_map_.emplace(std::make_pair(browser_context_id, std::move(cache))); data_cache_map_.emplace(browser_context_id, std::move(cache));
DCHECK(!base::Contains(data_cache_inspector_map_, browser_context_id)); DCHECK(!base::Contains(data_cache_inspector_map_, browser_context_id));
data_cache_inspector_map_.emplace(std::make_pair( data_cache_inspector_map_.emplace(browser_context_id, cache_raw);
browser_context_id, static_cast<SiteDataCacheInspector*>(cache_raw)));
} }
void SiteDataCacheFactory::OnBrowserContextCreated( void SiteDataCacheFactory::OnBrowserContextCreated(
...@@ -165,14 +164,14 @@ void SiteDataCacheFactory::OnBrowserContextCreated( ...@@ -165,14 +164,14 @@ void SiteDataCacheFactory::OnBrowserContextCreated(
SiteDataCache* data_cache_for_readers = SiteDataCache* data_cache_for_readers =
data_cache_map_[parent_context_id.value()].get(); data_cache_map_[parent_context_id.value()].get();
DCHECK(data_cache_for_readers); DCHECK(data_cache_for_readers);
data_cache_map_.emplace(std::make_pair( data_cache_map_.emplace(
std::move(browser_context_id), std::move(browser_context_id),
std::make_unique<NonRecordingSiteDataCache>( std::make_unique<NonRecordingSiteDataCache>(
browser_context_id, parent_debug, data_cache_for_readers))); browser_context_id, parent_debug, data_cache_for_readers));
} else { } else {
data_cache_map_.emplace(std::make_pair( data_cache_map_.emplace(
std::move(browser_context_id), std::move(browser_context_id),
std::make_unique<SiteDataCacheImpl>(browser_context_id, context_path))); std::make_unique<SiteDataCacheImpl>(browser_context_id, context_path));
} }
} }
......
...@@ -198,12 +198,12 @@ void ArcUsbHostPermissionManager::RestorePermissionFromChromePrefs() { ...@@ -198,12 +198,12 @@ void ArcUsbHostPermissionManager::RestorePermissionFromChromePrefs() {
continue; continue;
} }
usb_access_permission_dict_.emplace(std::make_pair( usb_access_permission_dict_.emplace(
package, package,
UsbDeviceEntry(std::string() /*guid*/, UsbDeviceEntry(std::string() /*guid*/,
base::UTF8ToUTF16(device_name_value->GetString()), base::UTF8ToUTF16(device_name_value->GetString()),
base::UTF8ToUTF16(serial_number_value->GetString()), base::UTF8ToUTF16(serial_number_value->GetString()),
vendor_id, product_id))); vendor_id, product_id));
} }
} }
} }
......
...@@ -20,7 +20,7 @@ void CrostiniAppDisplay::Register(const std::string& app_id, ...@@ -20,7 +20,7 @@ void CrostiniAppDisplay::Register(const std::string& app_id,
} }
auto it = app_id_to_display_id_.find(app_id); auto it = app_id_to_display_id_.find(app_id);
if (it == app_id_to_display_id_.end()) { if (it == app_id_to_display_id_.end()) {
app_id_to_display_id_.emplace(std::make_pair(app_id, display_id)); app_id_to_display_id_.emplace(app_id, display_id);
app_ids_.push_back(app_id); app_ids_.push_back(app_id);
} else { } else {
it->second = display_id; it->second = display_id;
......
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