Commit 8d90918d authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Remove mojo/public/cpp/bindings/map.h.

Convert all callers to use base::flat_map in the first place, instead of
using std::map and then converting them. Fix link errors along the way.

Change-Id: I34bd7b2c42cfb5cdcd68d4e0880b82633b989697
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892437Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712876}
parent 45215f1e
......@@ -40,7 +40,6 @@
#include "chromeos/dbus/power/fake_power_manager_client.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/user_names.h"
#include "mojo/public/cpp/bindings/map.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
......
......@@ -4,11 +4,14 @@
#include "chrome/browser/chromeos/power/ml/smart_dim/ml_service_client.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/power/ml/smart_dim/model_impl.h"
#include "chromeos/constants/chromeos_features.h"
......@@ -16,7 +19,6 @@
#include "chromeos/services/machine_learning/public/mojom/graph_executor.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/tensor.mojom.h"
#include "mojo/public/cpp/bindings/map.h"
#include "mojo/public/cpp/bindings/remote.h"
using ::chromeos::machine_learning::mojom::BuiltinModelId;
......@@ -169,7 +171,7 @@ void MlServiceClientImpl::DoInference(
InitMlServiceHandlesIfNeeded();
// Prepare the input tensor.
std::map<std::string, TensorPtr> inputs;
base::flat_map<std::string, TensorPtr> inputs;
auto tensor = Tensor::New();
tensor->shape = Int64List::New();
tensor->shape->value = std::vector<int64_t>({1, features.size()});
......@@ -182,7 +184,7 @@ void MlServiceClientImpl::DoInference(
std::vector<std::string> outputs({std::string("output")});
executor_->Execute(
mojo::MapToFlatMap(std::move(inputs)), std::move(outputs),
std::move(inputs), std::move(outputs),
base::BindOnce(&MlServiceClientImpl::ExecuteCallback,
weak_factory_.GetWeakPtr(), get_prediction_callback,
std::move(decision_callback)));
......
......@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_ML_SERVICE_CLIENT_H_
#define CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_ML_SERVICE_CLIENT_H_
#include <utility>
#include <memory>
#include <vector>
#include "base/callback.h"
......@@ -20,8 +20,7 @@ namespace ml {
// inference on inputs provided by the caller.
class MlServiceClient {
public:
MlServiceClient() = default;
virtual ~MlServiceClient() {}
virtual ~MlServiceClient() = default;
// Sends an input vector to the ML service to run inference on. It also
// provides a |decision_callback| to the Mojo service which will be run
......
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_list/search/search_result_ranker/ml_app_rank_provider.h"
#include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
......@@ -21,7 +23,6 @@
#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/map.h"
#include "ui/base/resource/resource_bundle.h"
using ::chromeos::machine_learning::mojom::BuiltinModelId;
......@@ -76,15 +77,15 @@ bool LoadExamplePreprocessorConfig(
// Perform the inference given the |features| and |app_id| of an app.
// Posts |callback| to |task_runner| to perform the actual inference.
void DoInference(
const std::string& app_id,
const std::vector<float>& features,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::RepeatingCallback<void(std::map<std::string, TensorPtr> inputs,
const std::vector<std::string> outputs,
const std::string app_id)> callback) {
void DoInference(const std::string& app_id,
const std::vector<float>& features,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::RepeatingCallback<
void(base::flat_map<std::string, TensorPtr> inputs,
const std::vector<std::string> outputs,
const std::string app_id)> callback) {
// Prepare the input tensor.
std::map<std::string, TensorPtr> inputs;
base::flat_map<std::string, TensorPtr> inputs;
auto tensor = Tensor::New();
tensor->shape = Int64List::New();
tensor->shape->value = std::vector<int64_t>({1, features.size()});
......@@ -104,10 +105,10 @@ void DoInference(
// Returns true on success.
bool RankerExampleToVectorizedFeatures(
const assist_ranker::ExamplePreprocessorConfig& preprocessor_config,
assist_ranker::RankerExample& example,
assist_ranker::RankerExample* example,
std::vector<float>* vectorized_features) {
int preprocessor_error = assist_ranker::ExamplePreprocessor::Process(
preprocessor_config, &example, true);
preprocessor_config, example, true);
// kNoFeatureIndexFound can occur normally (e.g., when the app URL
// isn't known to the model or a rarely seen enum value is used).
if (preprocessor_error != assist_ranker::ExamplePreprocessor::kSuccess &&
......@@ -118,7 +119,7 @@ bool RankerExampleToVectorizedFeatures(
}
const auto& extracted_features =
example.features()
example->features()
.at(assist_ranker::ExamplePreprocessor::kVectorizedFeatureDefaultName)
.float_list()
.float_value();
......@@ -137,9 +138,10 @@ void CreateRankingsImpl(
int all_clicks_last_hour,
int all_clicks_last_24_hours,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::RepeatingCallback<void(std::map<std::string, TensorPtr> inputs,
const std::vector<std::string> outputs,
const std::string app_id)>& callback) {
const base::RepeatingCallback<
void(base::flat_map<std::string, TensorPtr> inputs,
const std::vector<std::string> outputs,
const std::string app_id)>& callback) {
const base::Time now(base::Time::Now());
const int hour = HourOfDay(now);
const int day = DayOfWeek(now);
......@@ -156,7 +158,7 @@ void CreateRankingsImpl(
total_hours, day, hour, all_clicks_last_hour,
all_clicks_last_24_hours));
std::vector<float> vectorized_features;
if (RankerExampleToVectorizedFeatures(preprocessor_config, example,
if (RankerExampleToVectorizedFeatures(preprocessor_config, &example,
&vectorized_features)) {
DoInference(app.first, vectorized_features, task_runner, callback);
}
......@@ -283,12 +285,13 @@ std::map<std::string, float> MlAppRankProvider::RetrieveRankings() {
return ranking_map_;
}
void MlAppRankProvider::RunExecutor(std::map<std::string, TensorPtr> inputs,
const std::vector<std::string> outputs,
const std::string app_id) {
void MlAppRankProvider::RunExecutor(
base::flat_map<std::string, TensorPtr> inputs,
const std::vector<std::string> outputs,
const std::string app_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(creation_sequence_checker_);
BindGraphExecutorIfNeeded();
executor_->Execute(mojo::MapToFlatMap(std::move(inputs)), std::move(outputs),
executor_->Execute(std::move(inputs), std::move(outputs),
base::BindOnce(&MlAppRankProvider::ExecuteCallback,
base::Unretained(this), app_id));
}
......
......@@ -7,9 +7,9 @@
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
......@@ -62,8 +62,8 @@ class MlAppRankProvider {
private:
// Execute the |executor_| on the creation thread.
void RunExecutor(
std::map<std::string, ::chromeos::machine_learning::mojom::TensorPtr>
inputs,
base::flat_map<std::string,
::chromeos::machine_learning::mojom::TensorPtr> inputs,
std::vector<std::string> outputs,
std::string app_id);
......
......@@ -4,9 +4,10 @@
#include "chrome/browser/ui/app_list/search/search_result_ranker/search_ranking_event_logger.h"
#include <cmath>
#include <utility>
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/containers/flat_map.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
......@@ -20,7 +21,6 @@
#include "components/assist_ranker/example_preprocessing.h"
#include "components/crx_file/id_util.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
#include "mojo/public/cpp/bindings/map.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -51,7 +51,7 @@ constexpr base::TimeDelta kDelayForHistoryService =
// exponent used for counts that are not seconds is 1.15 (via
// ukm::GetExponentialBucketMinForCounts1000). The first value skipped by
// bucketing is 10.
constexpr float kBucketExponentForSeconds = 1.045;
constexpr float kBucketExponentForSeconds = 1.045f;
// The UMA histogram that logs the error occurs in inference code.
constexpr char kInferenceError[] = "Apps.AppList.AggregatedSearchRankerError";
......@@ -313,7 +313,7 @@ void SearchRankingEventLogger::PopulateSearchRankingItem(
}
}
if (event_info->last_launch != base::nullopt) {
if (event_info->last_launch.has_value()) {
base::Time last_launch = event_info->last_launch.value();
base::Time::Exploded last_launch_exploded;
last_launch.LocalExplode(&last_launch_exploded);
......@@ -576,7 +576,7 @@ void SearchRankingEventLogger::DoInference(const std::vector<float>& features,
BindGraphExecutorIfNeeded();
// Prepare the input tensor.
std::map<std::string, TensorPtr> inputs;
base::flat_map<std::string, TensorPtr> inputs;
auto tensor = Tensor::New();
tensor->shape = Int64List::New();
tensor->shape->value = std::vector<int64_t>({1, features.size()});
......@@ -588,7 +588,7 @@ void SearchRankingEventLogger::DoInference(const std::vector<float>& features,
const std::vector<std::string> outputs({std::string("output")});
// Execute
executor_->Execute(mojo::MapToFlatMap(std::move(inputs)), std::move(outputs),
executor_->Execute(std::move(inputs), std::move(outputs),
base::BindOnce(&SearchRankingEventLogger::ExecuteCallback,
weak_factory_.GetWeakPtr(), id));
}
......
......@@ -6,8 +6,8 @@
#define CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_SEARCH_RANKING_EVENT_LOGGER_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "ash/public/cpp/app_list/app_list_types.h"
......
......@@ -88,7 +88,6 @@ component("bindings_base") {
"lib/validation_errors.h",
"lib/validation_util.cc",
"lib/validation_util.h",
"map.h",
"map_data_view.h",
"map_traits.h",
"map_traits_flat_map.h",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
#define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
#include <map>
#include <utility>
#include "base/containers/flat_map.h"
namespace mojo {
// TODO(yzshen): These conversion functions should be removed and callsites
// should be revisited and changed to use the same map type.
template <typename Key, typename Value>
base::flat_map<Key, Value> MapToFlatMap(const std::map<Key, Value>& input) {
return base::flat_map<Key, Value>(input.begin(), input.end());
}
template <typename Key, typename Value>
base::flat_map<Key, Value> MapToFlatMap(std::map<Key, Value>&& input) {
return base::flat_map<Key, Value>(std::make_move_iterator(input.begin()),
std::make_move_iterator(input.end()));
}
template <typename Key, typename Value>
std::map<Key, Value> FlatMapToMap(const base::flat_map<Key, Value>& input) {
return std::map<Key, Value>(input.begin(), input.end());
}
template <typename Key, typename Value>
std::map<Key, Value> FlatMapToMap(base::flat_map<Key, Value>&& input) {
return std::map<Key, Value>(std::make_move_iterator(input.begin()),
std::make_move_iterator(input.end()));
}
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
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