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