summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoroscarpan@google.com <oscarpan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-31 23:15:42 +0000
committeroscarpan@google.com <oscarpan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-31 23:15:42 +0000
commit5a3f74d89e51dcc5fc0aded0eb032c8b01020bff (patch)
tree841bbdd7171cc765d43a2d5231754f9b346ac97a /chrome
parentd8dd0a0d3ecca736ac8410536456fac0c2d14d46 (diff)
downloadchromium_src-5a3f74d89e51dcc5fc0aded0eb032c8b01020bff.zip
chromium_src-5a3f74d89e51dcc5fc0aded0eb032c8b01020bff.tar.gz
chromium_src-5a3f74d89e51dcc5fc0aded0eb032c8b01020bff.tar.bz2
[Chrome OS ECHO] Get the OOBE timestamp and make it avaiable to echo 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
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/extensions/echo_private_api.cc46
-rw-r--r--chrome/browser/chromeos/extensions/echo_private_api.h14
-rw-r--r--chrome/browser/extensions/extension_function_histogram_value.h1
-rw-r--r--chrome/browser/extensions/extension_function_registry.cc1
-rw-r--r--chrome/common/extensions/api/echo_private.json18
-rw-r--r--chrome/test/data/extensions/api_test/echo/component_extension/test.js4
6 files changed, 84 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/extensions/echo_private_api.cc b/chrome/browser/chromeos/extensions/echo_private_api.cc
index 4d86957..51f195d 100644
--- a/chrome/browser/chromeos/extensions/echo_private_api.cc
+++ b/chrome/browser/chromeos/extensions/echo_private_api.cc
@@ -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 {
@@ -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;
+}
diff --git a/chrome/browser/chromeos/extensions/echo_private_api.h b/chrome/browser/chromeos/extensions/echo_private_api.h
index c365dba..8e81399 100644
--- a/chrome/browser/chromeos/extensions/echo_private_api.h
+++ b/chrome/browser/chromeos/extensions/echo_private_api.h
@@ -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_
diff --git a/chrome/browser/extensions/extension_function_histogram_value.h b/chrome/browser/extensions/extension_function_histogram_value.h
index 4923a43..5023c49 100644
--- a/chrome/browser/extensions/extension_function_histogram_value.h
+++ b/chrome/browser/extensions/extension_function_histogram_value.h
@@ -462,6 +462,7 @@ enum HistogramValue {
SESSIONRESTORE_GETRECENTLYCLOSED,
SESSIONRESTORE_RESTORE,
MANAGEMENT_UNINSTALLSELF,
+ ECHOPRIVATE_GETOOBETIMESTAMP,
ENUM_BOUNDARY // Last entry: Add new entries above.
};
diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc
index a121881..7ab4de3 100644
--- a/chrome/browser/extensions/extension_function_registry.cc
+++ b/chrome/browser/extensions/extension_function_registry.cc
@@ -183,6 +183,7 @@ void ExtensionFunctionRegistry::ResetFunctions() {
// Echo
RegisterFunction<GetRegistrationCodeFunction>();
+ RegisterFunction<GetOobeTimestampFunction>();
// Terminal
RegisterFunction<OpenTerminalProcessFunction>();
diff --git a/chrome/common/extensions/api/echo_private.json b/chrome/common/extensions/api/echo_private.json
index 905c1fa..980c7c0 100644
--- a/chrome/common/extensions/api/echo_private.json
+++ b/chrome/common/extensions/api/echo_private.json
@@ -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."
+ }
+ ]
+ }
+ ]
}
]
}
diff --git a/chrome/test/data/extensions/api_test/echo/component_extension/test.js b/chrome/test/data/extensions/api_test/echo/component_extension/test.js
index 4ffe6c5..c364d86 100644
--- a/chrome/test/data/extensions/api_test/echo/component_extension/test.js
+++ b/chrome/test/data/extensions/api_test/echo/component_extension/test.js
@@ -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 == '');
+ }));
}
]);