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

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
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..cef6c05abfc8ecd1587fc7efc827ce0d8c6717e9
--- /dev/null
+++ b/chrome/browser/interests/interests_retriever.h
@@ -0,0 +1,76 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
Marc Treib 2015/09/03 09:04:37 WHAT YEAR IS THIS?! :D
tache 2015/09/03 13:26:29 Done.
+// 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>
Marc Treib 2015/09/03 09:04:37 Quotes instead of angle brackets for non-stdlib in
tache 2015/09/03 13:26:29 Eclipse "organize imports" is so broken... Done.
+#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>
+
+namespace net {
+class URLFetcher;
Marc Treib 2015/09/03 09:04:37 Either include or forward declare, not both.
tache 2015/09/03 13:26:29 Done.
+class URLRequestContextGetter;
+} // namespace net
+
+FORWARD_DECLARE_TEST(InterestsRetrieverTest, DefaultFakeResponse);
Marc Treib 2015/09/03 09:04:37 Is this required? I don't think I've ever seen thi
tache 2015/09/03 13:26:29 https://code.google.com/p/chromium/codesearch#chro
Marc Treib 2015/09/03 13:54:55 Generally it doesn't need to be forward-declared,
+
+class InterestsRetriever : public net::URLFetcherDelegate {
+ public:
+ struct Interest {
+ std::string name;
+ std::string image_url;
+ double relevance;
+
+ bool operator==(const Interest &interest) const {
Marc Treib 2015/09/03 09:04:37 Do you actually need this operator? If so, please
tache 2015/09/03 13:26:29 Only used for testing atm. Moved it to the .cc fi
Marc Treib 2015/09/03 13:54:55 Then you could also move it to the test file (as a
+ return name == interest.name && image_url == interest.image_url &&
+ relevance == interest.relevance;
+ }
+ };
+
+ typedef base::Callback<void(std::vector<Interest, std::allocator<Interest>>)>
Marc Treib 2015/09/03 09:04:37 Remove the explicit allocator? Also, I find using
tache 2015/09/03 13:26:29 Done.
+ InterestsCallback;
+
+ InterestsRetriever(net::URLRequestContextGetter *url_request_context,
Marc Treib 2015/09/03 09:04:37 nit: * goes with the type, not the name. Also the
tache 2015/09/03 13:26:28 Done.
+ const std::string &token,
Marc Treib 2015/09/03 09:04:37 What exactly is |token|? An OAuth access token? Th
tache 2015/09/03 13:26:29 Done.
+ const InterestsCallback &callback,
+ net::URLFetcherFactory *url_fetcher_factory);
+
+ ~InterestsRetriever() override;
+
+ private:
+ // net::URLFetcherDelegate implementation.
+ void OnURLFetchComplete(const net::URLFetcher *source) override;
+
+ // create URLFetcher
Marc Treib 2015/09/03 09:04:37 Not a very useful comment ;P
tache 2015/09/03 13:26:29 Done.
+ scoped_ptr<net::URLFetcher> CreateFetcher();
+
+ // parse the json response
+ std::vector<Interest> ExtractInterests(const std::string &response);
+
+ static std::string FakeResponse();
Marc Treib 2015/09/03 09:04:37 This one, OTOH, would deserve a comment, or at lea
tache 2015/09/03 13:26:29 Done.
+
+ net::URLRequestContextGetter *url_request_context_;
+
+ std::string token_;
+
+ InterestsCallback callback_;
+
+ scoped_ptr<net::URLFetcher> fetcher_;
+
+ net::URLFetcherFactory *url_fetcher_factory_;
+
+
+ DISALLOW_COPY_AND_ASSIGN(InterestsRetriever);
+ FRIEND_TEST_ALL_PREFIXES(::InterestsRetrieverTest, DefaultFakeResponse);
Marc Treib 2015/09/03 09:04:37 By convention, the FRIEND_TEST goes to the top of
tache 2015/09/03 13:26:29 Done.
+};
+
+#endif // CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_H_
« no previous file with comments | « no previous file | chrome/browser/interests/interests_retriever.cc » ('j') | chrome/browser/interests/interests_retriever.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698