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

Side by Side Diff: components/proximity_auth/connection.h

Issue 585743004: [Easy Unlock] Port the BluetoothConnection class to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix scoped_refptr compile on non-clang Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_PROXIMITY_AUTH_CONNECTION_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_CONNECTION_H
6 #define COMPONENTS_PROXIMITY_AUTH_CONNECTION_H 6 #define COMPONENTS_PROXIMITY_AUTH_CONNECTION_H
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 class Connection { 21 class Connection {
22 public: 22 public:
23 enum Status { 23 enum Status {
24 DISCONNECTED, 24 DISCONNECTED,
25 IN_PROGRESS, 25 IN_PROGRESS,
26 CONNECTED, 26 CONNECTED,
27 }; 27 };
28 28
29 // Constructs a connection to the given |remote_device|. 29 // Constructs a connection to the given |remote_device|.
30 explicit Connection(const RemoteDevice& remote_device); 30 explicit Connection(const RemoteDevice& remote_device);
31 ~Connection(); 31 virtual ~Connection();
32 32
33 // Returns true iff the connection's status is CONNECTED. 33 // Returns true iff the connection's status is CONNECTED.
34 bool IsConnected() const; 34 bool IsConnected() const;
35 35
36 // Sends a message to the remote device. 36 // Sends a message to the remote device.
37 // |OnSendCompleted()| will be called for all observers upon completion with 37 // |OnSendCompleted()| will be called for all observers upon completion with
38 // either success or failure. 38 // either success or failure.
39 void SendMessage(scoped_ptr<WireMessage> message); 39 void SendMessage(scoped_ptr<WireMessage> message);
40 40
41 void AddObserver(ConnectionObserver* observer); 41 void AddObserver(ConnectionObserver* observer);
42 void RemoveObserver(ConnectionObserver* observer); 42 void RemoveObserver(ConnectionObserver* observer);
43 43
44 const RemoteDevice& remote_device() const { return remote_device_; } 44 const RemoteDevice& remote_device() const { return remote_device_; }
45 45
46 // Abstract methods that subclasses should implement: 46 // Abstract methods that subclasses should implement:
47 47
48 // Pauses or unpauses the handling of incoming messages. Pausing allows the
49 // user of the connection to add or remove observers without missing messages.
50 virtual void SetPaused(bool paused) = 0;
51
52 // Attempts to connect to the remote device if not already connected. 48 // Attempts to connect to the remote device if not already connected.
53 virtual void Connect() = 0; 49 virtual void Connect() = 0;
54 50
55 // Disconnects from the remote device. 51 // Disconnects from the remote device.
56 virtual void Disconnect() = 0; 52 virtual void Disconnect() = 0;
57 53
58 protected: 54 protected:
59 // Sets the connection's status to |status|. If this is different from the 55 // Sets the connection's status to |status|. If this is different from the
60 // previous status, notifies observers of the change in status. 56 // previous status, notifies observers of the change in status.
61 void SetStatus(Status status); 57 // Virtual for testing.
58 virtual void SetStatus(Status status);
62 59
63 Status status() const { return status_; } 60 Status status() const { return status_; }
64 61
65 // Called after attempting to send bytes over the connection, whether the 62 // Called after attempting to send bytes over the connection, whether the
66 // message was successfully sent or not. 63 // message was successfully sent or not.
67 void OnDidSendMessage(const WireMessage& message, bool success); 64 // Virtual for testing.
65 virtual void OnDidSendMessage(const WireMessage& message, bool success);
68 66
69 // Called when bytes are read from the connection. There should not be a send 67 // Called when bytes are read from the connection. There should not be a send
70 // in progress when this function is called. 68 // in progress when this function is called.
71 void OnBytesReceived(const std::string& bytes); 69 // Virtual for testing.
70 virtual void OnBytesReceived(const std::string& bytes);
72 71
73 // Sends bytes over the connection. The implementing class should call 72 // Sends bytes over the connection. The implementing class should call
74 // OnSendCompleted() once the send succeeds or fails. At most one send will be 73 // OnSendCompleted() once the send succeeds or fails. At most one send will be
75 // in progress. 74 // in progress.
76 virtual void SendMessageImpl(scoped_ptr<WireMessage> message) = 0; 75 virtual void SendMessageImpl(scoped_ptr<WireMessage> message) = 0;
77 76
78 // Deserializes the |recieved_bytes_| and returns the resulting WireMessage, 77 // Deserializes the |recieved_bytes_| and returns the resulting WireMessage,
79 // or NULL if the message is malformed. Sets |is_incomplete_message| to true 78 // or NULL if the message is malformed. Sets |is_incomplete_message| to true
80 // if the |serialized_message| does not have enough data to parse the header, 79 // if the |serialized_message| does not have enough data to parse the header,
81 // or if the message length encoded in the message header exceeds the size of 80 // or if the message length encoded in the message header exceeds the size of
(...skipping 17 matching lines...) Expand all
99 98
100 // Whether a message is currently in the process of being sent. 99 // Whether a message is currently in the process of being sent.
101 bool is_sending_message_; 100 bool is_sending_message_;
102 101
103 DISALLOW_COPY_AND_ASSIGN(Connection); 102 DISALLOW_COPY_AND_ASSIGN(Connection);
104 }; 103 };
105 104
106 } // namespace proximity_auth 105 } // namespace proximity_auth
107 106
108 #endif // COMPONENTS_PROXIMITY_AUTH_CONNECTION_H 107 #endif // COMPONENTS_PROXIMITY_AUTH_CONNECTION_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698