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

Side by Side Diff: chrome/browser/webshare/share_service_impl.cc

Issue 2849143002: webshare: Small refactor of WebShare (OnceCallback, const&, and alias) (Closed)
Patch Set: Add new line Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_service_impl.h" 5 #include "chrome/browser/webshare/share_service_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 split_template.push_back(url_template.substr( 98 split_template.push_back(url_template.substr(
99 start_index_to_copy, url_template.size() - start_index_to_copy)); 99 start_index_to_copy, url_template.size() - start_index_to_copy));
100 100
101 *url_template_filled = base::JoinString(split_template, base::StringPiece()); 101 *url_template_filled = base::JoinString(split_template, base::StringPiece());
102 return true; 102 return true;
103 } 103 }
104 104
105 void ShareServiceImpl::ShowPickerDialog( 105 void ShareServiceImpl::ShowPickerDialog(
106 const std::vector<std::pair<base::string16, GURL>>& targets, 106 const std::vector<std::pair<base::string16, GURL>>& targets,
107 const base::Callback<void(base::Optional<std::string>)>& callback) { 107 chrome::WebShareTargetPickerCallback callback) {
108 // TODO(mgiuca): Get the browser window as |parent_window|. 108 // TODO(mgiuca): Get the browser window as |parent_window|.
109 chrome::ShowWebShareTargetPickerDialog(nullptr /* parent_window */, targets, 109 chrome::ShowWebShareTargetPickerDialog(nullptr /* parent_window */, targets,
110 callback); 110 std::move(callback));
111 } 111 }
112 112
113 Browser* ShareServiceImpl::GetBrowser() { 113 Browser* ShareServiceImpl::GetBrowser() {
114 return BrowserList::GetInstance()->GetLastActive(); 114 return BrowserList::GetInstance()->GetLastActive();
115 } 115 }
116 116
117 void ShareServiceImpl::OpenTargetURL(const GURL& target_url) { 117 void ShareServiceImpl::OpenTargetURL(const GURL& target_url) {
118 Browser* browser = GetBrowser(); 118 Browser* browser = GetBrowser();
119 chrome::AddTabAt(browser, target_url, 119 chrome::AddTabAt(browser, target_url,
120 browser->tab_strip_model()->active_index() + 1, true); 120 browser->tab_strip_model()->active_index() + 1, true);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 share_targets = GetPrefService() 180 share_targets = GetPrefService()
181 ->GetDictionary(prefs::kWebShareVisitedTargets) 181 ->GetDictionary(prefs::kWebShareVisitedTargets)
182 ->CreateDeepCopy(); 182 ->CreateDeepCopy();
183 183
184 std::vector<std::pair<base::string16, GURL>> sufficiently_engaged_targets = 184 std::vector<std::pair<base::string16, GURL>> sufficiently_engaged_targets =
185 GetTargetsWithSufficientEngagement(*share_targets); 185 GetTargetsWithSufficientEngagement(*share_targets);
186 186
187 ShowPickerDialog( 187 ShowPickerDialog(
188 sufficiently_engaged_targets, 188 sufficiently_engaged_targets,
189 base::Bind(&ShareServiceImpl::OnPickerClosed, weak_factory_.GetWeakPtr(), 189 base::BindOnce(&ShareServiceImpl::OnPickerClosed,
190 base::Passed(&share_targets), title, text, share_url, 190 weak_factory_.GetWeakPtr(), base::Passed(&share_targets),
191 callback)); 191 title, text, share_url, callback));
192 } 192 }
193 193
194 void ShareServiceImpl::OnPickerClosed( 194 void ShareServiceImpl::OnPickerClosed(
195 std::unique_ptr<base::DictionaryValue> share_targets, 195 std::unique_ptr<base::DictionaryValue> share_targets,
196 const std::string& title, 196 const std::string& title,
197 const std::string& text, 197 const std::string& text,
198 const GURL& share_url, 198 const GURL& share_url,
199 const ShareCallback& callback, 199 const ShareCallback& callback,
200 base::Optional<std::string> result) { 200 const base::Optional<std::string>& result) {
201 if (!result.has_value()) { 201 if (!result.has_value()) {
202 callback.Run(blink::mojom::ShareError::CANCELED); 202 callback.Run(blink::mojom::ShareError::CANCELED);
203 return; 203 return;
204 } 204 }
205 205
206 std::string chosen_target = result.value(); 206 std::string chosen_target = result.value();
207 207
208 std::string url_template = GetTargetTemplate(chosen_target, *share_targets); 208 std::string url_template = GetTargetTemplate(chosen_target, *share_targets);
209 std::string url_template_filled; 209 std::string url_template_filled;
210 if (!ReplacePlaceholders(url_template, title, text, share_url, 210 if (!ReplacePlaceholders(url_template, title, text, share_url,
(...skipping 15 matching lines...) Expand all
226 // - The base URL: can't be invalid since it's derived from the manifest URL. 226 // - The base URL: can't be invalid since it's derived from the manifest URL.
227 // - The template: can only be invalid if it contains a NUL character or 227 // - The template: can only be invalid if it contains a NUL character or
228 // invalid UTF-8 sequence (which it can't have). 228 // invalid UTF-8 sequence (which it can't have).
229 // - The replaced pieces: these are escaped. 229 // - The replaced pieces: these are escaped.
230 // If somehow we slip through this DCHECK, it will just open about:blank. 230 // If somehow we slip through this DCHECK, it will just open about:blank.
231 DCHECK(target.is_valid()); 231 DCHECK(target.is_valid());
232 OpenTargetURL(target); 232 OpenTargetURL(target);
233 233
234 callback.Run(blink::mojom::ShareError::OK); 234 callback.Run(blink::mojom::ShareError::OK);
235 } 235 }
OLDNEW
« no previous file with comments | « chrome/browser/webshare/share_service_impl.h ('k') | chrome/browser/webshare/share_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698