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

Unified 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, 11 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/desktop_ios_promotion/sms_service.h
diff --git a/chrome/browser/ui/desktop_ios_promotion/sms_service.h b/chrome/browser/ui/desktop_ios_promotion/sms_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..6fb7e097b9a21418ac90f5030ce469779b04386c
--- /dev/null
+++ b/chrome/browser/ui/desktop_ios_promotion/sms_service.h
@@ -0,0 +1,109 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_
+#define CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_
+
+#include <stddef.h>
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "url/gurl.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+class OAuth2TokenService;
+class SigninManagerBase;
+
+// Provides an API for querying a logged in users's verified phone number,
+// and sending a predetermined promotional SMS to that number. This class is
+// based heavily on WebHistoryService's implementation to query Google services.
+class SMSService : public KeyedService {
+ public:
+ class Request {
+ public:
+ virtual ~Request();
+
+ virtual bool IsPending() = 0;
+
+ // Returns the response code received from the server, which will only be
+ // valid if the request succeeded.
+ virtual int GetResponseCode() = 0;
+
+ // Returns the contents of the response body received from the server.
+ virtual const std::string& GetResponseBody() = 0;
+
+ virtual void SetPostData(const std::string& post_data) = 0;
+
+ virtual void SetPostDataAndType(const std::string& post_data,
+ const std::string& mime_type) = 0;
+
+ // Tells the request to begin.
+ virtual void Start() = 0;
+
+ protected:
+ Request();
+ };
+
+ typedef base::Callback<
+ void(Request*, bool success, const std::string& number)>
+ PhoneNumberCallback;
+ typedef base::Callback<void(Request*, bool success)> CompletionCallback;
+
+ SMSService(
+ OAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context);
+ ~SMSService() override;
+
+ // Query the logged in user's verified phone number.
+ void QueryPhoneNumber(const PhoneNumberCallback& callback);
+
+ // Send an SMS to the logged in user's verified phone number. The text of
+ // the SMS is determined by |promo_id|.
+ void SendSMS(const std::string& promo_id,
+ const SMSService::PhoneNumberCallback& callback);
+
+ protected:
+ void QueryPhoneNumberCompletionCallback(
+ const SMSService::PhoneNumberCallback& callback,
+ SMSService::Request* request,
+ bool success);
+
+ void SendSMSCallback(const SMSService::PhoneNumberCallback& callback,
+ SMSService::Request* request,
+ bool success);
+
+ private:
+ virtual Request* CreateRequest(const GURL& url,
+ const CompletionCallback& callback);
+
+ // Stores pointer to OAuth2TokenService and SigninManagerBase instance. They
+ // must outlive the SMSService and can be null during
+ // tests.
+ OAuth2TokenService* token_service_;
+ SigninManagerBase* signin_manager_;
+
+ // Request context getter to use.
+ scoped_refptr<net::URLRequestContextGetter> request_context_;
+
+ // Pending expiration requests to be canceled if not complete by profile
+ // shutdown.
+ std::map<Request*, std::unique_ptr<Request>> pending_requests_;
+
+ base::WeakPtrFactory<SMSService> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(SMSService);
+};
+
+#endif // CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_
« 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