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

Side by Side Diff: chrome/browser/supervised_user/experimental/safe_search_url_reporter.cc

Issue 1878143002: Convert //chrome/browser/supervised_user from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/supervised_user/experimental/safe_search_url_reporter.h " 5 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h "
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/signin/signin_manager_factory.h" 13 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "components/signin/core/browser/profile_oauth2_token_service.h" 14 #include "components/signin/core/browser/profile_oauth2_token_service.h"
14 #include "components/signin/core/browser/signin_manager.h" 15 #include "components/signin/core/browser/signin_manager.h"
15 #include "components/signin/core/browser/signin_manager_base.h" 16 #include "components/signin/core/browser/signin_manager_base.h"
16 #include "google_apis/gaia/google_service_auth_error.h" 17 #include "google_apis/gaia/google_service_auth_error.h"
17 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
(...skipping 13 matching lines...) Expand all
32 33
33 // Request keys 34 // Request keys
34 const char kUrlKey[] = "url"; 35 const char kUrlKey[] = "url";
35 36
36 struct SafeSearchURLReporter::Report { 37 struct SafeSearchURLReporter::Report {
37 Report(const GURL& url, const SuccessCallback& callback, int url_fetcher_id); 38 Report(const GURL& url, const SuccessCallback& callback, int url_fetcher_id);
38 ~Report(); 39 ~Report();
39 40
40 GURL url; 41 GURL url;
41 SuccessCallback callback; 42 SuccessCallback callback;
42 scoped_ptr<OAuth2TokenService::Request> access_token_request; 43 std::unique_ptr<OAuth2TokenService::Request> access_token_request;
43 std::string access_token; 44 std::string access_token;
44 bool access_token_expired; 45 bool access_token_expired;
45 int url_fetcher_id; 46 int url_fetcher_id;
46 scoped_ptr<URLFetcher> url_fetcher; 47 std::unique_ptr<URLFetcher> url_fetcher;
47 }; 48 };
48 49
49 SafeSearchURLReporter::Report::Report(const GURL& url, 50 SafeSearchURLReporter::Report::Report(const GURL& url,
50 const SuccessCallback& callback, 51 const SuccessCallback& callback,
51 int url_fetcher_id) 52 int url_fetcher_id)
52 : url(url), 53 : url(url),
53 callback(callback), 54 callback(callback),
54 access_token_expired(false), 55 access_token_expired(false),
55 url_fetcher_id(url_fetcher_id) {} 56 url_fetcher_id(url_fetcher_id) {}
56 57
57 SafeSearchURLReporter::Report::~Report() {} 58 SafeSearchURLReporter::Report::~Report() {}
58 59
59 SafeSearchURLReporter::SafeSearchURLReporter( 60 SafeSearchURLReporter::SafeSearchURLReporter(
60 OAuth2TokenService* oauth2_token_service, 61 OAuth2TokenService* oauth2_token_service,
61 const std::string& account_id, 62 const std::string& account_id,
62 net::URLRequestContextGetter* context) 63 net::URLRequestContextGetter* context)
63 : OAuth2TokenService::Consumer("safe_search_url_reporter"), 64 : OAuth2TokenService::Consumer("safe_search_url_reporter"),
64 oauth2_token_service_(oauth2_token_service), 65 oauth2_token_service_(oauth2_token_service),
65 account_id_(account_id), 66 account_id_(account_id),
66 context_(context), 67 context_(context),
67 url_fetcher_id_(0) {} 68 url_fetcher_id_(0) {}
68 69
69 SafeSearchURLReporter::~SafeSearchURLReporter() {} 70 SafeSearchURLReporter::~SafeSearchURLReporter() {}
70 71
71 // static 72 // static
72 scoped_ptr<SafeSearchURLReporter> SafeSearchURLReporter::CreateWithProfile( 73 std::unique_ptr<SafeSearchURLReporter> SafeSearchURLReporter::CreateWithProfile(
73 Profile* profile) { 74 Profile* profile) {
74 ProfileOAuth2TokenService* token_service = 75 ProfileOAuth2TokenService* token_service =
75 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 76 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
76 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); 77 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
77 return make_scoped_ptr(new SafeSearchURLReporter( 78 return base::WrapUnique(new SafeSearchURLReporter(
78 token_service, signin->GetAuthenticatedAccountId(), 79 token_service, signin->GetAuthenticatedAccountId(),
79 profile->GetRequestContext())); 80 profile->GetRequestContext()));
80 } 81 }
81 82
82 void SafeSearchURLReporter::ReportUrl(const GURL& url, 83 void SafeSearchURLReporter::ReportUrl(const GURL& url,
83 const SuccessCallback& callback) { 84 const SuccessCallback& callback) {
84 reports_.push_back( 85 reports_.push_back(
85 make_scoped_ptr(new Report(url, callback, url_fetcher_id_))); 86 base::WrapUnique(new Report(url, callback, url_fetcher_id_)));
86 StartFetching(reports_.back().get()); 87 StartFetching(reports_.back().get());
87 } 88 }
88 89
89 void SafeSearchURLReporter::StartFetching(Report* report) { 90 void SafeSearchURLReporter::StartFetching(Report* report) {
90 OAuth2TokenService::ScopeSet scopes; 91 OAuth2TokenService::ScopeSet scopes;
91 scopes.insert(kApiScope); 92 scopes.insert(kApiScope);
92 report->access_token_request = 93 report->access_token_request =
93 oauth2_token_service_->StartRequest(account_id_, scopes, this); 94 oauth2_token_service_->StartRequest(account_id_, scopes, this);
94 } 95 }
95 96
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return; 175 return;
175 } 176 }
176 177
177 DispatchResult(it, true); 178 DispatchResult(it, true);
178 } 179 }
179 180
180 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) { 181 void SafeSearchURLReporter::DispatchResult(ReportIterator it, bool success) {
181 (*it)->callback.Run(success); 182 (*it)->callback.Run(success);
182 reports_.erase(it); 183 reports_.erase(it);
183 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698