OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ | |
6 #define CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/gtest_prod_util.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "chrome/browser/profiles/profile.h" | |
16 #include "components/signin/core/browser/signin_manager.h" | |
17 #include "google_apis/gaia/oauth2_token_service.h" | |
18 #include "net/url_request/url_fetcher.h" | |
19 #include "net/url_request/url_fetcher_delegate.h" | |
20 | |
21 | |
22 // Class to asynchronously retrieve the topics of interests for a user. | |
23 // Authentication is done using the user's OAuth access_token. | |
jochen (gone - plz use gerrit)
2015/09/30 09:23:09
this comment adds almost no information.
it shoul
tache
2015/09/30 17:32:02
Done.
| |
24 // | |
25 // If the InterestsFetcher is deleted before the callback is called then the | |
26 // request will be aborted. | |
27 // | |
28 // Example Usage: | |
29 // | |
30 // auto request = make_scoped_ptr(new InterestsFetcher(callback)); | |
31 // | |
32 class InterestsFetcher : public net::URLFetcherDelegate, | |
33 public OAuth2TokenService::Consumer { | |
34 public: | |
35 struct Interest { | |
36 std::string name; | |
jochen (gone - plz use gerrit)
2015/09/30 09:23:09
please add a ctor that takes parameters for all fi
tache
2015/09/30 17:32:02
Done.
| |
37 GURL image_url; | |
38 double relevance; | |
39 | |
40 bool operator==(const Interest& interest) const; | |
41 }; | |
42 | |
43 typedef base::Callback<void(const std::vector<Interest>&)> | |
44 InterestsCallback; | |
45 | |
46 InterestsFetcher( | |
47 OAuth2TokenService* oauth2_token_service, | |
48 const std::string& account_id, | |
49 net::URLRequestContextGetter* context); | |
50 | |
51 ~InterestsFetcher() override; | |
52 | |
53 static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile); | |
54 | |
55 void Start(const InterestsCallback& callback); | |
56 | |
57 | |
jochen (gone - plz use gerrit)
2015/09/30 09:23:09
please use fewer empty lines
tache
2015/09/30 17:32:02
Done.
| |
58 private: | |
59 // net::URLFetcherDelegate implementation. | |
60 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
61 | |
62 // OAuth2TokenService::Consumer implementation. | |
63 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
64 const std::string& access_token, | |
65 const base::Time& experiation_time) override; | |
66 | |
67 // OAuth2TokenService::Consumer implementation. | |
Bernhard Bauer
2015/09/30 08:14:08
This isn't necessary; just group all the methods f
tache
2015/09/30 17:32:02
Done.
| |
68 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
69 const GoogleServiceAuthError& error) override; | |
70 | |
71 void StartOAuth2Request(); | |
72 | |
73 OAuth2TokenService::ScopeSet GetApiScopes(); | |
74 | |
75 scoped_ptr<net::URLFetcher> CreateFetcher(); | |
76 | |
77 // Parse the json response. | |
78 std::vector<Interest> ExtractInterests(const std::string& response); | |
79 | |
80 | |
81 InterestsCallback callback_; | |
82 | |
83 scoped_ptr<net::URLFetcher> fetcher_; | |
84 | |
85 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | |
86 | |
87 OAuth2TokenService* token_service_; | |
88 | |
89 std::string account_id_; | |
90 | |
91 net::URLRequestContextGetter* url_request_context_; | |
92 | |
93 bool access_token_expired_; | |
94 | |
95 std::string access_token_; | |
96 | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(InterestsFetcher); | |
99 }; | |
100 | |
101 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ | |
OLD | NEW |