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

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

Issue 2716583003: Rename Origin.unique() to opaque().
Patch Set: Mac fixes Created 3 years, 10 months 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 case blink::mojom::BudgetOperationType::INVALID_OPERATION: 42 case blink::mojom::BudgetOperationType::INVALID_OPERATION:
43 return SiteEngagementScore::kMaxPoints + 1; 43 return SiteEngagementScore::kMaxPoints + 1;
44 // No default case. 44 // No default case.
45 } 45 }
46 NOTREACHED(); 46 NOTREACHED();
47 return SiteEngagementScore::kMaxPoints + 1.0; 47 return SiteEngagementScore::kMaxPoints + 1.0;
48 } 48 }
49 49
50 void BudgetManager::GetBudget(const url::Origin& origin, 50 void BudgetManager::GetBudget(const url::Origin& origin,
51 const GetBudgetCallback& callback) { 51 const GetBudgetCallback& callback) {
52 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) { 52 if (origin.opaque() || !content::IsOriginSecure(origin.GetURL())) {
53 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED, 53 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED,
54 std::vector<blink::mojom::BudgetStatePtr>()); 54 std::vector<blink::mojom::BudgetStatePtr>());
55 return; 55 return;
56 } 56 }
57 db_.GetBudgetDetails(origin, 57 db_.GetBudgetDetails(origin,
58 base::Bind(&BudgetManager::DidGetBudget, 58 base::Bind(&BudgetManager::DidGetBudget,
59 weak_ptr_factory_.GetWeakPtr(), callback)); 59 weak_ptr_factory_.GetWeakPtr(), callback));
60 } 60 }
61 61
62 void BudgetManager::Reserve(const url::Origin& origin, 62 void BudgetManager::Reserve(const url::Origin& origin,
63 blink::mojom::BudgetOperationType type, 63 blink::mojom::BudgetOperationType type,
64 const ReserveCallback& callback) { 64 const ReserveCallback& callback) {
65 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) { 65 if (origin.opaque() || !content::IsOriginSecure(origin.GetURL())) {
66 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED, 66 callback.Run(blink::mojom::BudgetServiceErrorType::NOT_SUPPORTED,
67 false /* success */); 67 false /* success */);
68 return; 68 return;
69 } 69 }
70 db_.SpendBudget(origin, GetCost(type), 70 db_.SpendBudget(origin, GetCost(type),
71 base::Bind(&BudgetManager::DidReserve, 71 base::Bind(&BudgetManager::DidReserve,
72 weak_ptr_factory_.GetWeakPtr(), origin, callback)); 72 weak_ptr_factory_.GetWeakPtr(), origin, callback));
73 } 73 }
74 74
75 void BudgetManager::Consume(const url::Origin& origin, 75 void BudgetManager::Consume(const url::Origin& origin,
76 blink::mojom::BudgetOperationType type, 76 blink::mojom::BudgetOperationType type,
77 const ConsumeCallback& callback) { 77 const ConsumeCallback& callback) {
78 if (origin.unique() || !content::IsOriginSecure(origin.GetURL())) { 78 if (origin.opaque() || !content::IsOriginSecure(origin.GetURL())) {
79 callback.Run(false /* success */); 79 callback.Run(false /* success */);
80 return; 80 return;
81 } 81 }
82 82
83 bool found_reservation = false; 83 bool found_reservation = false;
84 84
85 // First, see if there is a reservation already. 85 // First, see if there is a reservation already.
86 auto count = reservation_map_.find(origin); 86 auto count = reservation_map_.find(origin);
87 if (count != reservation_map_.end()) { 87 if (count != reservation_map_.end()) {
88 if (count->second == 1) 88 if (count->second == 1)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 blink::mojom::BudgetServiceErrorType error, 135 blink::mojom::BudgetServiceErrorType error,
136 bool success) { 136 bool success) {
137 // If the call succeeded, write the new reservation into the map. 137 // If the call succeeded, write the new reservation into the map.
138 if (success && error == blink::mojom::BudgetServiceErrorType::NONE) 138 if (success && error == blink::mojom::BudgetServiceErrorType::NONE)
139 reservation_map_[origin]++; 139 reservation_map_[origin]++;
140 140
141 UMA_HISTOGRAM_BOOLEAN("Blink.BudgetAPI.Reserve", success); 141 UMA_HISTOGRAM_BOOLEAN("Blink.BudgetAPI.Reserve", success);
142 142
143 callback.Run(error, success); 143 callback.Run(error, success);
144 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698