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

Unified Diff: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receiving_device_info_handler_ios.mm

Issue 11038063: Support chrome_to_mobile job receiving Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix format Created 8 years, 1 month 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/chrome_to_mobile/receive/chrome_to_mobile_receiving_device_info_handler_ios.mm
diff --git a/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receiving_device_info_handler_ios.mm b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receiving_device_info_handler_ios.mm
new file mode 100644
index 0000000000000000000000000000000000000000..767ce100c9b7aee96ea35c0dfa14764f3ff5723e
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receiving_device_info_handler_ios.mm
@@ -0,0 +1,85 @@
+// Copyright 2012 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.
+
+#include "chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_receiving_device_info_handler_ios.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/sys_string_conversions.h"
+
+namespace chrome_to_mobile_receive {
+
+const char kApnsDeviceTokenTag[] = "device_token";
+const char kApnsPackageTag[] = "package";
+
+} // namespace
+
+namespace chrome_to_mobile_receive {
+
+ChromeToMobileReceivingDeviceInfoHandlerIOS
+ ::ChromeToMobileReceivingDeviceInfoHandlerIOS() {
+}
+
+ChromeToMobileReceivingDeviceInfoHandlerIOS
+ ::~ChromeToMobileReceivingDeviceInfoHandlerIOS() {
+}
+
+bool ChromeToMobileReceivingDeviceInfoHandlerIOS::IsSupported() const {
+ return IsChromeToMobileReceiveNotificationSupported();
+}
+
+void ChromeToMobileReceivingDeviceInfoHandlerIOS::Start() {
+#if !TARGET_IPHONE_SIMULATOR
+ // Note remote notification needs to be registered even when notification is
+ // not enabled, for the following reason:
+ // - |UIApplication enabledRemoteNotificationTypes| defaults to be none when
+ // an application is installed.
+ // - The user is given choice to enable push notification when the first time
+ // |UIApplication registerForRemoteNotificationTypes| is called.
+ [[UIApplication sharedApplication]
+ registerForRemoteNotificationTypes:UIRemoteNotificationTypeAler];
+#else
+ // Mock push notification in simulator.
+ NSData* device_token = [@"testDeviceToken" dataUsingEncoding:
+ [NSString defaultCStringEncoding]];
+ UIApplication* application = [UIApplication sharedApplication];
+ [[[UIApplication sharedApplication] delegate] application:application
+ didRegisterForRemoteNotificationsWithDeviceToken:device_token];
+#endif // !TARGET_IPHONE_SIMULATOR
+}
+
+bool ChromeToMobileReceivingDeviceInfoHandlerIOS::HasRequiredInformation(
+ std::map<std::string, std::string> printer_tags) const {
+ std::map<std::string, std::string>::const_iterator token_it =
+ printer_tags.find(kApnsDeviceTokenTag);
+ std::map<std::string, std::string>::const_iterator package_it =
+ printer_tags.find(kApnsPackageTag);
+ return token_it != printer_tags.end() && !token_it->second.empty() &&
+ package_it != printer_tags.end() && !package_it->second.empty();
+}
+
+// static
+bool ChromeToMobileReceivingDeviceInfoHandlerIOS::
+ IsChromeToMobileReceiveNotificationSupported() {
+#if !TARGET_IPHONE_SIMULATOR
+ UIRemoteNotificationType enabledType =
+ [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
+ return enabledType & UIRemoteNotificationTypeAlert;
+#else
+ return true;
+#endif // !TARGET_IPHONE_SIMULATOR
+}
+
+// static
+std::map<std::string, std::string> ChromeToMobileReceivingDeviceInfoHandlerIOS::
+ GeneratePrinterTags(const std::string& device_token) {
+ std::map<std::string, std::string> printer_tags;
+ NSString* appId = [[[NSBundle mainBundle] infoDictionary]
+ objectForKey:@"CFBundleIdentifier"];
+ printer_tags[kApnsDeviceTokenTag] = device_token;
+ printer_tags[kApnsPackageTag] = std::string(base::SysNSStringToUTF8(appId));
+ return printer_tags;
+}
+
+} // namespace chrome_to_mobile_receive

Powered by Google App Engine
This is Rietveld 408576698