 Chromium Code Reviews
 Chromium Code Reviews Issue 2639463002:
  Add a pref name for share targets, and store their manifest data.  (Closed)
    
  
    Issue 2639463002:
  Add a pref name for share targets, and store their manifest data.  (Closed) 
  | 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..d82d957a1879395d6d4234cf21e111b24d9a5cee | 
| --- /dev/null | 
| +++ b/chrome/browser/webshare/share_target_pref_helper.cc | 
| @@ -0,0 +1,45 @@ | 
| +// Copyright 2016 The Chromium Authors. All rights reserved. | 
| 
Matt Giuca
2017/01/23 03:00:57
Copyright 2017.
 
constantina
2017/01/24 02:03:42
OMG. Done.
 | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| 
Matt Giuca
2017/01/23 03:00:57
You need a .h file for this file.
Also you need t
 
constantina
2017/01/24 02:03:42
Done.
 | 
| +#include <sstream> | 
| + | 
| +#include "base/strings/string16.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" | 
| +#include "content/public/common/manifest.h" | 
| + | 
| +namespace { | 
| 
Matt Giuca
2017/01/23 03:00:57
This can't be in an anonymous namespace, since it
 
constantina
2017/01/24 02:03:43
Done. Used 'webshare'.
 
Matt Giuca
2017/01/24 03:26:09
We haven't used the "webshare" namespace anywhere
 
constantina
2017/01/24 23:39:04
Done.
 | 
| + | 
| +// Adds the Web Share target |share_target_origin| with template |url_template| | 
| +// to |pref_service| under kWebShareVisitedTargets. If |url_template| is null, | 
| +// this function does nothing. | 
| 
Matt Giuca
2017/01/23 03:00:58
Obsolete comment? It removes the target from the p
 
constantina
2017/01/24 02:03:42
Yeah, obsolete. Removed.
 | 
| +void AddShareTargetToPrefs(std::string share_target_origin, | 
| 
Matt Giuca
2017/01/23 03:00:57
StringPiece?
 
constantina
2017/01/24 02:03:42
Done.
 | 
| + base::NullableString16 share_target_url_template, | 
| 
Matt Giuca
2017/01/23 03:00:57
Hmm, I think it would be more natural to accept a
 
constantina
2017/01/24 02:03:42
I do care about optionality, because we want to al
 | 
| + PrefService* pref_service) { | 
| + DictionaryPrefUpdate update(pref_service, prefs::kWebShareVisitedTargets); | 
| + base::DictionaryValue* share_target_dict = update.Get(); | 
| + | 
| + if (share_target_url_template.is_null()) { | 
| 
Matt Giuca
2017/01/23 03:00:57
nit: && rather than two if statements.
 
constantina
2017/01/24 02:03:42
There are supposed to be two distinct cases here,
 
Matt Giuca
2017/01/24 03:26:09
I see, I misread it.
No, don't do the same check
 
constantina
2017/01/24 23:39:04
Done.
 | 
| + if (share_target_dict->HasKey(share_target_origin)) | 
| + share_target_dict->RemoveWithoutPathExpansion(share_target_origin, NULL); | 
| + return; | 
| + } | 
| + | 
| + constexpr char kUrlTemplateKey[] = "url_template"; | 
| + | 
| + std::unique_ptr<base::DictionaryValue> origin_dict(new base::DictionaryValue); | 
| + | 
| + std::stringstream ss; | 
| + ss << share_target_url_template.string(); | 
| + std::string url_template; | 
| + ss >> url_template; | 
| 
Matt Giuca
2017/01/23 03:00:57
What's with the stringstream? Are you just doing t
 
constantina
2017/01/24 02:03:43
Done.
 | 
| + origin_dict->SetStringWithoutPathExpansion(kUrlTemplateKey, url_template); | 
| + | 
| + share_target_dict->SetWithoutPathExpansion(share_target_origin, | 
| 
Matt Giuca
2017/01/23 03:58:56
As discussed offline, this should actually be keye
 
constantina
2017/01/24 02:03:43
Done.
 | 
| + std::move(origin_dict)); | 
| +} | 
| + | 
| +} // namespace |