Merge "Created an ObjectStore skeleton with functional encryption."
diff --git a/login_event_client.cc b/login_event_client.cc
index 6c1b44e..5b781f9 100644
--- a/login_event_client.cc
+++ b/login_event_client.cc
@@ -17,22 +17,25 @@
namespace chaps {
-LoginEventClient::LoginEventClient() : proxy_(NULL) {}
+LoginEventClient::LoginEventClient()
+ : proxy_(new ChapsProxyImpl()),
+ is_connected_(false) {
+ CHECK(proxy_);
+}
LoginEventClient::~LoginEventClient() {
delete proxy_;
}
-bool LoginEventClient::Init() {
- proxy_ = new ChapsProxyImpl();
- CHECK(proxy_);
- return proxy_->Init();
-}
-
void LoginEventClient::FireLoginEvent(const string& path,
const uint8_t* auth_data,
size_t auth_data_length) {
CHECK(proxy_);
+ if (!Connect()) {
+ LOG(WARNING) << "Failed to connect to the Chaps daemon. "
+ << "Login notification will not be sent.";
+ return;
+ }
// TODO(dkrahn): Use SecureBlob; see crosbug.com/27681.
vector<uint8_t> auth_data_vector(auth_data, auth_data + auth_data_length);
proxy_->FireLoginEvent(path, auth_data_vector);
@@ -41,6 +44,11 @@
void LoginEventClient::FireLogoutEvent(const string& path) {
CHECK(proxy_);
+ if (!Connect()) {
+ LOG(WARNING) << "Failed to connect to the Chaps daemon. "
+ << "Logout notification will not be sent.";
+ return;
+ }
proxy_->FireLogoutEvent(path);
}
@@ -51,6 +59,11 @@
const uint8_t* new_auth_data,
size_t new_auth_data_length) {
CHECK(proxy_);
+ if (!Connect()) {
+ LOG(WARNING) << "Failed to connect to the Chaps daemon. "
+ << "Change authorization data notification will not be sent.";
+ return;
+ }
// TODO(dkrahn): Use SecureBlob; see crosbug.com/27681.
vector<uint8_t> old_auth_data_vector(old_auth_data,
old_auth_data + old_auth_data_length);
@@ -63,4 +76,10 @@
chromeos::SecureMemset(&new_auth_data_vector[0], 0, new_auth_data_length);
}
+bool LoginEventClient::Connect() {
+ if (!is_connected_)
+ is_connected_ = proxy_->Init();
+ return is_connected_;
+}
+
} // namespace chaps
diff --git a/login_event_client.h b/login_event_client.h
index 8ff8351..b65fafb 100644
--- a/login_event_client.h
+++ b/login_event_client.h
@@ -23,9 +23,6 @@
LoginEventClient();
virtual ~LoginEventClient();
- // Initializes the client instance. Returns true on success.
- bool Init();
-
// Sends a login event. The Chaps daemon will insert a token for the user.
// path - The path to the user's token directory.
// auth_data - Authorization data to unlock the token.
@@ -49,6 +46,10 @@
size_t new_auth_data_length);
private:
ChapsProxyImpl* proxy_;
+ bool is_connected_;
+
+ // Attempts to connect to the Chaps daemon. Returns true on success.
+ bool Connect();
DISALLOW_COPY_AND_ASSIGN(LoginEventClient);
};