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

Unified Diff: chrome/browser/policy/device_token_fetcher.cc

Issue 4949003: CrOS policies: Store device ID with device token (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 10 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/policy/device_token_fetcher.cc
diff --git a/chrome/browser/policy/device_token_fetcher.cc b/chrome/browser/policy/device_token_fetcher.cc
index a1ba00e9a172e3103fe8ee52ebcbfba96fd05dc9..00a3f501b02bcef023710363c170e7677d55f714 100644
--- a/chrome/browser/policy/device_token_fetcher.cc
+++ b/chrome/browser/policy/device_token_fetcher.cc
@@ -9,6 +9,7 @@
#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"
@@ -18,6 +19,8 @@
namespace policy {
+namespace em = enterprise_management;
+
DeviceTokenFetcher::DeviceTokenFetcher(
DeviceManagementBackend* backend,
const FilePath& token_path)
@@ -64,7 +67,8 @@ void DeviceTokenFetcher::HandleRegisterResponse(
FROM_HERE,
NewRunnableFunction(&WriteDeviceTokenToDisk,
token_path_,
- device_token_));
+ device_token_,
+ device_id_));
SetState(kStateHasDeviceToken);
} else {
NOTREACHED();
@@ -95,8 +99,12 @@ void DeviceTokenFetcher::AttemptTokenLoadFromDisk() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
FetcherState new_state = kStateFailure;
if (file_util::PathExists(token_path_)) {
- std::string device_token;
- if (file_util::ReadFileToString(token_path_, &device_token_)) {
+ std::string data;
+ em::DeviceToken stored_device_token;
+ if (file_util::ReadFileToString(token_path_, &data) &&
+ stored_device_token.ParseFromArray(data.c_str(), data.size())) {
+ device_token_ = stored_device_token.device_token();
+ device_id_ = stored_device_token.device_id();
new_state = kStateHasDeviceToken;
}
BrowserThread::PostTask(
@@ -128,7 +136,7 @@ void DeviceTokenFetcher::SendServerRequestIfPossible() {
em::DeviceRegisterRequest register_request;
SetState(kStateRequestingDeviceTokenFromServer);
backend_->ProcessRegisterRequest(auth_token_,
- GenerateNewDeviceID(),
+ GetDeviceID(),
register_request,
this);
}
@@ -145,10 +153,21 @@ 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();
+ }
Mattias Nissler (ping if slow) 2010/11/15 18:02:51 no curlies needed here.
Jakob Kummerow (corp) 2010/11/16 09:37:02 Alright, alright, I give up. Done.
Mattias Nissler (ping if slow) 2010/11/16 09:58:14 :)
+ return device_id_;
+}
+
void DeviceTokenFetcher::SetState(FetcherState state) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (state_ == state)
+ if (state_ == state) {
return;
+ }
Mattias Nissler (ping if slow) 2010/11/15 18:02:51 Same here? Or do you have a reason for changing th
Jakob Kummerow (corp) 2010/11/16 09:37:02 Done.
state_ = state;
if (state == kStateFailure) {
device_token_load_complete_event_.Signal();
@@ -174,10 +193,16 @@ bool DeviceTokenFetcher::IsTokenValid() const {
// static
void DeviceTokenFetcher::WriteDeviceTokenToDisk(
const FilePath& path,
- const std::string& device_token) {
+ const std::string& device_token,
+ const std::string& device_id) {
+ em::DeviceToken storable_device_token;
+ storable_device_token.set_device_token(device_token);
+ storable_device_token.set_device_id(device_id);
+ std::string data;
+ storable_device_token.SerializeToString(&data);
Mattias Nissler (ping if slow) 2010/11/15 18:02:51 Should probably put a DCHECK() for the SerializeTo
Jakob Kummerow (corp) 2010/11/16 09:37:02 Done.
file_util::WriteFile(path,
- device_token.c_str(),
- device_token.length());
+ data.c_str(),
+ data.length());
Mattias Nissler (ping if slow) 2010/11/15 18:02:51 Hm, doesn't this fit on line 203?
Jakob Kummerow (corp) 2010/11/16 09:37:02 Done.
}
// static

Powered by Google App Engine
This is Rietveld 408576698