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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/state_store.cc

Issue 1342873002: Small logic change to StateStore::Transaction::ClearAll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/safe_browsing/incident_reporting/state_store.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // will result in a full serialize-and-write operation on the preferences 56 // will result in a full serialize-and-write operation on the preferences
57 // store. 57 // store.
58 std::string type_string(base::IntToString(static_cast<int32_t>(type))); 58 std::string type_string(base::IntToString(static_cast<int32_t>(type)));
59 const base::DictionaryValue* type_dict = nullptr; 59 const base::DictionaryValue* type_dict = nullptr;
60 if (store_->incidents_sent_->GetDictionaryWithoutPathExpansion(type_string, 60 if (store_->incidents_sent_->GetDictionaryWithoutPathExpansion(type_string,
61 &type_dict)) { 61 &type_dict)) {
62 GetPrefDict()->RemoveWithoutPathExpansion(type_string, nullptr); 62 GetPrefDict()->RemoveWithoutPathExpansion(type_string, nullptr);
63 } 63 }
64 } 64 }
65 65
66 void StateStore::Transaction::ClearAll() { 66 void StateStore::Transaction::ClearAll() {
grt (UTC plus 2) 2015/09/14 18:42:39 looks like there's no unittest for this. could you
proberge 2015/09/14 19:59:52 Done.
67 if (pref_update_) 67 // Clear the preference if it exists and contains any values.
68 pref_update_.reset(); 68 if (store_->incidents_sent_ && !store_->incidents_sent_->empty())
69 if (store_->incidents_sent_) { 69 GetPrefDict()->Clear();
70 store_->incidents_sent_ = nullptr;
71 store_->profile_->GetPrefs()->ClearPref(prefs::kSafeBrowsingIncidentsSent);
72 }
73 } 70 }
74 71
75 base::DictionaryValue* StateStore::Transaction::GetPrefDict() { 72 base::DictionaryValue* StateStore::Transaction::GetPrefDict() {
76 if (!pref_update_) { 73 if (!pref_update_) {
77 pref_update_.reset(new DictionaryPrefUpdate( 74 pref_update_.reset(new DictionaryPrefUpdate(
78 store_->profile_->GetPrefs(), prefs::kSafeBrowsingIncidentsSent)); 75 store_->profile_->GetPrefs(), prefs::kSafeBrowsingIncidentsSent));
79 // Getting the dict will cause it to be created if it doesn't exist. 76 // Getting the dict will cause it to be created if it doesn't exist.
80 // Unconditionally refresh the store's read-only view on the preference so 77 // Unconditionally refresh the store's read-only view on the preference so
81 // that it will always be correct. 78 // that it will always be correct.
82 store_->incidents_sent_ = pref_update_->Get(); 79 store_->incidents_sent_ = pref_update_->Get();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 static const IncidentType kLegacyTypes[] = { 147 static const IncidentType kLegacyTypes[] = {
151 // TODO(grt): remove in M44 (crbug.com/451173). 148 // TODO(grt): remove in M44 (crbug.com/451173).
152 IncidentType::OMNIBOX_INTERACTION, 149 IncidentType::OMNIBOX_INTERACTION,
153 }; 150 };
154 151
155 for (IncidentType type : kLegacyTypes) 152 for (IncidentType type : kLegacyTypes)
156 transaction->ClearForType(type); 153 transaction->ClearForType(type);
157 } 154 }
158 155
159 } // namespace safe_browsing 156 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698