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

Unified Diff: chrome/browser/extensions/api/time/time_api.cc

Issue 18063003: Chromium extension API - written as part of course in Open Software Development at Reykjavik Univer… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Second round of fixes from review Created 7 years, 6 months 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/extensions/api/time/time_api.cc
diff --git a/chrome/browser/extensions/api/time/time_api.cc b/chrome/browser/extensions/api/time/time_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1799e8de97570da144a2df9e3d35028a03e92bbd
--- /dev/null
+++ b/chrome/browser/extensions/api/time/time_api.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/time/time_api.h"
+
+#include <time.h>
+#include <string>
+
+namespace extensions {
+
+TimeGetTimeFunction::~TimeGetTimeFunction() {}
+
+bool TimeGetTimeFunction::RunImpl() {
+ // Args are passed in via the args_ member as a base::ListValue.
+ // Use the convenience member of the glue class to easily parse it.
+ scoped_ptr<api::time::GetTime::Params> params(
+ api::time::GetTime::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+ time_t rawtime;
+ struct tm * timeinfo;
+ char buffer[80];
+ std::string format = "%d/%m/%Y";
+
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ if (params->format) {
+ format = params->format->c_str();
+ }
+ std::strftime(buffer, arraysize(buffer), format.c_str(), timeinfo);
+
+ api::time::TimeResult result;
+ result.time_string = buffer;
+
+ // Use the convenience member of the glue class to easily serialize
+ // to base::Value. ExtensionFunction owns the resulting base::Value.
+ SetResult(result.ToValue().release());
+ // Not needed if you're a SyncExtensionFunction
+ // since it's set on the return value of RunImpl().
+ SendResponse(true /* success */);
+ return true;
+}
+
+} // namespace extensions
+
« no previous file with comments | « chrome/browser/extensions/api/time/time_api.h ('k') | chrome/browser/extensions/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698