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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..66df8e6bb58646f783dc859b873f52ac68c89d62 |
--- /dev/null |
+++ b/chrome/browser/webshare/share_target_pref_helper.cc |
@@ -0,0 +1,39 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/webshare/share_target_pref_helper.h" |
+ |
+#include <sstream> |
Matt Giuca
2017/01/24 03:26:09
No more sstream.
constantina
2017/01/24 23:39:04
Done.
|
+ |
+#include "chrome/common/pref_names.h" |
+#include "components/prefs/pref_service.h" |
+#include "components/prefs/scoped_user_pref_update.h" |
+#include "content/public/common/manifest.h" |
+ |
+namespace webshare { |
+ |
+void AddShareTargetToPrefs(base::StringPiece share_target_origin, |
+ base::Optional<std::string> url_template, |
+ PrefService* pref_service) { |
+ DictionaryPrefUpdate update(pref_service, prefs::kWebShareVisitedTargets); |
+ base::DictionaryValue* share_target_dict = update.Get(); |
+ |
+ if (!url_template.has_value()) { |
+ if (share_target_dict->HasKey(share_target_origin)) |
+ share_target_dict->RemoveWithoutPathExpansion(share_target_origin, NULL); |
Matt Giuca
2017/01/24 03:26:09
Does this need a check at all? If the key is missi
constantina
2017/01/24 23:39:04
Yeah, it does nothing. Deleted.
|
+ return; |
+ } |
+ |
+ constexpr char kUrlTemplateKey[] = "url_template"; |
+ |
+ std::unique_ptr<base::DictionaryValue> origin_dict(new base::DictionaryValue); |
+ |
+ origin_dict->SetStringWithoutPathExpansion(kUrlTemplateKey, |
+ url_template.value()); |
+ |
+ share_target_dict->SetWithoutPathExpansion(share_target_origin, |
+ std::move(origin_dict)); |
+} |
+ |
+} // namespace webshare |