Chromium Code Reviews| Index: chrome/browser/webshare/share_target_pref_helper.cc |
| diff --git a/chrome/browser/webshare/share_target_pref_helper.cc b/chrome/browser/webshare/share_target_pref_helper.cc |
| index f09fc14ab79277635acfd30fab4a59316e6fe453..d0087d08dec97948bc0f1608790bc6e4c8684556 100644 |
| --- a/chrome/browser/webshare/share_target_pref_helper.cc |
| +++ b/chrome/browser/webshare/share_target_pref_helper.cc |
| @@ -4,29 +4,41 @@ |
| #include "chrome/browser/webshare/share_target_pref_helper.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| #include "chrome/common/pref_names.h" |
| #include "components/prefs/pref_service.h" |
| #include "components/prefs/scoped_user_pref_update.h" |
| -void UpdateShareTargetInPrefs(base::StringPiece manifest_url, |
| - base::Optional<std::string> url_template, |
| +void UpdateShareTargetInPrefs(const GURL& manifest_url, |
| + const content::Manifest& manifest, |
| PrefService* pref_service) { |
| DictionaryPrefUpdate update(pref_service, prefs::kWebShareVisitedTargets); |
| base::DictionaryValue* share_target_dict = update.Get(); |
| - if (!url_template.has_value()) { |
| - share_target_dict->RemoveWithoutPathExpansion(manifest_url, NULL); |
| + // Manifest does not contain a share_target field, or it does but there is no |
| + // url_template field. |
| + if (!manifest.share_target.has_value() || |
| + manifest.share_target.value().url_template.is_null()) { |
| + share_target_dict->RemoveWithoutPathExpansion(manifest_url.spec(), NULL); |
|
Matt Giuca
2017/02/06 00:40:11
s/NULL/nullptr
constantina
2017/02/07 05:16:25
Done.
|
| return; |
| } |
| + std::string url_template = |
| + base::UTF16ToUTF8(manifest.share_target.value().url_template.string()); |
| + |
| + constexpr char kNameKey[] = "name"; |
| constexpr char kUrlTemplateKey[] = "url_template"; |
| std::unique_ptr<base::DictionaryValue> origin_dict(new base::DictionaryValue); |
| + if (!manifest.name.is_null()) { |
| + origin_dict->SetStringWithoutPathExpansion(kNameKey, |
| + manifest.name.string()); |
| + } |
| origin_dict->SetStringWithoutPathExpansion(kUrlTemplateKey, |
| - url_template.value()); |
| + url_template); |
| - share_target_dict->SetWithoutPathExpansion(manifest_url, |
| + share_target_dict->SetWithoutPathExpansion(manifest_url.spec(), |
| std::move(origin_dict)); |
| } |