Skip to content

Commit

Permalink
[Chrome OS ECHO] Get the OOBE timestamp and make it avaiable to echo …
Browse files Browse the repository at this point in the history
…extension

Chrome OS Registration service need to know when the device is first activated
and will use that information to determine the expiration date of some offer.
The OOBE timestamp extracted from file /home/chronos/.oobe_completed is used
to determine the activation date.

BUG=chromium-os:38325
TEST=unit tests


Review URL: https://chromiumcodereview.appspot.com/12091052

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179996 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oscarpan@google.com committed Jan 31, 2013
1 parent d8dd0a0 commit 5a3f74d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
46 changes: 46 additions & 0 deletions chrome/browser/chromeos/extensions/echo_private_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

#include <string>

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/location.h"
#include "base/stringprintf.h"
#include "base/time.h"
#include "base/values.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

namespace {

Expand Down Expand Up @@ -52,3 +60,41 @@ bool GetRegistrationCodeFunction::RunImpl() {
SetResult(GetValueForRegistrationCodeType(type));
return true;
}

GetOobeTimestampFunction::GetOobeTimestampFunction() {
}

GetOobeTimestampFunction::~GetOobeTimestampFunction() {
}

bool GetOobeTimestampFunction::RunImpl() {
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::FILE, FROM_HERE,
base::Bind(
&GetOobeTimestampFunction::GetOobeTimestampOnFileThread, this),
base::Bind(
&GetOobeTimestampFunction::SendResponse, this));
return true;
}

// Get the OOBE timestamp from file /home/chronos/.oobe_completed.
// The timestamp is used to determine when the user first activates the device.
// If we can get the timestamp info, return it as yyyy-mm-dd, otherwise, return
// an empty string.
bool GetOobeTimestampFunction::GetOobeTimestampOnFileThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));

const char kOobeTimestampFile[] = "/home/chronos/.oobe_completed";
std::string timestamp = "";
base::PlatformFileInfo fileInfo;
if (file_util::GetFileInfo(FilePath(kOobeTimestampFile), &fileInfo)) {
base::Time::Exploded ctime;
fileInfo.creation_time.UTCExplode(&ctime);
timestamp += base::StringPrintf("%u-%u-%u",
ctime.year,
ctime.month,
ctime.day_of_month);
}
SetResult(new base::StringValue(timestamp));
return true;
}
14 changes: 14 additions & 0 deletions chrome/browser/chromeos/extensions/echo_private_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ class GetRegistrationCodeFunction : public SyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION("echoPrivate.getRegistrationCode",
ECHOPRIVATE_GETREGISTRATIONCODE)
};

class GetOobeTimestampFunction : public AsyncExtensionFunction {
public:
GetOobeTimestampFunction();

protected:
virtual ~GetOobeTimestampFunction();
virtual bool RunImpl() OVERRIDE;

private:
bool GetOobeTimestampOnFileThread();
DECLARE_EXTENSION_FUNCTION("echoPrivate.getOobeTimestamp",
ECHOPRIVATE_GETOOBETIMESTAMP)
};
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ enum HistogramValue {
SESSIONRESTORE_GETRECENTLYCLOSED,
SESSIONRESTORE_RESTORE,
MANAGEMENT_UNINSTALLSELF,
ECHOPRIVATE_GETOOBETIMESTAMP,
ENUM_BOUNDARY // Last entry: Add new entries above.
};

Expand Down
1 change: 1 addition & 0 deletions chrome/browser/extensions/extension_function_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void ExtensionFunctionRegistry::ResetFunctions() {

// Echo
RegisterFunction<GetRegistrationCodeFunction>();
RegisterFunction<GetOobeTimestampFunction>();

// Terminal
RegisterFunction<OpenTerminalProcessFunction>();
Expand Down
18 changes: 18 additions & 0 deletions chrome/common/extensions/api/echo_private.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
]
}
]
},
{
"name": "getOobeTimestamp",
"description": "Get the OOBE timestamp.",
"type": "function",
"parameters": [
{
"name": "callback",
"type": "function",
"parameters": [
{
"name": "result",
"type": "string",
"description" : "The OOBE timestamp."
}
]
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ chrome.test.runTests([
chrome.test.callbackPass(function(result) {
chrome.test.assertTrue(result == '');
}));
chrome.echoPrivate.getOobeTimestamp(
chrome.test.callbackPass(function(result) {
chrome.test.assertTrue(result == '');
}));
}
]);

0 comments on commit 5a3f74d

Please sign in to comment.