Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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_BREAKING_NEWS_SUBSCRIPTION_JSON_REQUEST_H_ | |
| 6 #define COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_JSON_REQUEST_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/optional.h" | |
| 15 #include "base/time/time.h" | |
| 16 #include "components/ntp_snippets/status.h" | |
| 17 #include "components/translate/core/browser/language_model.h" | |
| 18 #include "google_apis/gaia/oauth2_token_service.h" | |
| 19 #include "net/http/http_request_headers.h" | |
| 20 | |
| 21 namespace ntp_snippets { | |
| 22 | |
| 23 namespace internal { | |
| 24 | |
| 25 // A single request to subscribe for breaking news via GCM. | |
|
fhorschig
2017/06/01 16:25:21
nit: Please mention that the Request has to stay a
mamir
2017/06/01 17:13:00
Done.
| |
| 26 class SubscriptionJsonRequest : public net::URLFetcherDelegate { | |
| 27 public: | |
| 28 // A client can expect a message in the status only, if there was any error | |
| 29 // during the subscription. In successful cases, it will be an empty string. | |
| 30 using CompletedCallback = | |
| 31 base::OnceCallback<void(const ntp_snippets::Status& status)>; | |
| 32 | |
| 33 // Builds non-authenticated SubscriptionJsonRequests. | |
| 34 class Builder { | |
| 35 public: | |
| 36 Builder(); | |
| 37 Builder(Builder&&); | |
| 38 ~Builder(); | |
| 39 | |
| 40 // Builds a Request object that contains all data to fetch new snippets. | |
| 41 std::unique_ptr<SubscriptionJsonRequest> Build() const; | |
| 42 | |
| 43 Builder& SetToken(const std::string& token); | |
| 44 Builder& SetUrl(const GURL& url); | |
| 45 Builder& SetUrlRequestContextGetter( | |
| 46 const scoped_refptr<net::URLRequestContextGetter>& context_getter); | |
| 47 | |
| 48 private: | |
| 49 std::string BuildHeaders() const; | |
| 50 std::string BuildBody() const; | |
| 51 std::unique_ptr<net::URLFetcher> BuildURLFetcher( | |
| 52 net::URLFetcherDelegate* request, | |
| 53 const std::string& headers, | |
| 54 const std::string& body) const; | |
| 55 | |
| 56 // GCM subscribtion token obtain from GCM driver (instanceID::getToken()) | |
| 57 std::string token_; | |
| 58 // TODO(mamir): Additional fields to be added: country, language | |
| 59 | |
| 60 GURL url_; | |
| 61 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
| 62 | |
| 63 // Optional properties. | |
| 64 std::string obfuscated_gaia_id_; | |
|
fhorschig
2017/06/01 16:25:21
This property is very optional as it's never used.
mamir
2017/06/01 17:13:00
Done.
| |
| 65 }; | |
| 66 | |
| 67 ~SubscriptionJsonRequest() override; | |
| 68 | |
| 69 void Start(CompletedCallback callback); | |
|
fhorschig
2017/06/01 16:25:21
Could you comment this please?
(Something like:
S
mamir
2017/06/01 17:13:00
Done.
| |
| 70 | |
| 71 private: | |
| 72 friend class Builder; | |
| 73 SubscriptionJsonRequest(); | |
| 74 // URLFetcherDelegate implementation. | |
| 75 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 76 | |
| 77 // The fetcher for subscribing. | |
| 78 std::unique_ptr<net::URLFetcher> url_fetcher_; | |
| 79 | |
| 80 // The callback to notify when URLFetcher finished and results are available. | |
|
fhorschig
2017/06/01 16:25:21
Nit: When the request is finished/aborted/destroye
mamir
2017/06/01 17:13:00
Done.
| |
| 81 CompletedCallback request_completed_callback_; | |
| 82 | |
| 83 base::WeakPtrFactory<SubscriptionJsonRequest> weak_ptr_factory_; | |
|
fhorschig
2017/06/01 16:25:21
unused
mamir
2017/06/01 17:13:00
Done.
| |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(SubscriptionJsonRequest); | |
| 86 }; | |
| 87 | |
| 88 } // namespace internal | |
| 89 | |
| 90 } // namespace ntp_snippets | |
| 91 | |
| 92 #endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_JSON_REQUEST_H_ | |
| OLD | NEW |