| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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_SUPERVISED_USER_REPORT_URL_H
_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_REPORT_URL_H
_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/supervised_user/report_url_request_creator.h" |
| 12 #include "google_apis/gaia/oauth2_token_service.h" |
| 13 #include "net/url_request/url_fetcher_delegate.h" |
| 14 #include "base/callback_forward.h" |
| 15 #include "base/containers/mru_cache.h" |
| 16 #include "base/macros.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 class GURL; |
| 20 class Profile; |
| 21 |
| 22 namespace net { |
| 23 class URLFetcher; |
| 24 class URLRequestContextGetter; |
| 25 } |
| 26 |
| 27 class SupervisedUserReportURLApiary : public OAuth2TokenService::Consumer, |
| 28 public net::URLFetcherDelegate, |
| 29 public ReportUrlRequestCreator { |
| 30 |
| 31 public: |
| 32 SupervisedUserReportURLApiary( |
| 33 OAuth2TokenService* oauth2_token_service, |
| 34 const std::string& account_id, |
| 35 net::URLRequestContextGetter* context); |
| 36 ~SupervisedUserReportURLApiary() override; |
| 37 |
| 38 static scoped_ptr<ReportUrlRequestCreator> CreateWithProfile( |
| 39 Profile* profile); |
| 40 |
| 41 // ReportUrlRequestCreator implementation |
| 42 void CreateReportUrlRequest(const GURL& url, |
| 43 const SuccessCallback& callback) override; |
| 44 |
| 45 void set_url_fetcher_id_for_testing(int id) { url_fetcher_id_ = id; } |
| 46 |
| 47 private: |
| 48 struct Request; |
| 49 using RequestIterator = std::vector<scoped_ptr<Request>>::iterator; |
| 50 |
| 51 // OAuth2TokenService::Consumer implementation: |
| 52 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 53 const std::string& access_token, |
| 54 const base::Time& expiration_time) override; |
| 55 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 56 const GoogleServiceAuthError& error) override; |
| 57 |
| 58 // net::URLFetcherDelegate implementation. |
| 59 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 60 |
| 61 // Requests an access token, which is the first thing we need. This is where |
| 62 // we restart when the returned access token has expired. |
| 63 void StartFetching(Request* request); |
| 64 |
| 65 void DispatchResult(RequestIterator it, bool success); |
| 66 |
| 67 OAuth2TokenService* oauth2_token_service_; |
| 68 std::string account_id_; |
| 69 net::URLRequestContextGetter* context_; |
| 70 int url_fetcher_id_; |
| 71 |
| 72 std::vector<scoped_ptr<Request>> requests_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SupervisedUserReportURLApiary); |
| 75 }; |
| 76 |
| 77 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_REPORT_URL
_H_ |
| OLD | NEW |