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