Histograms.xml python script housekeeping:
[chromium-blink-merge.git] / rlz / lib / rlz_lib_clear.cc
blob0dd13a40ab898201e005fa14948a2aa1db297b9d
1 // Copyright (c) 2012 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 // The methods in this file belong conceptually to rlz_lib.cc. However, some
6 // programs depend on rlz only to call ClearAllProductEvents(), so this file
7 // contains this in fairly self-contained form to make it easier for linkers
8 // to strip away most of rlz. In particular, this file should not reference any
9 // symbols defined in financial_ping.cc.
11 #include "rlz/lib/rlz_lib.h"
13 #include "base/lazy_instance.h"
14 #include "rlz/lib/assert.h"
15 #include "rlz/lib/rlz_value_store.h"
17 namespace rlz_lib {
19 bool ClearAllProductEvents(Product product) {
20 rlz_lib::ScopedRlzValueStoreLock lock;
21 rlz_lib::RlzValueStore* store = lock.GetStore();
22 if (!store || !store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess))
23 return false;
25 bool result;
26 result = store->ClearAllProductEvents(product);
27 result &= store->ClearAllStatefulEvents(product);
28 return result;
31 void ClearProductState(Product product, const AccessPoint* access_points) {
32 rlz_lib::ScopedRlzValueStoreLock lock;
33 rlz_lib::RlzValueStore* store = lock.GetStore();
34 if (!store || !store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess))
35 return;
37 // Delete all product specific state.
38 VERIFY(ClearAllProductEvents(product));
39 VERIFY(store->ClearPingTime(product));
41 // Delete all RLZ's for access points being uninstalled.
42 if (access_points) {
43 for (int i = 0; access_points[i] != NO_ACCESS_POINT; i++) {
44 VERIFY(store->ClearAccessPointRlz(access_points[i]));
48 store->CollectGarbage();
51 static base::LazyInstance<std::string>::Leaky g_supplemental_branding;
53 SupplementaryBranding::SupplementaryBranding(const char* brand)
54 : lock_(new ScopedRlzValueStoreLock) {
55 if (!lock_->GetStore())
56 return;
58 if (!g_supplemental_branding.Get().empty()) {
59 ASSERT_STRING("ProductBranding: existing brand is not empty");
60 return;
63 if (brand == NULL || brand[0] == 0) {
64 ASSERT_STRING("ProductBranding: new brand is empty");
65 return;
68 g_supplemental_branding.Get() = brand;
71 SupplementaryBranding::~SupplementaryBranding() {
72 if (lock_->GetStore())
73 g_supplemental_branding.Get().clear();
74 delete lock_;
77 // static
78 const std::string& SupplementaryBranding::GetBrand() {
79 return g_supplemental_branding.Get();
82 } // namespace rlz_lib