electron/atom/browser/render_process_preferences.cc
Shelley Vohr 9f328abe19 refactor: remove instances of createDeepCopy (#13703)
* add new native_mate converters for base::Value

* fix converter swapping

* remove createDeepCopy from browser/api

* replace missing ListValue converter

* convert bulk of remaining createDeepCopy instances

* convert last remaining instances of createDeepCopy

* incremental progress and helper methods for value conversion

* convert Get and add template function for GetString

* final DictionaryValue method conversions

* remove usage of base::DictionaryValue in web_contents_preferences

* use IsEnabled helper where possible

* Update atom_api_web_view_manager.cc
2018-08-04 07:23:07 +10:00

60 lines
1.8 KiB
C++

// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/render_process_preferences.h"
#include "atom/common/api/api_messages.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
namespace atom {
RenderProcessPreferences::RenderProcessPreferences(const Predicate& predicate)
: predicate_(predicate) {
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
content::NotificationService::AllBrowserContextsAndSources());
}
RenderProcessPreferences::~RenderProcessPreferences() {}
int RenderProcessPreferences::AddEntry(const base::DictionaryValue& entry) {
int id = ++next_id_;
entries_[id] =
base::DictionaryValue::From(base::Value::ToUniquePtrValue(entry.Clone()));
cache_needs_update_ = true;
return id;
}
void RenderProcessPreferences::RemoveEntry(int id) {
cache_needs_update_ = true;
entries_.erase(id);
}
void RenderProcessPreferences::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, content::NOTIFICATION_RENDERER_PROCESS_CREATED);
content::RenderProcessHost* process =
content::Source<content::RenderProcessHost>(source).ptr();
if (!predicate_.Run(process))
return;
UpdateCache();
process->Send(new AtomMsg_UpdatePreferences(cached_entries_));
}
void RenderProcessPreferences::UpdateCache() {
if (!cache_needs_update_)
return;
cached_entries_.Clear();
for (const auto& iter : entries_)
cached_entries_.Append(iter.second->CreateDeepCopy());
cache_needs_update_ = false;
}
} // namespace atom