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

Side by Side Diff: components/web_restrictions/browser/web_restrictions_mojo_implementation.cc

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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 "components/web_restrictions/browser/web_restrictions_mojo_implementati on.h" 5 #include "components/web_restrictions/browser/web_restrictions_mojo_implementati on.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "components/web_restrictions/browser/web_restrictions_client.h" 10 #include "components/web_restrictions/browser/web_restrictions_client.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h"
11 12
12 namespace web_restrictions { 13 namespace web_restrictions {
13 14
14 namespace { 15 namespace {
15 16
16 void ClientRequestPermissionCallback( 17 void ClientRequestPermissionCallback(
17 const mojom::WebRestrictions::RequestPermissionCallback& callback, 18 const mojom::WebRestrictions::RequestPermissionCallback& callback,
18 bool result) { 19 bool result) {
19 callback.Run(result); 20 callback.Run(result);
20 } 21 }
21 22
22 } // namespace 23 } // namespace
23 24
25 WebRestrictionsMojoImplementation::WebRestrictionsMojoImplementation(
26 WebRestrictionsClient* client)
27 : web_restrictions_client_(client) {}
28
29 WebRestrictionsMojoImplementation::~WebRestrictionsMojoImplementation() {}
30
24 void WebRestrictionsMojoImplementation::Create( 31 void WebRestrictionsMojoImplementation::Create(
25 WebRestrictionsClient* client, 32 WebRestrictionsClient* client,
26 mojo::InterfaceRequest<mojom::WebRestrictions> request) { 33 mojo::InterfaceRequest<mojom::WebRestrictions> request) {
27 new WebRestrictionsMojoImplementation(client, std::move(request)); 34 mojo::MakeStrongBinding(
35 base::MakeUnique<WebRestrictionsMojoImplementation>(client),
36 std::move(request));
28 } 37 }
29 38
30 WebRestrictionsMojoImplementation::WebRestrictionsMojoImplementation(
31 WebRestrictionsClient* client,
32 mojo::InterfaceRequest<mojom::WebRestrictions> request)
33 : binding_(this, std::move(request)), web_restrictions_client_(client) {}
34
35 WebRestrictionsMojoImplementation::~WebRestrictionsMojoImplementation() {}
36
37 void WebRestrictionsMojoImplementation::GetResult( 39 void WebRestrictionsMojoImplementation::GetResult(
38 const std::string& url, 40 const std::string& url,
39 const GetResultCallback& callback) { 41 const GetResultCallback& callback) {
40 std::unique_ptr<const WebRestrictionsClientResult> web_restrictions_result( 42 std::unique_ptr<const WebRestrictionsClientResult> web_restrictions_result(
41 web_restrictions_client_->GetCachedWebRestrictionsResult(url)); 43 web_restrictions_client_->GetCachedWebRestrictionsResult(url));
42 mojom::ClientResultPtr result = mojom::ClientResult::New(); 44 mojom::ClientResultPtr result = mojom::ClientResult::New();
43 if (!web_restrictions_result) { 45 if (!web_restrictions_result) {
44 callback.Run(std::move(result)); 46 callback.Run(std::move(result));
45 return; 47 return;
46 } 48 }
(...skipping 11 matching lines...) Expand all
58 } 60 }
59 61
60 void WebRestrictionsMojoImplementation::RequestPermission( 62 void WebRestrictionsMojoImplementation::RequestPermission(
61 const std::string& url, 63 const std::string& url,
62 const mojom::WebRestrictions::RequestPermissionCallback& callback) { 64 const mojom::WebRestrictions::RequestPermissionCallback& callback) {
63 web_restrictions_client_->RequestPermission( 65 web_restrictions_client_->RequestPermission(
64 url, base::Bind(&ClientRequestPermissionCallback, callback)); 66 url, base::Bind(&ClientRequestPermissionCallback, callback));
65 } 67 }
66 68
67 } // namespace web_restrictions 69 } // namespace web_restrictions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698