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

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: 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
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..f22337f32494f8bb5677561f2b03dcac495a0467
--- /dev/null
+++ b/chrome/browser/ui/desktop_ios_promotion/sms_service.h
@@ -0,0 +1,117 @@
+// Copyright (c) 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 "base/observer_list.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "url/gurl.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+class SMSServiceObserver;
+class OAuth2TokenService;
+class SigninManagerBase;
+
+namespace DesktopIOSPromotion {
+
+// 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;
+
+ 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
+ void RemoveObserver(SMSServiceObserver* observer);
+
+ void QueryPhoneNumber(const PhoneNumberCallback& callback);
msramek 2017/01/23 21:13:57 Please document public methods.
justincohen 2017/01/25 22:52:38 Done.
+ void SendSMS(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_;
+
+ // Observers.
+ base::ObserverList<SMSServiceObserver, true> observer_list_;
+
+ base::WeakPtrFactory<SMSService> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(SMSService);
+};
+
+} // namespace DesktopIOSPromotion
+
+#endif // CHROME_BROWSER_UI_DESKTOP_IOS_PROMOTION_SMS_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698