summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/policy/device_token_fetcher.cc55
-rw-r--r--chrome/browser/policy/device_token_fetcher.h8
-rw-r--r--chrome/browser/policy/device_token_fetcher_unittest.cc19
-rw-r--r--chrome/browser/policy/proto/device_management_local.proto6
4 files changed, 18 insertions, 70 deletions
diff --git a/chrome/browser/policy/device_token_fetcher.cc b/chrome/browser/policy/device_token_fetcher.cc
index a0ae34f..a1ba00e 100644
--- a/chrome/browser/policy/device_token_fetcher.cc
+++ b/chrome/browser/policy/device_token_fetcher.cc
@@ -9,7 +9,6 @@
#include "base/singleton.h"
#include "chrome/browser/guid.h"
#include "chrome/browser/net/gaia/token_service.h"
-#include "chrome/browser/policy/proto/device_management_local.pb.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "chrome/common/notification_details.h"
@@ -19,8 +18,6 @@
namespace policy {
-namespace em = enterprise_management;
-
DeviceTokenFetcher::DeviceTokenFetcher(
DeviceManagementBackend* backend,
const FilePath& token_path)
@@ -67,8 +64,7 @@ void DeviceTokenFetcher::HandleRegisterResponse(
FROM_HERE,
NewRunnableFunction(&WriteDeviceTokenToDisk,
token_path_,
- device_token_,
- device_id_));
+ device_token_));
SetState(kStateHasDeviceToken);
} else {
NOTREACHED();
@@ -97,23 +93,19 @@ void DeviceTokenFetcher::StartFetching() {
void DeviceTokenFetcher::AttemptTokenLoadFromDisk() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ FetcherState new_state = kStateFailure;
if (file_util::PathExists(token_path_)) {
- std::string data;
- em::DeviceCredentials device_credentials;
- if (file_util::ReadFileToString(token_path_, &data) &&
- device_credentials.ParseFromArray(data.c_str(), data.size())) {
- device_token_ = device_credentials.device_token();
- device_id_ = device_credentials.device_id();
- if (!device_token_.empty() && !device_id_.empty()) {
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- NewRunnableMethod(this,
- &DeviceTokenFetcher::SetState,
- kStateHasDeviceToken));
- return;
- }
+ std::string device_token;
+ if (file_util::ReadFileToString(token_path_, &device_token_)) {
+ new_state = kStateHasDeviceToken;
}
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ NewRunnableMethod(this,
+ &DeviceTokenFetcher::SetState,
+ new_state));
+ return;
}
BrowserThread::PostTask(
@@ -136,7 +128,7 @@ void DeviceTokenFetcher::SendServerRequestIfPossible() {
em::DeviceRegisterRequest register_request;
SetState(kStateRequestingDeviceTokenFromServer);
backend_->ProcessRegisterRequest(auth_token_,
- GetDeviceID(),
+ GenerateNewDeviceID(),
register_request,
this);
}
@@ -153,15 +145,6 @@ std::string DeviceTokenFetcher::GetDeviceToken() {
return device_token_;
}
-std::string DeviceTokenFetcher::GetDeviceID() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // As long as access to this is only allowed from the UI thread, no explicit
- // locking is necessary to prevent the ID from being generated twice.
- if (device_id_.empty())
- device_id_ = GenerateNewDeviceID();
- return device_id_;
-}
-
void DeviceTokenFetcher::SetState(FetcherState state) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (state_ == state)
@@ -191,14 +174,10 @@ bool DeviceTokenFetcher::IsTokenValid() const {
// static
void DeviceTokenFetcher::WriteDeviceTokenToDisk(
const FilePath& path,
- const std::string& device_token,
- const std::string& device_id) {
- em::DeviceCredentials device_credentials;
- device_credentials.set_device_token(device_token);
- device_credentials.set_device_id(device_id);
- std::string data;
- DCHECK(device_credentials.SerializeToString(&data));
- file_util::WriteFile(path, data.c_str(), data.length());
+ const std::string& device_token) {
+ file_util::WriteFile(path,
+ device_token.c_str(),
+ device_token.length());
}
// static
diff --git a/chrome/browser/policy/device_token_fetcher.h b/chrome/browser/policy/device_token_fetcher.h
index 066e300..d685f54 100644
--- a/chrome/browser/policy/device_token_fetcher.h
+++ b/chrome/browser/policy/device_token_fetcher.h
@@ -61,10 +61,6 @@ class DeviceTokenFetcher
// case that the token could not be fetched, an empty string is returned.
std::string GetDeviceToken();
- // Returns the device ID for this device. If no such ID has been set yet, a
- // new ID is generated and returned.
- std::string GetDeviceID();
-
// True if the fetcher has a valid AuthToken for the device management server.
bool HasAuthToken() const { return !auth_token_.empty(); }
@@ -112,8 +108,7 @@ class DeviceTokenFetcher
// Saves the device management token to disk once it has been retrieved from
// the server. Must be called on the FILE thread.
static void WriteDeviceTokenToDisk(const FilePath& path,
- const std::string& token,
- const std::string& device_id);
+ const std::string& token);
// Generates a new device ID used to register the device with the device
// management server and generate the device token.
@@ -123,7 +118,6 @@ class DeviceTokenFetcher
DeviceManagementBackend* backend_; // weak
FetcherState state_;
std::string device_token_;
- std::string device_id_;
// Contains the AuthToken for the device management server. Empty if the
// AuthToken hasn't been issued yet or that was an error getting the
diff --git a/chrome/browser/policy/device_token_fetcher_unittest.cc b/chrome/browser/policy/device_token_fetcher_unittest.cc
index b6f50e5..8a408d6 100644
--- a/chrome/browser/policy/device_token_fetcher_unittest.cc
+++ b/chrome/browser/policy/device_token_fetcher_unittest.cc
@@ -85,25 +85,6 @@ TEST_F(DeviceTokenFetcherTest, IsPending) {
ASSERT_FALSE(fetcher_->IsTokenPending());
}
-TEST_F(DeviceTokenFetcherTest, StoreAndLoad) {
- backend_->AllShouldSucceed();
- EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
- SimulateSuccessfulLoginAndRunPending();
- ASSERT_FALSE(fetcher_->IsTokenPending());
- std::string device_token = fetcher_->GetDeviceToken();
- std::string device_id = fetcher_->GetDeviceID();
- ASSERT_NE("", device_id);
-
- FilePath token_path;
- GetDeviceTokenPath(fetcher_, &token_path);
- scoped_refptr<DeviceTokenFetcher> fetcher2(
- new DeviceTokenFetcher(backend_.get(), token_path));
- fetcher2->StartFetching();
- loop_.RunAllPending();
- ASSERT_EQ(device_id, fetcher2->GetDeviceID());
- ASSERT_EQ(device_token, fetcher2->GetDeviceToken());
-}
-
TEST_F(DeviceTokenFetcherTest, SimpleFetchSingleLogin) {
backend_->AllShouldSucceed();
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
diff --git a/chrome/browser/policy/proto/device_management_local.proto b/chrome/browser/policy/proto/device_management_local.proto
index ad7fc05..cd5a93a 100644
--- a/chrome/browser/policy/proto/device_management_local.proto
+++ b/chrome/browser/policy/proto/device_management_local.proto
@@ -18,9 +18,3 @@ message CachedDevicePolicyResponse {
optional uint64 timestamp = 2;
}
-// Encapsulates a device ID and the associated device token.
-message DeviceCredentials {
- optional string device_id = 1;
- optional string device_token = 2;
-}
-