Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / browser / user_metrics.cc
bloba1c7819a5443cae5b22aad918ce3051b06d06b7d
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/browser/user_metrics.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/lazy_instance.h"
11 #include "content/public/browser/browser_thread.h"
13 namespace content {
14 namespace {
16 base::LazyInstance<std::vector<ActionCallback> > g_action_callbacks =
17 LAZY_INSTANCE_INITIALIZER;
19 // Forward declare because of circular dependency.
20 void CallRecordOnUI(const std::string& action);
22 void Record(const char *action) {
23 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
24 BrowserThread::PostTask(
25 BrowserThread::UI,
26 FROM_HERE,
27 base::Bind(&CallRecordOnUI, action));
28 return;
31 for (size_t i = 0; i < g_action_callbacks.Get().size(); i++)
32 g_action_callbacks.Get()[i].Run(action);
35 void CallRecordOnUI(const std::string& action) {
36 Record(action.c_str());
39 } // namespace
41 void RecordAction(const UserMetricsAction& action) {
42 Record(action.str_);
45 void RecordComputedAction(const std::string& action) {
46 Record(action.c_str());
49 void AddActionCallback(const ActionCallback& callback) {
50 g_action_callbacks.Get().push_back(callback);
53 void RemoveActionCallback(const ActionCallback& callback) {
54 for (size_t i = 0; i < g_action_callbacks.Get().size(); i++) {
55 if (g_action_callbacks.Get()[i].Equals(callback)) {
56 g_action_callbacks.Get().erase(g_action_callbacks.Get().begin() + i);
57 return;
62 } // namespace content