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

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: Review comments 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
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_fetcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2ae47ad8bdde9ac14b16154d8029b019634e518e
--- /dev/null
+++ b/components/ntp_snippets/ntp_snippets_fetcher.h
@@ -0,0 +1,94 @@
+// 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/callback.h"
+#include "base/callback_list.h"
+#include "base/files/file_path.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "base/sequenced_task_runner.h"
+#include "google_apis/gaia/oauth2_token_service.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace net {
+class URLFetcher;
+class URLFetcherDelegate;
+} // namespace net
+
+class SigninManagerBase;
+
+namespace ntp_snippets {
+
+// Fetches snippet data for the NTP from the server
+class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
+ public OAuth2TokenService::Observer,
+ public net::URLFetcherDelegate {
+ public:
+ using SnippetsAvailableCallback = base::Callback<void(const base::FilePath&)>;
+ using SnippetsAvailableCallbackList =
+ base::CallbackList<void(const base::FilePath&)>;
+
+ NTPSnippetsFetcher(scoped_refptr<base::SequencedTaskRunner> file_task_runner,
+ SigninManagerBase* signin_manager,
+ OAuth2TokenService* oauth2_token_service,
+ scoped_refptr<net::URLRequestContextGetter>
+ url_request_context_getter,
+ const base::FilePath& base_download_path);
+ ~NTPSnippetsFetcher() override;
+
+ // Fetches snippets from the server. |overwrite| is true if existing snippets
+ // should be overwritten.
+ void FetchSnippets(bool overwrite);
+
+ // Adds a callback that is called when a new set of snippets are downloaded
+ scoped_ptr<SnippetsAvailableCallbackList::Subscription> AddCallback(
+ const SnippetsAvailableCallback& callback) WARN_UNUSED_RESULT;
+
+ 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.
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+
+ scoped_ptr<net::URLFetcher> url_fetcher_;
+ scoped_ptr<SigninManagerBase> signin_manager_;
+ scoped_ptr<OAuth2TokenService> token_service_;
+ scoped_ptr<OAuth2TokenService::Request> oauth_request_;
+
+ base::FilePath download_path_;
+ bool waiting_for_refresh_token_;
+
+ SnippetsAvailableCallbackList callback_list_;
+
+ base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
+};
+} // namespace ntp_snippets
+
+#endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698