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

Side by Side Diff: services/preferences/public/cpp/pref_store_impl.cc

Issue 2706383002: DO NOT SUBMIT: Show silent service manager failure (Closed)
Patch Set: Created 3 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 2017 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 "services/preferences/public/cpp/pref_store_impl.h"
6
7 #include <memory>
8
9 #include "base/values.h"
10
11 namespace prefs {
12
13 // static
14 std::unique_ptr<PrefStoreImpl> PrefStoreImpl::Create(
15 mojom::PrefStoreRegistryPtr registry_ptr,
16 scoped_refptr<::PrefStore> pref_store,
17 PrefValueStore::PrefStoreType type) {
18 LOG(INFO) << "PrefStoreImpl::Create";
19 mojom::PrefStorePtr ptr;
20 auto impl = base::MakeUnique<PrefStoreImpl>(std::move(pref_store),
21 mojo::MakeRequest(&ptr));
22 registry_ptr->Register(std::move(ptr), type);
23 return impl;
24 }
25
26 PrefStoreImpl::PrefStoreImpl(scoped_refptr<::PrefStore> pref_store,
27 mojom::PrefStoreRequest request)
28 : backing_pref_store_(std::move(pref_store)),
29 initialized_(false),
30 binding_(this, std::move(request)) {
31 DCHECK(backing_pref_store_);
32 if (backing_pref_store_->IsInitializationComplete())
33 OnInitializationCompleted(true);
34 backing_pref_store_->AddObserver(this);
35 }
36
37 PrefStoreImpl::~PrefStoreImpl() {
38 backing_pref_store_->RemoveObserver(this);
39 }
40
41 void PrefStoreImpl::OnPrefValueChanged(const std::string& key) {
42 auto dictionary = base::MakeUnique<base::DictionaryValue>();
43 const base::Value* value = nullptr;
44 if (backing_pref_store_->GetValue(key, &value)) {
45 dictionary->SetWithoutPathExpansion(key, value->CreateDeepCopy());
46 } else {
47 dictionary->SetWithoutPathExpansion(key, base::Value::CreateNullValue());
48 }
49 for (const auto& observer : observers_)
50 observer->OnPreferencesChanged(dictionary->CreateDeepCopy());
51 }
52
53 void PrefStoreImpl::OnInitializationCompleted(bool succeeded) {
54 // Some pref stores call this more than once. We just ignore all calls after
55 // the first.
56 if (initialized_) {
57 DCHECK(succeeded);
58 return;
59 }
60 initialized_ = succeeded;
61 for (const auto& observer : observers_)
62 observer->OnInitializationCompleted(succeeded);
63 }
64
65 void PrefStoreImpl::AddObserver(const AddObserverCallback& callback) {
66 mojom::PrefStoreObserverPtr observer_ptr;
67 auto request = mojo::MakeRequest(&observer_ptr);
68 observers_.push_back(std::move(observer_ptr));
69 mojom::PrefStoreConnectionPtr connection = mojom::PrefStoreConnection::New();
70 connection->observer = std::move(request);
71 connection->initial_prefs = backing_pref_store_->GetValues();
72 connection->is_initialized = backing_pref_store_->IsInitializationComplete();
73 callback.Run(std::move(connection));
74 }
75
76 } // namespace prefs
OLDNEW
« no previous file with comments | « services/preferences/public/cpp/pref_store_impl.h ('k') | services/preferences/public/cpp/pref_store_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698