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

Unified Diff: components/ntp_snippets/ntp_snippets_fetcher.h

Issue 1677073002: Fetch snippets from ChromeReader and show them on the NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning up Created 4 years, 10 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: components/ntp_snippets/ntp_snippets_fetcher.h
diff --git a/components/ntp_snippets/ntp_snippets_fetcher.h b/components/ntp_snippets/ntp_snippets_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..6ce9af3ca49042504f108724131faffb3ba05c13
--- /dev/null
+++ b/components/ntp_snippets/ntp_snippets_fetcher.h
@@ -0,0 +1,90 @@
+// Copyright 2016 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 COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
+#define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "base/sequenced_task_runner.h"
+#include "components/signin/core/browser/signin_tracker.h"
Bernhard Bauer 2016/02/08 18:19:26 Do you need this, or SigninManager (which you coul
May 2016/02/09 17:38:53 Done.
+#include "google_apis/gaia/oauth2_token_service.h"
+
+namespace net {
+class URLRequestContextGetter;
+class URLFetcher;
+class URLFetcherDelegate;
+} // namespace net
+
+namespace ntp_snippets {
+
+// Fetches snippet data for the NTP from the server
+class NTPSnippetsFetcher : public KeyedService,
Bernhard Bauer 2016/02/08 18:19:26 I don't think this should be a KeyedService if it'
May 2016/02/09 17:38:53 You're right, leftover crud from original way I wr
+ public OAuth2TokenService::Consumer,
+ public OAuth2TokenService::Observer,
+ public net::URLFetcherDelegate {
+ public:
+ class Observer {
+ public:
+ // Send everytime the a new set of snippets is downloaded
+ virtual void OnNTPSnippetsDownloaded() = 0;
Bernhard Bauer 2016/02/08 18:19:26 Instead of a single-method interface, consider usi
May 2016/02/09 17:38:53 Done.
+
+ protected:
+ virtual ~Observer() {}
+ };
+
+ explicit NTPSnippetsFetcher(
Marc Treib 2016/02/09 09:17:54 explicit is only useful for single-argument constr
May 2016/02/09 17:38:53 Done.
+ scoped_refptr<base::SequencedTaskRunner> file_task_runner,
+ SigninManager* signin_manager,
+ OAuth2TokenService* oauth2_token_service,
+ net::URLRequestContextGetter* url_request_context_getter);
+ virtual ~NTPSnippetsFetcher();
+
+ // Fetches snippets from the server. |overwrite| is true if existing snippets
+ // should be overwritten.
+ void FetchSnippets(bool overwrite);
+
+ // Observer accessors.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ void StartTokenRequest();
+ void NotifyObservers();
+ void OnDownloadSnippetsDone(bool success);
+ void OnFileExistsCheckDone(bool exists);
+ void OnFileMoveDone(bool success);
+ void StartFetch();
+
+ // OAuth2TokenService::Consumer overrides:
+ void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) override;
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) override;
+
+ // OAuth2TokenService::Observer overrides:
+ void OnRefreshTokenAvailable(const std::string& account_id) override;
+
+ // URLFetcherDelegate implementation.
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ // The SequencedTaskRunner on which file system operations will be run.
+ scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
+
+ // Holds the URL request context. Not owned.
+ net::URLRequestContextGetter* url_request_context_getter_;
+
+ scoped_ptr<net::URLFetcher> url_fetcher_;
+ scoped_ptr<SigninManager> signin_manager_;
+ scoped_ptr<OAuth2TokenService> token_service_;
+ scoped_ptr<OAuth2TokenService::Request> oauth_request_;
+
+ base::ObserverList<Observer> observers_;
+
+ base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
Bernhard Bauer 2016/02/08 18:19:26 Add DISALLOW_COPY_AND_ASSIGN.
May 2016/02/09 17:38:53 Done.
+};
+} // namespace ntp_snippets
+
+#endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698