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

Unified Diff: chrome/browser/webshare/share_target_pref_helper.cc

Issue 2679523002: Store target app name in Web Share prefs, and add extra logic. (Closed)
Patch Set: My nits 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 side-by-side diff with in-line comments
Download patch
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..9b9ea4b1fe95585850c0175853b56542c56f0579 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(), nullptr);
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));
}

Powered by Google App Engine
This is Rietveld 408576698