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

Side by Side Diff: chrome/browser/interests/interests_retriever.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: Created 5 years, 3 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 | « no previous file | chrome/browser/interests/interests_retriever.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_RETRIEVER_H_
6 #define CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_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 "net/url_request/url_fetcher.h"
16 #include "net/url_request/url_fetcher_delegate.h"
17 #include "net/url_request/url_fetcher_factory.h"
18
19 FORWARD_DECLARE_TEST(InterestsRetrieverTest, DefaultFakeResponse);
20
21 // Class to asynchronously retrieve the topics of interests for a user.
22 // Authentication is done using the user's OAUTH access_token.
Marc Treib 2015/09/03 15:35:06 nit: OAuth
tache 2015/09/03 16:25:30 Done.
23 //
24 // Example Usage:
25 //
26 // auto request = scoped_ptr<InterestsRetriever>(new InterestsRetriever(
Marc Treib 2015/09/03 15:35:06 make_scoped_ptr(new ... then you don't have to wri
tache 2015/09/03 16:25:30 Done.
27 // "user_access_token",
28 // callback));
29 //
30 class InterestsRetriever : public net::URLFetcherDelegate {
Marc Treib 2015/09/03 15:35:06 Hm, "Fetcher" is much more common in Chromium than
tache 2015/09/03 16:25:30 Done.
31 public:
32 struct Interest {
33 std::string name;
34 std::string image_url;
35 double relevance;
36
37 bool operator==(const Interest& interest) const;
38 };
39
40 typedef base::Callback<void(const std::vector<Interest>&)>
41 InterestsCallback;
42
43 InterestsRetriever(net::URLRequestContextGetter* url_request_context,
44 const std::string& access_token,
45 const InterestsCallback& callback,
46 net::URLFetcherFactory* url_fetcher_factory);
47
48 ~InterestsRetriever() override;
49
50 private:
51 FRIEND_TEST_ALL_PREFIXES(::InterestsRetrieverTest, DefaultFakeResponse);
52
53 // net::URLFetcherDelegate implementation.
54 void OnURLFetchComplete(const net::URLFetcher* source) override;
55
56 scoped_ptr<net::URLFetcher> CreateFetcher();
57
58 // parse the json response
59 std::vector<Interest> ExtractInterests(const std::string& response);
60
61 //
62 // Currently the InterestsRetreiever servers a static response since the API
Marc Treib 2015/09/03 15:35:06 s/servers/serves/g
tache 2015/09/03 16:25:30 Done.
63 // is not ready yet.
64 // This method is needed to access the static response in tests.
65 //
66 // TODO(tache): Remove this once the API is ready.
67 //
68 static std::string GetFakeResponseForTest();
69
70 net::URLRequestContextGetter* url_request_context_;
71
72 std::string access_token_;
73
74 InterestsCallback callback_;
75
76 scoped_ptr<net::URLFetcher> fetcher_;
77
78 net::URLFetcherFactory* url_fetcher_factory_;
79
80
81 DISALLOW_COPY_AND_ASSIGN(InterestsRetriever);
82 };
83
84 #endif // CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/interests/interests_retriever.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698