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

Side by Side Diff: ios/crnet/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: Review comments 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 "ios/crnet/sdch_owner_pref_storage.h"
6
7 #include "base/prefs/persistent_pref_store.h"
8 #include "base/values.h"
9
10 namespace {
11
12 static const char kStorageKey[] = "SDCH";
13
14 } // namespace
15
16 SdchOwnerPrefStorage::SdchOwnerPrefStorage(PersistentPrefStore* storage)
17 : storage_(storage),
18 storage_key_(KStorageKey),
19 init_observer_(nullptr) {
20 }
21
22 SdchOwnerPrefStorage::~SdchOwnerPrefStorage() {
23 if (init_observer_)
24 storage_->RemoveObserver(this);
25 }
26
27 net::SdchOwner::PrefStorage::ReadError
28 SdchOwnerPrefStorage::GetReadError() const {
29 PersistentPrefStore::PrefReadError error = storage_->GetReadError();
30
31 DCHECK_NE(error,
32 PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE);
33 DCHECK_NE(error, PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM);
34
35 switch (error) {
36 case PersistentPrefStore::PREF_READ_ERROR_NONE:
37 return PERSISTENCE_FAILURE_NONE;
38
39 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE:
40 return PERSISTENCE_FAILURE_REASON_NO_FILE;
41
42 case PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE:
43 case PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE:
44 case PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER:
45 case PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED:
46 case PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT:
47 return PERSISTENCE_FAILURE_REASON_READ_FAILED;
48
49 case PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED:
50 case PersistentPrefStore::PREF_READ_ERROR_FILE_NOT_SPECIFIED:
51 case PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE:
52 case PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM:
53 default:
54 // We don't expect these other failures given our usage of prefs.
55 NOTREACHED();
56 return PERSISTENCE_FAILURE_OTHER;
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 DCHECK(init_observer_);
106 init_observer_->OnPrefStorageInitializationComplete(succeeded);
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698