Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/budget_service/budget_manager.cc

Issue 2524533002: Added UMA for usage of BudgetAPI calls. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/budget_service/budget_manager.h" 5 #include "chrome/browser/budget_service/budget_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return SiteEngagementScore::kMaxPoints + 1.0; 67 return SiteEngagementScore::kMaxPoints + 1.0;
68 } 68 }
69 69
70 void BudgetManager::GetBudget(const url::Origin& origin, 70 void BudgetManager::GetBudget(const url::Origin& origin,
71 const GetBudgetCallback& callback) { 71 const GetBudgetCallback& callback) {
72 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) { 72 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) {
73 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED, 73 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED,
74 mojo::Array<blink::mojom::BudgetStatePtr>()); 74 mojo::Array<blink::mojom::BudgetStatePtr>());
75 return; 75 return;
76 } 76 }
77 db_.GetBudgetDetails(origin, callback); 77 db_.GetBudgetDetails(origin,
78 base::Bind(&BudgetManager::DidGetBudget,
79 weak_ptr_factory_.GetWeakPtr(), callback));
78 } 80 }
79 81
80 void BudgetManager::Reserve(const url::Origin& origin, 82 void BudgetManager::Reserve(const url::Origin& origin,
81 blink::mojom::BudgetOperationType type, 83 blink::mojom::BudgetOperationType type,
82 const ReserveCallback& callback) { 84 const ReserveCallback& callback) {
83 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) { 85 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) {
84 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED, 86 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED,
85 false /* success */); 87 false /* success */);
86 return; 88 return;
87 } 89 }
(...skipping 27 matching lines...) Expand all
115 return; 117 return;
116 } 118 }
117 119
118 // If there wasn't a reservation already, try to directly consume budget. 120 // If there wasn't a reservation already, try to directly consume budget.
119 // The callback will return directly to the caller. 121 // The callback will return directly to the caller.
120 db_.SpendBudget(origin, GetCost(type), 122 db_.SpendBudget(origin, GetCost(type),
121 base::Bind(&BudgetManager::DidConsume, 123 base::Bind(&BudgetManager::DidConsume,
122 weak_ptr_factory_.GetWeakPtr(), callback)); 124 weak_ptr_factory_.GetWeakPtr(), callback));
123 } 125 }
124 126
127 void BudgetManager::DidGetBudget(
128 const GetBudgetCallback& callback,
129 const blink::mojom::BudgetServiceErrorType error,
130 mojo::Array<blink::mojom::BudgetStatePtr> budget) {
131 // If there was an error, just record a budget of 0, so the API query is still
132 // counted.
133 if (error != blink::mojom::BudgetServiceErrorType::NONE)
134 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BudgetAPIQuery", 0);
135 else
136 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BudgetAPIQuery",
137 budget[0]->budget_at);
Peter Beverloo 2016/11/28 10:59:00 What is the added value of recording the immediate
harkness 2016/11/28 13:58:04 I'd like to have an idea of whether the people who
Peter Beverloo 2016/11/28 14:14:06 But since UMA gives us aggregated data, we have no
harkness 2016/11/28 16:09:09 My gut feel for the API is that it will be used by
Peter Beverloo 2016/11/28 18:22:04 We have three variables for values in this histogr
harkness 2016/11/29 15:27:21 Discussed in person, summarizing here. The budget
138
139 callback.Run(error, std::move(budget));
140 }
141
125 void BudgetManager::DidConsume(const ConsumeCallback& callback, 142 void BudgetManager::DidConsume(const ConsumeCallback& callback,
126 blink::mojom::BudgetServiceErrorType error, 143 blink::mojom::BudgetServiceErrorType error,
127 bool success) { 144 bool success) {
128 // The caller of Consume only cares whether it succeeded or failed and not 145 // The caller of Consume only cares whether it succeeded or failed and not
129 // why. So, only return a combined bool. 146 // why. So, only return a combined bool.
130 if (error != blink::mojom::BudgetServiceErrorType::NONE) { 147 if (error != blink::mojom::BudgetServiceErrorType::NONE) {
131 callback.Run(false /* success */); 148 callback.Run(false /* success */);
132 return; 149 return;
133 } 150 }
134 callback.Run(success); 151 callback.Run(success);
135 } 152 }
136 153
137 void BudgetManager::DidReserve(const url::Origin& origin, 154 void BudgetManager::DidReserve(const url::Origin& origin,
138 const ReserveCallback& callback, 155 const ReserveCallback& callback,
139 blink::mojom::BudgetServiceErrorType error, 156 blink::mojom::BudgetServiceErrorType error,
140 bool success) { 157 bool success) {
141 // If the call succeeded, write the new reservation into the map. 158 // If the call succeeded, write the new reservation into the map.
142 if (success && error == blink::mojom::BudgetServiceErrorType::NONE) 159 if (success && error == blink::mojom::BudgetServiceErrorType::NONE)
143 reservation_map_[origin]++; 160 reservation_map_[origin]++;
144 161
162 UMA_HISTOGRAM_BOOLEAN("PushMessaging.BudgetAPIReserve", success);
163
145 callback.Run(error, success); 164 callback.Run(error, success);
146 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698