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

Side by Side Diff: chrome/browser/ui/desktop_ios_promotion/sms_service.h

Issue 2646823002: D2MIOS: Add plumbing to query verified number and send SMS from growth server. (Closed)
Patch Set: Change to const ref std::string Created 3 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
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/desktop_ios_promotion/sms_service.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 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 // Provides an API for querying a logged in users's verified phone number,
29 // and sending a predetermined promotional SMS to that number. This class is
30 // based heavily on WebHistoryService's implementation to query Google services.
31 class SMSService : public KeyedService {
32 public:
33 class Request {
34 public:
35 virtual ~Request();
36
37 virtual bool IsPending() = 0;
38
39 // Returns the response code received from the server, which will only be
40 // valid if the request succeeded.
41 virtual int GetResponseCode() = 0;
42
43 // Returns the contents of the response body received from the server.
44 virtual const std::string& GetResponseBody() = 0;
45
46 virtual void SetPostData(const std::string& post_data) = 0;
47
48 virtual void SetPostDataAndType(const std::string& post_data,
49 const std::string& mime_type) = 0;
50
51 // Tells the request to begin.
52 virtual void Start() = 0;
53
54 protected:
55 Request();
56 };
57
58 typedef base::Callback<
59 void(Request*, bool success, const std::string& number)>
60 PhoneNumberCallback;
61 typedef base::Callback<void(Request*, bool success)> CompletionCallback;
62
63 SMSService(
64 OAuth2TokenService* token_service,
65 SigninManagerBase* signin_manager,
66 const scoped_refptr<net::URLRequestContextGetter>& request_context);
67 ~SMSService() override;
68
69 // Query the logged in user's verified phone number.
70 void QueryPhoneNumber(const PhoneNumberCallback& callback);
71
72 // Send an SMS to the logged in user's verified phone number. The text of
73 // the SMS is determined by |promo_id|.
74 void SendSMS(const std::string& promo_id,
75 const SMSService::PhoneNumberCallback& callback);
76
77 protected:
78 void QueryPhoneNumberCompletionCallback(
79 const SMSService::PhoneNumberCallback& callback,
80 SMSService::Request* request,
81 bool success);
82
83 void SendSMSCallback(const SMSService::PhoneNumberCallback& callback,
84 SMSService::Request* request,
85 bool success);
86
87 private:
88 virtual Request* CreateRequest(const GURL& url,
89 const CompletionCallback& callback);
90
91 // Stores pointer to OAuth2TokenService and SigninManagerBase instance. They
92 // must outlive the SMSService and can be null during
93 // tests.
94 OAuth2TokenService* token_service_;
95 SigninManagerBase* signin_manager_;
96
97 // Request context getter to use.
98 scoped_refptr<net::URLRequestContextGetter> request_context_;
99
100 // Pending expiration requests to be canceled if not complete by profile
101 // shutdown.
102 std::map<Request*, std::unique_ptr<Request>> pending_requests_;
103
104 base::WeakPtrFactory<SMSService> weak_ptr_factory_;
105
106 DISALLOW_COPY_AND_ASSIGN(SMSService);
107 };
108
109 #endif // CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/desktop_ios_promotion/sms_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698