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

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: Fixing lint errors. 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..0b8f7321312a7d38b5b29a820c9e67550be08d22
--- /dev/null
+++ b/chrome/browser/extensions/api/time/time_api.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
Jói 2013/06/28 10:49:15 2013
hpjonsson 2013/06/28 12:13:04 Done.
+// 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"
Jói 2013/06/28 10:49:15 We put a blank line after including our "own" head
hpjonsson 2013/06/28 12:13:04 Done.
+#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, 80, format.c_str(), timeinfo);
Jói 2013/06/28 10:49:15 80 -> arraysize(buffer)
hpjonsson 2013/06/28 12:13:04 Done.
+
+ api::time::TimeResult result;
+ result.time_string = buffer;
Jói 2013/06/28 10:49:15 indent -2
hpjonsson 2013/06/28 12:13:04 Done.
+
+ // 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
Jói 2013/06/28 10:49:15 Usually we put a blank line before closing the nam
hpjonsson 2013/06/28 12:13:04 Done.
+

Powered by Google App Engine
This is Rietveld 408576698