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

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

Issue 1317513004: Add InterestsFetcher which retrieves a user's interests from the server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Get the access_token in the InterestsFetcher 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
22 // Class to asynchronously retrieve the topics of interests for a user.
23 // Authentication is done using the user's OAuth access_token.
24 //
25 // The instance of this class should be deleted after the callback has been
26 // called else the request will be aborted.
Bernhard Bauer 2015/09/29 14:01:12 What does this comment mean? How can the request b
tache 2015/09/29 19:58:24 Sorry about that. Hope now it's clear.
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;
37 std::string image_url;
Bernhard Bauer 2015/09/29 14:01:12 Could this be a GURL?
tache 2015/09/29 19:58:24 Done.
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
58 private:
59 // net::URLFetcherDelegate implementation.
60 void OnURLFetchComplete(const net::URLFetcher* source) override;
61
62
63 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
Bernhard Bauer 2015/09/29 14:01:12 Also document which interface these methods implem
tache 2015/09/29 19:58:24 Done.
64 const std::string& access_token,
65 const base::Time& experiation_time) override;
66
67 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
68 const GoogleServiceAuthError& error) override;
69
70 scoped_ptr<net::URLFetcher> CreateFetcher();
71
72 // parse the json response
Bernhard Bauer 2015/09/29 14:01:12 Capitalize the beginning of the sentence, and end
tache 2015/09/29 19:58:24 Done.
73 std::vector<Interest> ExtractInterests(const std::string& response);
74
75
76 InterestsCallback callback_;
77
78 scoped_ptr<net::URLFetcher> fetcher_;
79
80 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
81
82 OAuth2TokenService* token_service_;
83
84 std::string account_id_;
85
86 net::URLRequestContextGetter* url_request_context_;
87
88
89 DISALLOW_COPY_AND_ASSIGN(InterestsFetcher);
90 };
91
92 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698