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 CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_ | |
6 #define CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <map> | |
11 #include <memory> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "base/macros.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "base/memory/weak_ptr.h" | |
18 #include "components/keyed_service/core/keyed_service.h" | |
19 #include "url/gurl.h" | |
20 | |
21 namespace net { | |
22 class URLRequestContextGetter; | |
23 } | |
24 | |
25 class OAuth2TokenService; | |
26 class SigninManagerBase; | |
27 | |
28 namespace DesktopIOSPromotion { | |
msramek
2017/01/27 16:38:57
Sorry, didn't notice this before. chrome/browser/
justincohen
2017/01/27 23:06:46
Done.
| |
29 | |
30 // Provides an API for querying a logged in users's verified phone number, | |
31 // and sending a predetermined promotional SMS to that number. This class is | |
32 // based heavily on WebHistoryService's implementation to query Google services. | |
33 class SMSService : public KeyedService { | |
34 public: | |
35 class Request { | |
36 public: | |
37 virtual ~Request(); | |
38 | |
39 virtual bool IsPending() = 0; | |
40 | |
41 // Returns the response code received from the server, which will only be | |
42 // valid if the request succeeded. | |
43 virtual int GetResponseCode() = 0; | |
44 | |
45 // Returns the contents of the response body received from the server. | |
46 virtual const std::string& GetResponseBody() = 0; | |
47 | |
48 virtual void SetPostData(const std::string& post_data) = 0; | |
49 | |
50 virtual void SetPostDataAndType(const std::string& post_data, | |
51 const std::string& mime_type) = 0; | |
52 | |
53 // Tells the request to begin. | |
54 virtual void Start() = 0; | |
55 | |
56 protected: | |
57 Request(); | |
58 }; | |
59 | |
60 typedef base::Callback< | |
61 void(Request*, bool success, const std::string& number)> | |
62 PhoneNumberCallback; | |
63 typedef base::Callback<void(Request*, bool success)> CompletionCallback; | |
64 | |
65 SMSService( | |
66 OAuth2TokenService* token_service, | |
67 SigninManagerBase* signin_manager, | |
68 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
69 ~SMSService() override; | |
70 | |
71 // Query the logged in user's verified phone number. | |
72 void QueryPhoneNumber(const PhoneNumberCallback& callback); | |
73 | |
74 // Send an SMS to the logged in user's verified phone number. The text of | |
75 // the SMS is determined by |promo_id|. | |
76 void SendSMS(std::string promo_id, | |
77 const SMSService::PhoneNumberCallback& callback); | |
78 | |
79 protected: | |
80 void QueryPhoneNumberCompletionCallback( | |
81 const SMSService::PhoneNumberCallback& callback, | |
82 SMSService::Request* request, | |
83 bool success); | |
84 | |
85 void SendSMSCallback(const SMSService::PhoneNumberCallback& callback, | |
86 SMSService::Request* request, | |
87 bool success); | |
88 | |
89 private: | |
90 virtual Request* CreateRequest(const GURL& url, | |
91 const CompletionCallback& callback); | |
92 | |
93 // Stores pointer to OAuth2TokenService and SigninManagerBase instance. They | |
94 // must outlive the SMSService and can be null during | |
95 // tests. | |
96 OAuth2TokenService* token_service_; | |
97 SigninManagerBase* signin_manager_; | |
98 | |
99 // Request context getter to use. | |
100 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
101 | |
102 // Pending expiration requests to be canceled if not complete by profile | |
103 // shutdown. | |
104 std::map<Request*, std::unique_ptr<Request>> pending_requests_; | |
105 | |
106 base::WeakPtrFactory<SMSService> weak_ptr_factory_; | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(SMSService); | |
109 }; | |
110 | |
111 } // namespace DesktopIOSPromotion | |
112 | |
113 #endif // CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_ | |
OLD | NEW |