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

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: 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 unified diff | Download patch
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/memory/weak_ptr.h"
9 #include "base/observer_list.h"
10 #include "base/sequenced_task_runner.h"
11 #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.
12 #include "google_apis/gaia/oauth2_token_service.h"
13
14 namespace net {
15 class URLRequestContextGetter;
16 class URLFetcher;
17 class URLFetcherDelegate;
18 } // namespace net
19
20 namespace ntp_snippets {
21
22 // Fetches snippet data for the NTP from the server
23 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
24 public OAuth2TokenService::Consumer,
25 public OAuth2TokenService::Observer,
26 public net::URLFetcherDelegate {
27 public:
28 class Observer {
29 public:
30 // Send everytime the a new set of snippets is downloaded
31 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.
32
33 protected:
34 virtual ~Observer() {}
35 };
36
37 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.
38 scoped_refptr<base::SequencedTaskRunner> file_task_runner,
39 SigninManager* signin_manager,
40 OAuth2TokenService* oauth2_token_service,
41 net::URLRequestContextGetter* url_request_context_getter);
42 virtual ~NTPSnippetsFetcher();
43
44 // Fetches snippets from the server. |overwrite| is true if existing snippets
45 // should be overwritten.
46 void FetchSnippets(bool overwrite);
47
48 // Observer accessors.
49 void AddObserver(Observer* observer);
50 void RemoveObserver(Observer* observer);
51
52 private:
53 void StartTokenRequest();
54 void NotifyObservers();
55 void OnDownloadSnippetsDone(bool success);
56 void OnFileExistsCheckDone(bool exists);
57 void OnFileMoveDone(bool success);
58 void StartFetch();
59
60 // OAuth2TokenService::Consumer overrides:
61 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
62 const std::string& access_token,
63 const base::Time& expiration_time) override;
64 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
65 const GoogleServiceAuthError& error) override;
66
67 // OAuth2TokenService::Observer overrides:
68 void OnRefreshTokenAvailable(const std::string& account_id) override;
69
70 // URLFetcherDelegate implementation.
71 void OnURLFetchComplete(const net::URLFetcher* source) override;
72
73 // The SequencedTaskRunner on which file system operations will be run.
74 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
75
76 // Holds the URL request context. Not owned.
77 net::URLRequestContextGetter* url_request_context_getter_;
78
79 scoped_ptr<net::URLFetcher> url_fetcher_;
80 scoped_ptr<SigninManager> signin_manager_;
81 scoped_ptr<OAuth2TokenService> token_service_;
82 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
83
84 base::ObserverList<Observer> observers_;
85
86 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.
87 };
88 } // namespace ntp_snippets
89
90 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698