OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |
6 #define CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ | 6 #define CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 Interest(const std::string& name, const GURL& image_url, double relevance); | 38 Interest(const std::string& name, const GURL& image_url, double relevance); |
39 ~Interest(); | 39 ~Interest(); |
40 | 40 |
41 bool operator==(const Interest& interest) const; | 41 bool operator==(const Interest& interest) const; |
42 | 42 |
43 std::string name; | 43 std::string name; |
44 GURL image_url; | 44 GURL image_url; |
45 double relevance; | 45 double relevance; |
46 }; | 46 }; |
47 | 47 |
48 using InterestsCallback = base::Callback<void(const std::vector<Interest>&)>; | 48 using InterestsCallback = |
| 49 base::Callback<void(scoped_ptr<std::vector<Interest>>)>; |
49 | 50 |
50 InterestsFetcher(OAuth2TokenService* oauth2_token_service, | 51 InterestsFetcher(OAuth2TokenService* oauth2_token_service, |
51 const std::string& account_id, | 52 const std::string& account_id, |
52 net::URLRequestContextGetter* context); | 53 net::URLRequestContextGetter* context); |
53 | 54 |
54 ~InterestsFetcher() override; | 55 ~InterestsFetcher() override; |
55 | 56 |
56 static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile); | 57 static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile); |
57 | 58 |
58 void FetchInterests(const InterestsCallback& callback); | 59 void FetchInterests(const InterestsCallback& callback); |
59 | 60 |
60 private: | 61 private: |
61 // net::URLFetcherDelegate implementation. | 62 // net::URLFetcherDelegate implementation. |
62 void OnURLFetchComplete(const net::URLFetcher* source) override; | 63 void OnURLFetchComplete(const net::URLFetcher* source) override; |
63 | 64 |
64 // OAuth2TokenService::Consumer implementation. | 65 // OAuth2TokenService::Consumer implementation. |
65 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 66 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
66 const std::string& access_token, | 67 const std::string& access_token, |
67 const base::Time& experiation_time) override; | 68 const base::Time& experiation_time) override; |
68 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 69 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
69 const GoogleServiceAuthError& error) override; | 70 const GoogleServiceAuthError& error) override; |
70 | 71 |
71 void StartOAuth2Request(); | 72 void StartOAuth2Request(); |
72 OAuth2TokenService::ScopeSet GetApiScopes(); | 73 OAuth2TokenService::ScopeSet GetApiScopes(); |
73 scoped_ptr<net::URLFetcher> CreateFetcher(); | 74 scoped_ptr<net::URLFetcher> CreateFetcher(); |
74 | 75 |
75 // Parse the json response. | 76 // Parse the json response. |
76 std::vector<Interest> ExtractInterests(const std::string& response); | 77 scoped_ptr<std::vector<Interest>> |
| 78 ExtractInterests(const std::string& response); |
77 | 79 |
78 InterestsCallback callback_; | 80 InterestsCallback callback_; |
79 scoped_ptr<net::URLFetcher> fetcher_; | 81 scoped_ptr<net::URLFetcher> fetcher_; |
80 std::string account_id_; | 82 std::string account_id_; |
81 net::URLRequestContextGetter* url_request_context_; | 83 net::URLRequestContextGetter* url_request_context_; |
82 bool access_token_expired_; | 84 bool access_token_expired_; |
83 std::string access_token_; | 85 std::string access_token_; |
84 | 86 |
85 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | 87 scoped_ptr<OAuth2TokenService::Request> oauth_request_; |
86 OAuth2TokenService* token_service_; | 88 OAuth2TokenService* token_service_; |
87 | 89 |
88 DISALLOW_COPY_AND_ASSIGN(InterestsFetcher); | 90 DISALLOW_COPY_AND_ASSIGN(InterestsFetcher); |
89 }; | 91 }; |
90 | 92 |
91 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ | 93 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |
OLD | NEW |