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

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

Issue 2639463002: Add a pref name for share targets, and store their manifest data. (Closed)
Patch Set: Separate tests, add .h, as per feedback Created 3 years, 11 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
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

Powered by Google App Engine
This is Rietveld 408576698