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

Side by Side 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, 9 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
7
8 #include "base/callback.h"
9 #include "base/callback_list.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/sequenced_task_runner.h"
14 #include "google_apis/gaia/oauth2_token_service.h"
15 #include "net/url_request/url_request_context_getter.h"
16
17 namespace net {
18 class URLFetcher;
19 class URLFetcherDelegate;
20 } // namespace net
21
22 class SigninManagerBase;
23
24 namespace ntp_snippets {
25
26 // Fetches snippet data for the NTP from the server
27 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
28 public OAuth2TokenService::Observer,
29 public net::URLFetcherDelegate {
30 public:
31 using SnippetsAvailableCallback = base::Callback<void(const base::FilePath&)>;
32 using SnippetsAvailableCallbackList =
33 base::CallbackList<void(const base::FilePath&)>;
34
35 NTPSnippetsFetcher(scoped_refptr<base::SequencedTaskRunner> file_task_runner,
36 SigninManagerBase* signin_manager,
37 OAuth2TokenService* oauth2_token_service,
38 scoped_refptr<net::URLRequestContextGetter>
39 url_request_context_getter,
40 const base::FilePath& base_download_path);
41 ~NTPSnippetsFetcher() override;
42
43 // Fetches snippets from the server. |overwrite| is true if existing snippets
44 // should be overwritten.
45 void FetchSnippets(bool overwrite);
46
47 // Adds a callback that is called when a new set of snippets are downloaded
48 scoped_ptr<SnippetsAvailableCallbackList::Subscription> AddCallback(
49 const SnippetsAvailableCallback& callback) WARN_UNUSED_RESULT;
50
51 private:
52 void StartTokenRequest();
53 void NotifyObservers();
54 void OnDownloadSnippetsDone(bool success);
55 void OnFileExistsCheckDone(bool exists);
56 void OnFileMoveDone(bool success);
57 void StartFetch();
58
59 // OAuth2TokenService::Consumer overrides:
60 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
61 const std::string& access_token,
62 const base::Time& expiration_time) override;
63 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
64 const GoogleServiceAuthError& error) override;
65
66 // OAuth2TokenService::Observer overrides:
67 void OnRefreshTokenAvailable(const std::string& account_id) override;
68
69 // URLFetcherDelegate implementation.
70 void OnURLFetchComplete(const net::URLFetcher* source) override;
71
72 // The SequencedTaskRunner on which file system operations will be run.
73 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
74
75 // Holds the URL request context.
76 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
77
78 scoped_ptr<net::URLFetcher> url_fetcher_;
79 scoped_ptr<SigninManagerBase> signin_manager_;
80 scoped_ptr<OAuth2TokenService> token_service_;
81 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
82
83 base::FilePath download_path_;
84 bool waiting_for_refresh_token_;
85
86 SnippetsAvailableCallbackList callback_list_;
87
88 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
89
90 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
91 };
92 } // namespace ntp_snippets
93
94 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
OLDNEW
« 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