Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/webshare/share_target_pref_helper.h" | 5 #include "chrome/browser/webshare/share_target_pref_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 9 #include "components/prefs/pref_service.h" | 10 #include "components/prefs/pref_service.h" |
| 10 #include "components/prefs/scoped_user_pref_update.h" | 11 #include "components/prefs/scoped_user_pref_update.h" |
| 11 | 12 |
| 12 void UpdateShareTargetInPrefs(base::StringPiece manifest_url, | 13 void UpdateShareTargetInPrefs(const GURL& manifest_url, |
| 13 base::Optional<std::string> url_template, | 14 const content::Manifest& manifest, |
| 14 PrefService* pref_service) { | 15 PrefService* pref_service) { |
| 15 DictionaryPrefUpdate update(pref_service, prefs::kWebShareVisitedTargets); | 16 DictionaryPrefUpdate update(pref_service, prefs::kWebShareVisitedTargets); |
| 16 base::DictionaryValue* share_target_dict = update.Get(); | 17 base::DictionaryValue* share_target_dict = update.Get(); |
| 17 | 18 |
| 18 if (!url_template.has_value()) { | 19 // Manifest does not contain a share_target field, or it does but there is no |
| 19 share_target_dict->RemoveWithoutPathExpansion(manifest_url, NULL); | 20 // url_template field. |
| 21 if (!manifest.share_target.has_value() || | |
| 22 manifest.share_target.value().url_template.is_null()) { | |
| 23 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.
| |
| 20 return; | 24 return; |
| 21 } | 25 } |
| 22 | 26 |
| 27 std::string url_template = | |
| 28 base::UTF16ToUTF8(manifest.share_target.value().url_template.string()); | |
| 29 | |
| 30 constexpr char kNameKey[] = "name"; | |
| 23 constexpr char kUrlTemplateKey[] = "url_template"; | 31 constexpr char kUrlTemplateKey[] = "url_template"; |
| 24 | 32 |
| 25 std::unique_ptr<base::DictionaryValue> origin_dict(new base::DictionaryValue); | 33 std::unique_ptr<base::DictionaryValue> origin_dict(new base::DictionaryValue); |
| 26 | 34 |
| 35 if (!manifest.name.is_null()) { | |
| 36 origin_dict->SetStringWithoutPathExpansion(kNameKey, | |
| 37 manifest.name.string()); | |
| 38 } | |
| 27 origin_dict->SetStringWithoutPathExpansion(kUrlTemplateKey, | 39 origin_dict->SetStringWithoutPathExpansion(kUrlTemplateKey, |
| 28 url_template.value()); | 40 url_template); |
| 29 | 41 |
| 30 share_target_dict->SetWithoutPathExpansion(manifest_url, | 42 share_target_dict->SetWithoutPathExpansion(manifest_url.spec(), |
| 31 std::move(origin_dict)); | 43 std::move(origin_dict)); |
| 32 } | 44 } |
| OLD | NEW |