Chromium Code Reviews| 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.
|
| + |