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

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

Issue 2524533002: Added UMA for usage of BudgetAPI calls. (Closed)
Patch Set: Code review comments Created 4 years 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 double budget_at = error != blink::mojom::BudgetServiceErrorType::NONE
134 ? 0
135 : budget[0]->budget_at;
Alexei Svitkine (slow) 2016/12/01 18:25:10 Nit: This looks a bit messy to me. How about: dou
harkness 2016/12/02 13:12:38 Done.
136 UMA_HISTOGRAM_COUNTS_100("BudgetAPI.QueryBudget", budget_at);
137
138 callback.Run(error, std::move(budget));
139 }
140
125 void BudgetManager::DidConsume(const ConsumeCallback& callback, 141 void BudgetManager::DidConsume(const ConsumeCallback& callback,
126 blink::mojom::BudgetServiceErrorType error, 142 blink::mojom::BudgetServiceErrorType error,
127 bool success) { 143 bool success) {
128 // The caller of Consume only cares whether it succeeded or failed and not 144 // The caller of Consume only cares whether it succeeded or failed and not
129 // why. So, only return a combined bool. 145 // why. So, only return a combined bool.
130 if (error != blink::mojom::BudgetServiceErrorType::NONE) { 146 if (error != blink::mojom::BudgetServiceErrorType::NONE) {
131 callback.Run(false /* success */); 147 callback.Run(false /* success */);
132 return; 148 return;
133 } 149 }
134 callback.Run(success); 150 callback.Run(success);
135 } 151 }
136 152
137 void BudgetManager::DidReserve(const url::Origin& origin, 153 void BudgetManager::DidReserve(const url::Origin& origin,
138 const ReserveCallback& callback, 154 const ReserveCallback& callback,
139 blink::mojom::BudgetServiceErrorType error, 155 blink::mojom::BudgetServiceErrorType error,
140 bool success) { 156 bool success) {
141 // If the call succeeded, write the new reservation into the map. 157 // If the call succeeded, write the new reservation into the map.
142 if (success && error == blink::mojom::BudgetServiceErrorType::NONE) 158 if (success && error == blink::mojom::BudgetServiceErrorType::NONE)
143 reservation_map_[origin]++; 159 reservation_map_[origin]++;
144 160
161 UMA_HISTOGRAM_BOOLEAN("BudgetAPI.Reserve", success);
162
145 callback.Run(error, success); 163 callback.Run(error, success);
146 } 164 }
OLDNEW
« no previous file with comments | « chrome/browser/budget_service/budget_manager.h ('k') | chrome/browser/budget_service/budget_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698