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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/interests/interests_retriever.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/interests/interests_retriever.h
diff --git a/chrome/browser/interests/interests_retriever.h b/chrome/browser/interests/interests_retriever.h
new file mode 100644
index 0000000000000000000000000000000000000000..c472a5924f1c032fb80391897b2df5f460920b57
--- /dev/null
+++ b/chrome/browser/interests/interests_retriever.h
@@ -0,0 +1,84 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_H_
+#define CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "net/url_request/url_fetcher_factory.h"
+
+FORWARD_DECLARE_TEST(InterestsRetrieverTest, DefaultFakeResponse);
+
+// Class to asynchronously retrieve the topics of interests for a user.
+// 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.
+//
+// Example Usage:
+//
+// 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.
+// "user_access_token",
+// callback));
+//
+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.
+ public:
+ struct Interest {
+ std::string name;
+ std::string image_url;
+ double relevance;
+
+ bool operator==(const Interest& interest) const;
+ };
+
+ typedef base::Callback<void(const std::vector<Interest>&)>
+ InterestsCallback;
+
+ InterestsRetriever(net::URLRequestContextGetter* url_request_context,
+ const std::string& access_token,
+ const InterestsCallback& callback,
+ net::URLFetcherFactory* url_fetcher_factory);
+
+ ~InterestsRetriever() override;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(::InterestsRetrieverTest, DefaultFakeResponse);
+
+ // net::URLFetcherDelegate implementation.
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ scoped_ptr<net::URLFetcher> CreateFetcher();
+
+ // parse the json response
+ std::vector<Interest> ExtractInterests(const std::string& response);
+
+ //
+ // 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.
+ // is not ready yet.
+ // This method is needed to access the static response in tests.
+ //
+ // TODO(tache): Remove this once the API is ready.
+ //
+ static std::string GetFakeResponseForTest();
+
+ net::URLRequestContextGetter* url_request_context_;
+
+ std::string access_token_;
+
+ InterestsCallback callback_;
+
+ scoped_ptr<net::URLFetcher> fetcher_;
+
+ net::URLFetcherFactory* url_fetcher_factory_;
+
+
+ DISALLOW_COPY_AND_ASSIGN(InterestsRetriever);
+};
+
+#endif // CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_H_
« 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