OLD | NEW |
(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 "chrome/browser/webshare/share_target_pref_helper.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/common/pref_names.h" |
| 9 #include "components/prefs/pref_service.h" |
| 10 #include "components/prefs/scoped_user_pref_update.h" |
| 11 |
| 12 void UpdateShareTargetInPrefs(base::StringPiece manifest_url, |
| 13 base::Optional<std::string> url_template, |
| 14 PrefService* pref_service) { |
| 15 DictionaryPrefUpdate update(pref_service, prefs::kWebShareVisitedTargets); |
| 16 base::DictionaryValue* share_target_dict = update.Get(); |
| 17 |
| 18 if (!url_template.has_value()) { |
| 19 share_target_dict->RemoveWithoutPathExpansion(manifest_url, NULL); |
| 20 return; |
| 21 } |
| 22 |
| 23 constexpr char kUrlTemplateKey[] = "url_template"; |
| 24 |
| 25 std::unique_ptr<base::DictionaryValue> origin_dict(new base::DictionaryValue); |
| 26 |
| 27 origin_dict->SetStringWithoutPathExpansion(kUrlTemplateKey, |
| 28 url_template.value()); |
| 29 |
| 30 share_target_dict->SetWithoutPathExpansion(manifest_url, |
| 31 std::move(origin_dict)); |
| 32 } |
OLD | NEW |