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

Side by Side Diff: chrome/browser/net/sdch_owner_pref_storage.cc

Issue 1634653003: Abstract pref storage from net::SdchOwner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@net_prefs
Patch Set: Created 4 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/sdch_owner_pref_storage.h"
6
7 #include "base/prefs/persistent_pref_store.h"
8 #include "base/values.h"
9
10 namespace chrome_browser_net {
11
12 SdchOwnerPrefStorage::SdchOwnerPrefStorage(PersistentPrefStore* storage)
13 : storage_(storage),
14 storage_key_("SDCH"),
Randy Smith (Not in Mondays) 2016/01/27 21:48:17 I'd like this to be abstracted out into a constant
15 init_observer_(nullptr) {
16 }
17
18 SdchOwnerPrefStorage::~SdchOwnerPrefStorage() {
19 if (init_observer_)
20 storage_->RemoveObserver(this);
21 }
22
23 net::SdchOwner::PrefStorage::ReadError
24 SdchOwnerPrefStorage::GetReadError() const {
25 PersistentPrefStore::PrefReadError error = storage_->GetReadError();
26
27 DCHECK_NE(error,
28 PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE);
29 DCHECK_NE(error, PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM);
30
31 switch (error) {
32 case PersistentPrefStore::PREF_READ_ERROR_NONE:
33 return PERSISTENCE_FAILURE_NONE;
34
35 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE:
36 return PERSISTENCE_FAILURE_REASON_NO_FILE;
37
38 case PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE:
39 case PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE:
40 case PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER:
41 case PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED:
42 case PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT:
43 return PERSISTENCE_FAILURE_REASON_READ_FAILED;
44
45 case PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED:
46 case PersistentPrefStore::PREF_READ_ERROR_FILE_NOT_SPECIFIED:
47 case PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE:
48 case PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM:
49 default:
50 // This may seem a bit odd but our goal here is to map errors we expect
51 // to a histogram that the SDCH system cares about. We don't expect to
52 // get these errors with our usage, and there is no histogram value for
53 // them, which is why we return "none" rather than having a general
54 // "other" error value.
Randy Smith (Not in Mondays) 2016/01/27 21:48:17 Could you say a bit more about your logic here? I
brettw 2016/01/27 22:23:54 I was trying to avoid updating the histogram but n
55 NOTREACHED();
56 return PERSISTENCE_FAILURE_NONE;
57 }
58 }
59
60 bool SdchOwnerPrefStorage::GetValue(
61 const base::DictionaryValue** result) const {
62 const base::Value* result_value = nullptr;
63 if (!storage_->GetValue(storage_key_, &result_value))
64 return false;
65 return result_value->GetAsDictionary(result);
66 }
67
68 bool SdchOwnerPrefStorage::GetMutableValue(base::DictionaryValue** result) {
69 base::Value* result_value = nullptr;
70 if (!storage_->GetMutableValue(storage_key_, &result_value))
71 return false;
72 return result_value->GetAsDictionary(result);
73 }
74
75 void SdchOwnerPrefStorage::SetValue(scoped_ptr<base::DictionaryValue> value) {
76 storage_->SetValue(storage_key_, std::move(value),
77 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
78 }
79
80 void SdchOwnerPrefStorage::ReportValueChanged() {
81 storage_->ReportValueChanged(storage_key_,
82 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
83 }
84
85 bool SdchOwnerPrefStorage::IsInitializationComplete() {
86 return storage_->IsInitializationComplete();
87 }
88
89 void SdchOwnerPrefStorage::StartObservingInit(net::SdchOwner* observer) {
90 DCHECK(!init_observer_);
91 init_observer_ = observer;
92 storage_->AddObserver(this);
93 }
94
95 void SdchOwnerPrefStorage::StopObservingInit() {
96 DCHECK(init_observer_);
97 init_observer_ = nullptr;
98 storage_->RemoveObserver(this);
99 }
100
101 void SdchOwnerPrefStorage::OnPrefValueChanged(const std::string& key) {
102 }
103
104 void SdchOwnerPrefStorage::OnInitializationCompleted(bool succeeded) {
105 init_observer_->OnPrefStorageInitializationComplete(succeeded);
Randy Smith (Not in Mondays) 2016/01/27 21:48:17 There's an implication in this line about the inte
brettw 2016/01/27 22:23:54 I changed the comments in the interface to make th
Randy Smith (Not in Mondays) 2016/01/28 17:45:56 Ah, gotcha. That makes sense. Sorry about the mi
106 }
107
108 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698