OLD | NEW |
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_database.h" | 5 #include "chrome/browser/budget_service/budget_database.h" |
6 | 6 |
7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
8 #include "base/time/clock.h" | 8 #include "base/time/clock.h" |
9 #include "base/time/default_clock.h" | 9 #include "base/time/default_clock.h" |
10 #include "chrome/browser/budget_service/budget.pb.h" | 10 #include "chrome/browser/budget_service/budget.pb.h" |
11 #include "components/leveldb_proto/proto_database_impl.h" | 11 #include "components/leveldb_proto/proto_database_impl.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // UMA are logged for the database with this string as part of the name. | 19 // UMA are logged for the database with this string as part of the name. |
20 // They will be LevelDB.*.BackgroundBudgetService. Changes here should be | 20 // They will be LevelDB.*.BudgetManager. Changes here should be synchronized |
21 // synchronized with histograms.xml. | 21 // with histograms.xml. |
22 const char kDatabaseUMAName[] = "BackgroundBudgetService"; | 22 const char kDatabaseUMAName[] = "BudgetManager"; |
23 | 23 |
24 // The default amount of time during which a budget will be valid. | 24 // The default amount of time during which a budget will be valid. |
25 // This is 3 days = 72 hours. | 25 // This is 3 days = 72 hours. |
26 constexpr double kBudgetDurationInHours = 72; | 26 constexpr double kBudgetDurationInHours = 72; |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 BudgetDatabase::BudgetDatabase( | 30 BudgetDatabase::BudgetDatabase( |
31 const base::FilePath& database_dir, | 31 const base::FilePath& database_dir, |
32 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 32 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 auto cleanup_iter = chunks.begin(); | 195 auto cleanup_iter = chunks.begin(); |
196 | 196 |
197 // This relies on the list of chunks being in timestamp order. | 197 // This relies on the list of chunks being in timestamp order. |
198 while (cleanup_iter != chunks.end() && cleanup_iter->expiration <= now) | 198 while (cleanup_iter != chunks.end() && cleanup_iter->expiration <= now) |
199 cleanup_iter = chunks.erase(cleanup_iter); | 199 cleanup_iter = chunks.erase(cleanup_iter); |
200 | 200 |
201 // If the entire budget is empty now, cleanup the map. | 201 // If the entire budget is empty now, cleanup the map. |
202 if (chunks.empty()) | 202 if (chunks.empty()) |
203 budget_map_.erase(origin.spec()); | 203 budget_map_.erase(origin.spec()); |
204 } | 204 } |
OLD | NEW |