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

Unified 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: Removed the use of FakeURLFetcher 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_fetcher.h
diff --git a/chrome/browser/interests/interests_fetcher.h b/chrome/browser/interests/interests_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..ac06c961256a088c65fafd8720bd9cd755830e17
--- /dev/null
+++ b/chrome/browser/interests/interests_fetcher.h
@@ -0,0 +1,76 @@
+// 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_FETCHER_H_
+#define CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_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"
Marc Treib 2015/09/22 12:02:59 Not needed anymore
tache 2015/09/29 09:33:34 Done.
+
+FORWARD_DECLARE_TEST(InterestsFetcherTest, DefaultFakeResponse);
Marc Treib 2015/09/22 12:02:59 not needed anymore (test doesn't exist anymore)
tache 2015/09/29 09:33:34 Done.
+
+// Class to asynchronously retrieve the topics of interests for a user.
+// Authentication is done using the user's OAuth access_token.
+//
+// The user of this class is responsible of ensuring that the instance is
+// deleted only after the callback has been called.
Marc Treib 2015/09/22 12:02:59 This sounds like bad things will happen if you del
tache 2015/09/29 09:33:34 Done.
+//
+// Example Usage:
+//
+// auto request = make_scoped_ptr(new InterestsFetcher(
+// "user_access_token",
+// callback));
+//
+class InterestsFetcher : public net::URLFetcherDelegate {
+ 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;
+
+ InterestsFetcher(net::URLRequestContextGetter* url_request_context,
+ const std::string& access_token);
Marc Treib 2015/09/22 12:02:59 nit: alignment
tache 2015/09/29 09:33:34 Done.
+
+ void Start(const InterestsCallback& callback);
+
+ ~InterestsFetcher() override;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(::InterestsFetcherTest, DefaultFakeResponse);
Marc Treib 2015/09/22 12:02:59 not needed anymore
tache 2015/09/29 09:33:34 Done.
+
+ // 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);
+
+ net::URLRequestContextGetter* url_request_context_;
+
+ std::string access_token_;
+
+ InterestsCallback callback_;
+
+ scoped_ptr<net::URLFetcher> fetcher_;
+
+
+ DISALLOW_COPY_AND_ASSIGN(InterestsFetcher);
+};
+
+#endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_
« no previous file with comments | « no previous file | chrome/browser/interests/interests_fetcher.cc » ('j') | chrome/browser/interests/interests_fetcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698