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

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: Fix iOS Created 4 years, 10 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 namespace {
13
14 static const char kStorageKey[] = "SDCH";
15
16 } // namespace
17
18 SdchOwnerPrefStorage::SdchOwnerPrefStorage(PersistentPrefStore* storage)
19 : storage_(storage),
20 storage_key_(kStorageKey),
21 init_observer_(nullptr) {
22 }
23
24 SdchOwnerPrefStorage::~SdchOwnerPrefStorage() {
25 if (init_observer_)
26 storage_->RemoveObserver(this);
27 }
28
29 net::SdchOwner::PrefStorage::ReadError
30 SdchOwnerPrefStorage::GetReadError() const {
31 PersistentPrefStore::PrefReadError error = storage_->GetReadError();
32
33 DCHECK_NE(error,
34 PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE);
35 DCHECK_NE(error, PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM);
36
37 switch (error) {
38 case PersistentPrefStore::PREF_READ_ERROR_NONE:
39 return PERSISTENCE_FAILURE_NONE;
40
41 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE:
42 return PERSISTENCE_FAILURE_REASON_NO_FILE;
43
44 case PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE:
45 case PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE:
46 case PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER:
47 case PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED:
48 case PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT:
49 return PERSISTENCE_FAILURE_REASON_READ_FAILED;
50
51 case PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED:
52 case PersistentPrefStore::PREF_READ_ERROR_FILE_NOT_SPECIFIED:
53 case PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE:
54 case PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM:
55 default:
56 // We don't expect these other failures given our usage of prefs.
57 NOTREACHED();
58 return PERSISTENCE_FAILURE_REASON_OTHER;
59 }
60 }
61
62 bool SdchOwnerPrefStorage::GetValue(
63 const base::DictionaryValue** result) const {
64 const base::Value* result_value = nullptr;
65 if (!storage_->GetValue(storage_key_, &result_value))
66 return false;
67 return result_value->GetAsDictionary(result);
68 }
69
70 bool SdchOwnerPrefStorage::GetMutableValue(base::DictionaryValue** result) {
71 base::Value* result_value = nullptr;
72 if (!storage_->GetMutableValue(storage_key_, &result_value))
73 return false;
74 return result_value->GetAsDictionary(result);
75 }
76
77 void SdchOwnerPrefStorage::SetValue(scoped_ptr<base::DictionaryValue> value) {
78 storage_->SetValue(storage_key_, std::move(value),
79 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
80 }
81
82 void SdchOwnerPrefStorage::ReportValueChanged() {
83 storage_->ReportValueChanged(storage_key_,
84 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
85 }
86
87 bool SdchOwnerPrefStorage::IsInitializationComplete() {
88 return storage_->IsInitializationComplete();
89 }
90
91 void SdchOwnerPrefStorage::StartObservingInit(net::SdchOwner* observer) {
92 DCHECK(!init_observer_);
93 init_observer_ = observer;
94 storage_->AddObserver(this);
95 }
96
97 void SdchOwnerPrefStorage::StopObservingInit() {
98 DCHECK(init_observer_);
99 init_observer_ = nullptr;
100 storage_->RemoveObserver(this);
101 }
102
103 void SdchOwnerPrefStorage::OnPrefValueChanged(const std::string& key) {
104 }
105
106 void SdchOwnerPrefStorage::OnInitializationCompleted(bool succeeded) {
107 DCHECK(init_observer_);
108 init_observer_->OnPrefStorageInitializationComplete(succeeded);
109 }
110
111 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/sdch_owner_pref_storage.h ('k') | chrome/browser/profiles/profile_impl_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698