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

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
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 a user's interests as computed by Google Now. Each interest is
22 // represented as a tuple of its name, an url to a representative image, and a
23 // score measuring the level of interest of the user.
24 //
25 // Authentication is done via OAuth2 and requires the
26 // https://www.googleapis.com/auth/googlenow scope.
27 //
28 // If the InterestsFetcher is deleted before the callback is called then the
29 // request will be aborted.
30 //
31 // It is up to the user to ensure that both the Profile and the
32 // OAuth2TokenService outlive the InterestsFetcher.
33 class InterestsFetcher : public net::URLFetcherDelegate,
34 public OAuth2TokenService::Consumer {
35 public:
36 struct Interest {
37 Interest(const std::string& name, const GURL& image_url, double relevance);
38 ~Interest();
39
40 bool operator==(const Interest& interest) const;
41
42 std::string name;
43 GURL image_url;
44 double relevance;
45 };
46
47 using InterestsCallback = base::Callback<void(const std::vector<Interest>&)>;
48
49 InterestsFetcher(OAuth2TokenService* oauth2_token_service,
50 const std::string& account_id,
51 net::URLRequestContextGetter* context);
52
53 ~InterestsFetcher() override;
54
55 static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile);
56
57 // This should only be called once per instance.
Bernhard Bauer 2015/10/06 13:44:12 Actually, I would move this to the top of the file
PEConn 2015/10/06 14:21:29 Done.
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

Powered by Google App Engine
This is Rietveld 408576698