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

Unified Diff: components/proximity_auth/messenger_impl.cc

Issue 1372283002: Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: Created 5 years, 3 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: components/proximity_auth/messenger_impl.cc
diff --git a/components/proximity_auth/messenger_impl.cc b/components/proximity_auth/messenger_impl.cc
index 13bfac7a4e36a1f1b707508fdd62690d4d7c3ed7..33c97a049c2707a112139794cb174497b423c8fb 100644
--- a/components/proximity_auth/messenger_impl.cc
+++ b/components/proximity_auth/messenger_impl.cc
@@ -7,6 +7,8 @@
#include "base/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "base/location.h"
+#include "base/thread_task_runner_handle.h"
#include "base/values.h"
#include "components/proximity_auth/connection.h"
#include "components/proximity_auth/cryptauth/base64url.h"
@@ -36,6 +38,15 @@ const char kMessageTypeUnlockResponse[] = "unlock_response";
// The name for an unlock event originating from the local device.
const char kUnlockEventName[] = "easy_unlock";
+// Messages sent and received from the iOS app when polling for it's lock screen
+// status.
+// TODO(tengs): Unify the iOS status update protocol with the existing Android
+// protocol, so we don't have this special case.
+const char kPollScreenState[] = "PollScreenState";
+const char kScreenUnlocked[] = "Screen Unlocked";
+const char kScreenLocked[] = "Screen Locked";
+const int kIOSPollingIntervalSeconds = 5;
+
// Serializes the |value| to a JSON string and returns the result.
std::string SerializeValueToJson(const base::Value& value) {
std::string json;
@@ -61,6 +72,11 @@ MessengerImpl::MessengerImpl(scoped_ptr<Connection> connection,
weak_ptr_factory_(this) {
DCHECK(connection_->IsConnected());
connection_->AddObserver(this);
+
+ // TODO(tengs): We need CryptAuth to report if the phone runs iOS or Android,
+ // rather than relying on this heuristic.
+ if (connection_->remote_device().bluetooth_address.empty())
sacomoto 2015/09/29 18:45:57 Please use the RemoteDevice::bluetooth_type field.
Tim Song 2015/09/30 00:05:04 Done.
+ PollScreenStateForIOS();
}
MessengerImpl::~MessengerImpl() {
@@ -243,6 +259,20 @@ void MessengerImpl::HandleUnlockResponseMessage(
FOR_EACH_OBSERVER(MessengerObserver, observers_, OnUnlockResponse(true));
}
+void MessengerImpl::PollScreenStateForIOS() {
+ if (!connection_->IsConnected())
+ return;
+
+ // Sends message requesting screen state.
+ connection_->SendMessage(make_scoped_ptr(new WireMessage(kPollScreenState)));
+
+ // Schedules the next message in |kPollingIntervalSeconds|.
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, base::Bind(&MessengerImpl::PollScreenStateForIOS,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromSeconds(kIOSPollingIntervalSeconds));
+}
+
void MessengerImpl::OnConnectionStatusChanged(Connection* connection,
Connection::Status old_status,
Connection::Status new_status) {
@@ -259,6 +289,20 @@ void MessengerImpl::OnConnectionStatusChanged(Connection* connection,
void MessengerImpl::OnMessageReceived(const Connection& connection,
const WireMessage& wire_message) {
+ // TODO(tengs): Unify the iOS status update protocol with the existing Android
+ // protocol, so we don't have this special case.
+ std::string payload = wire_message.payload();
+ if (payload == kScreenUnlocked || payload == kScreenLocked) {
+ RemoteStatusUpdate update;
+ update.user_presence =
+ (payload == kScreenUnlocked ? USER_PRESENT : USER_ABSENT);
+ update.secure_screen_lock_state = SECURE_SCREEN_LOCK_ENABLED;
+ update.trust_agent_state = TRUST_AGENT_ENABLED;
+ FOR_EACH_OBSERVER(MessengerObserver, observers_,
+ OnRemoteStatusUpdate(update));
+ return;
+ }
+
secure_context_->Decode(wire_message.payload(),
base::Bind(&MessengerImpl::OnMessageDecoded,
weak_ptr_factory_.GetWeakPtr()));

Powered by Google App Engine
This is Rietveld 408576698