OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SAFE_SEARCH_URL_REPORTER_H_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SAFE_SEARCH_URL_REPORTER_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "google_apis/gaia/oauth2_token_service.h" |
| 10 #include "net/url_request/url_fetcher_delegate.h" |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 class GURL; |
| 16 class Profile; |
| 17 |
| 18 namespace net { |
| 19 class URLFetcher; |
| 20 class URLReportContextGetter; |
| 21 } |
| 22 |
| 23 class SafeSearchURLReporter : public OAuth2TokenService::Consumer, |
| 24 public net::URLFetcherDelegate { |
| 25 public: |
| 26 using SuccessCallback = base::Callback<void(bool)>; |
| 27 |
| 28 SafeSearchURLReporter(OAuth2TokenService* oauth2_token_service, |
| 29 const std::string& account_id, |
| 30 net::URLRequestContextGetter* context); |
| 31 ~SafeSearchURLReporter() override; |
| 32 |
| 33 static scoped_ptr<SafeSearchURLReporter> CreateWithProfile(Profile* profile); |
| 34 |
| 35 void ReportUrl(const GURL& url, const SuccessCallback& callback); |
| 36 |
| 37 void set_url_fetcher_id_for_testing(int id) { url_fetcher_id_ = id; } |
| 38 |
| 39 private: |
| 40 struct Report; |
| 41 using ReportIterator = std::vector<scoped_ptr<Report>>::iterator; |
| 42 |
| 43 // OAuth2TokenService::Consumer implementation: |
| 44 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 45 const std::string& access_token, |
| 46 const base::Time& expiration_time) override; |
| 47 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 48 const GoogleServiceAuthError& error) override; |
| 49 |
| 50 // net::URLFetcherDelegate implementation. |
| 51 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 52 |
| 53 // Requests an access token, which is the first thing we need. This is where |
| 54 // we restart when the returned access token has expired. |
| 55 void StartFetching(Report* Report); |
| 56 |
| 57 void DispatchResult(ReportIterator it, bool success); |
| 58 |
| 59 OAuth2TokenService* oauth2_token_service_; |
| 60 std::string account_id_; |
| 61 net::URLRequestContextGetter* context_; |
| 62 int url_fetcher_id_; |
| 63 |
| 64 std::vector<scoped_ptr<Report>> reports_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(SafeSearchURLReporter); |
| 67 }; |
| 68 |
| 69 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SAFE_SEARCH_URL_REPORTER_
H_ |
OLD | NEW |