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

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: Fix comments 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 //
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 please remove the example usage part of the commen
PEConn 2015/10/05 14:12:05 Done.
31 // Example Usage:
32 //
33 // auto request = make_scoped_ptr(new InterestsFetcher(callback));
34 //
35 class InterestsFetcher : public net::URLFetcherDelegate,
36 public OAuth2TokenService::Consumer {
37 public:
38 struct Interest {
39 std::string name;
40 GURL image_url;
41 double relevance;
42
43 Interest(const std::string& name, const GURL& image_url, float rlevance);
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 ctor and dtor should come before data members: htt
PEConn 2015/10/05 14:12:04 Done.
44
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 no empty line here
PEConn 2015/10/05 14:12:04 Done.
45 ~Interest();
46
47 bool operator==(const Interest& interest) const;
48 };
49
50 typedef base::Callback<void(const std::vector<Interest>&)>
51 InterestsCallback;
52
53 InterestsFetcher(
54 OAuth2TokenService* oauth2_token_service,
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 how do you guarantee that the token service is sti
PEConn 2015/10/05 14:12:04 The token service needs to be stored so we can ret
55 const std::string& account_id,
56 net::URLRequestContextGetter* context);
57
58 ~InterestsFetcher() override;
59
60 static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile);
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 can you have multiple fetchers per profile? Should
PEConn 2015/10/05 14:12:04 You can have multiple fetchers per profile. It's p
61
62 void Start(const InterestsCallback& callback);
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 this could use a comment what it starts (or a bett
PEConn 2015/10/05 14:12:04 Done.
63
64 private:
65 // net::URLFetcherDelegate implementation.
66 void OnURLFetchComplete(const net::URLFetcher* source) override;
67
68 // OAuth2TokenService::Consumer implementation.
69 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
70 const std::string& access_token,
71 const base::Time& experiation_time) override;
72
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 no empty line here
PEConn 2015/10/05 14:12:05 Done.
73 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
74 const GoogleServiceAuthError& error) override;
75
76 void StartOAuth2Request();
77
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 no empty line here
PEConn 2015/10/05 14:12:05 Done.
78 OAuth2TokenService::ScopeSet GetApiScopes();
79
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 nor here
PEConn 2015/10/05 14:12:05 Done.
80 scoped_ptr<net::URLFetcher> CreateFetcher();
81
82 // Parse the json response.
83 std::vector<Interest> ExtractInterests(const std::string& response);
84
85 InterestsCallback callback_;
86
87 scoped_ptr<net::URLFetcher> fetcher_;
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 sooo many empty lines here.
PEConn 2015/10/05 14:12:04 Done.
88
89 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
90
91 OAuth2TokenService* token_service_;
92
93 std::string account_id_;
94
95 net::URLRequestContextGetter* url_request_context_;
96
97 bool access_token_expired_;
98
99 std::string access_token_;
100
101
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 only one empty line here
PEConn 2015/10/05 14:12:05 Done.
102 DISALLOW_COPY_AND_ASSIGN(InterestsFetcher);
103 };
104
105 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698