Chromium Code Reviews| Index: base/test/user_action_tester.cc |
| diff --git a/base/test/user_action_tester.cc b/base/test/user_action_tester.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..578d8bbee13e1c62c9b0fac8d8a275e97f072b50 |
| --- /dev/null |
| +++ b/base/test/user_action_tester.cc |
| @@ -0,0 +1,36 @@ |
| +// Copyright 2015 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 "base/test/user_action_tester.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/metrics/user_metrics.h" |
|
Mark Mentovai
2015/04/13 20:08:37
Me too.
|
| + |
| +namespace base { |
| + |
| +UserActionTester::UserActionTester() |
| + : action_callback_( |
| + base::Bind(&UserActionTester::OnUserAction, base::Unretained(this))) { |
| + base::AddActionCallback(action_callback_); |
| +} |
| + |
| +UserActionTester::~UserActionTester() { |
| + base::RemoveActionCallback(action_callback_); |
| +} |
| + |
| +int UserActionTester::GetActionCount(const std::string& user_action) const { |
| + UserActionCountMap::const_iterator iter = count_map_.find(user_action); |
| + return iter == count_map_.end() ? 0 : iter->second; |
| +} |
| + |
| +void UserActionTester::ResetCounts() { |
| + count_map_.clear(); |
| +} |
| + |
| +void UserActionTester::OnUserAction(const std::string& user_action) { |
| + ++(count_map_[user_action]); |
| +} |
| + |
| +} // namespace base |