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

Side by Side Diff: chrome/browser/interests/interests_fetcher.h

Issue 1384973002: Add InterestsFetcher which retrieves a user's interests from the server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « chrome/browser/interests/OWNERS ('k') | chrome/browser/interests/interests_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Class to fetch topics of interest for a user as computed by Google Now. Each
22 // interest is a tuple of a name, a thumbnail URL and a relevance score. This
23 // class is one-shot. To retrieve interests multiple times use multiple
24 // instances of this class.
25 //
26 // Authentication is done via OAuth2 and requires the
27 // https://www.googleapis.com/auth/googlenow scope.
28 //
29 // If the InterestsFetcher is deleted before the callback is called then the
30 // request will be aborted. It is up to the user to ensure that both the
31 // Profile and the OAuth2TokenService outlive the InterestsFetcher.
32 //
33 // The server required for this feature is not publicly available yet.
34 class InterestsFetcher : public net::URLFetcherDelegate,
35 public OAuth2TokenService::Consumer {
36 public:
37 struct Interest {
38 Interest(const std::string& name, const GURL& image_url, double relevance);
39 ~Interest();
40
41 bool operator==(const Interest& interest) const;
42
43 std::string name;
44 GURL image_url;
45 double relevance;
46 };
47
48 using InterestsCallback = base::Callback<void(const std::vector<Interest>&)>;
49
50 InterestsFetcher(OAuth2TokenService* oauth2_token_service,
51 const std::string& account_id,
52 net::URLRequestContextGetter* context);
53
54 ~InterestsFetcher() override;
55
56 static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile);
57
58 void FetchInterests(const InterestsCallback& callback);
59
60 private:
61 // net::URLFetcherDelegate implementation.
62 void OnURLFetchComplete(const net::URLFetcher* source) override;
63
64 // OAuth2TokenService::Consumer implementation.
65 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
66 const std::string& access_token,
67 const base::Time& experiation_time) override;
68 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
69 const GoogleServiceAuthError& error) override;
70
71 void StartOAuth2Request();
72 OAuth2TokenService::ScopeSet GetApiScopes();
73 scoped_ptr<net::URLFetcher> CreateFetcher();
74
75 // Parse the json response.
76 std::vector<Interest> ExtractInterests(const std::string& response);
77
78 InterestsCallback callback_;
79 scoped_ptr<net::URLFetcher> fetcher_;
80 std::string account_id_;
81 net::URLRequestContextGetter* url_request_context_;
82 bool access_token_expired_;
83 std::string access_token_;
84
85 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
86 OAuth2TokenService* token_service_;
87
88 DISALLOW_COPY_AND_ASSIGN(InterestsFetcher);
89 };
90
91 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/interests/OWNERS ('k') | chrome/browser/interests/interests_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698